d40031605f9bbb5955f3b74857ced43ba0212182
[debian/amanda] / perl / Amanda / Device.swg
1 /*
2  * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 %module "Amanda::Device"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24 %import "Amanda/Header.swg";
25
26 %include "Amanda/Device.pod"
27
28 %{
29 #include "device.h"
30 #include "property.h"
31 #include "fileheader.h"
32 #include "glib-util.h"
33 #include "simpleprng.h"
34 #include "amanda.h"
35 #include "sockaddr-util.h"
36 %}
37
38 %init %{
39     /* Initialize the Device API on load */
40     device_api_init();
41 %}
42
43 %{
44
45 /* Utility functions for typemaps, below */
46
47 /* return a new, mortal SV corresponding to the given GValue
48  *
49  * @param value: the value to convert
50  * @returns: a new, mortal SV
51  */
52 static SV *
53 set_sv_from_gvalue(GValue *value)
54 {
55     GType fundamental = G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value));
56     SV *sv = NULL;
57
58     /* complex reference types */
59     switch (fundamental) {
60         case G_TYPE_LONG:
61             return sv_2mortal(amglue_newSVi64(g_value_get_long(value)));
62
63         case G_TYPE_ULONG:
64             return sv_2mortal(amglue_newSVu64(g_value_get_ulong(value)));
65
66         case G_TYPE_INT64:
67             return sv_2mortal(amglue_newSVi64(g_value_get_int64(value)));
68
69         case G_TYPE_UINT64:
70             return sv_2mortal(amglue_newSVu64(g_value_get_uint64(value)));
71     }
72
73     /* simple types that can be constructed with sv_set*v */
74     sv = sv_newmortal();
75     switch (fundamental) {
76         case G_TYPE_CHAR:
77             sv_setiv(sv, g_value_get_char(value));
78             break;
79
80         case G_TYPE_UCHAR:
81             sv_setuv(sv, g_value_get_uchar(value));
82             break;
83
84         case G_TYPE_BOOLEAN:
85             sv_setiv(sv, g_value_get_boolean(value));
86             break;
87
88         case G_TYPE_INT:
89             sv_setiv(sv, g_value_get_int(value));
90             break;
91
92         case G_TYPE_UINT:
93             sv_setuv(sv, g_value_get_uint(value));
94             break;
95
96         case G_TYPE_FLOAT:
97             sv_setnv(sv, g_value_get_float(value));
98             break;
99
100         case G_TYPE_DOUBLE:
101             sv_setnv(sv, g_value_get_double(value));
102             break;
103
104         case G_TYPE_STRING:
105             sv_setpv(sv, g_value_get_string(value));
106             break;
107
108         case G_TYPE_ENUM:
109             sv_setiv(sv, g_value_get_enum(value));
110             break;
111
112         case G_TYPE_FLAGS:
113             sv_setiv(sv, g_value_get_flags(value));
114             break;
115
116         /* Unsupported */
117         default:
118         case G_TYPE_POINTER:
119         case G_TYPE_INTERFACE:
120         case G_TYPE_OBJECT:
121         case G_TYPE_PARAM:
122             warn("Unsupported fundamental property type #%d", (int)fundamental);
123             sv_setsv(sv, &PL_sv_undef);
124             break;
125     }
126
127     return sv;
128 }
129
130 /* Given an SV and an initialized GValue, set the GValue to the value
131  * represented by the SV.  The GValue's type must already be set.
132  *
133  * For basic corresponding types (string -> string, integer -> integer),
134  * the translation is straightforward.  However, if the GValue is not a
135  * string, but the SV has a string value, then g_value_set_from_string will
136  * be used to parse the string.
137  *
138  * @param sv: SV to convert
139  * @param value: (input/output) destination
140  * @returns: TRUE on success
141  */
142 static gboolean
143 set_gvalue_from_sv(SV *sv, GValue *value)
144 {
145     GType fundamental = G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value));
146
147     /* if we got a string, use g_value_set_from_string to parse any funny
148      * values or suffixes */
149     if (SvPOK(sv)) {
150         if (g_value_set_from_string(value, SvPV_nolen(sv)))
151             return TRUE;
152     }
153
154     /* otherwise, handle numeric types with SvIV, SvNV, or the amglue_* functions */
155     switch (fundamental) {
156         case G_TYPE_BOOLEAN:
157             g_value_set_boolean(value, SvIV(sv));
158             return TRUE;
159
160         case G_TYPE_CHAR:
161             g_value_set_char(value, amglue_SvI8(sv));
162             return TRUE;
163
164         case G_TYPE_UCHAR:
165             g_value_set_uchar(value, amglue_SvU8(sv));
166             return TRUE;
167
168         case G_TYPE_INT:
169             g_value_set_int(value, amglue_SvI32(sv));
170             return TRUE;
171
172         case G_TYPE_UINT:
173             g_value_set_uint(value, amglue_SvU32(sv));
174             return TRUE;
175
176         case G_TYPE_LONG:
177             g_value_set_int64(value, amglue_SvI64(sv));
178             return TRUE;
179
180         case G_TYPE_ULONG:
181             g_value_set_uint64(value, amglue_SvU64(sv));
182             return TRUE;
183
184         case G_TYPE_INT64:
185             g_value_set_int64(value, amglue_SvI64(sv));
186             return TRUE;
187
188         case G_TYPE_UINT64:
189             g_value_set_uint64(value, amglue_SvU64(sv));
190             return TRUE;
191
192         case G_TYPE_FLOAT:
193             g_value_set_float(value, SvNV(sv));
194             return TRUE;
195
196         case G_TYPE_DOUBLE:
197             g_value_set_double(value, SvNV(sv));
198             return TRUE;
199
200         case G_TYPE_ENUM:
201             g_value_set_enum(value, SvIV(sv));
202             return TRUE;
203
204         case G_TYPE_FLAGS:
205             g_value_set_flags(value, SvIV(sv));
206             return TRUE;
207
208         default:
209             /* for anything else, let perl stringify it for us and try parsing it */
210             return g_value_set_from_string(value, SvPV_nolen(sv));
211     }
212 }
213
214 %}
215
216 /*
217  * DirectTCPConnection object
218  */
219
220 typedef struct DirectTCPConnection {
221     %extend {
222         ~DirectTCPConnection() {
223             g_object_unref(self);
224         };
225
226         %newobject close;
227         char *close() {
228             return directtcp_connection_close(self);
229         }
230     };
231 } DirectTCPConnection;
232
233 /*
234  * Device struct, %extend-ed into a Perl class
235  */
236
237 %name(unaliased_name) extern char *device_unaliased_name(char *);
238
239 typedef struct Device {
240
241     /* methods */
242     %extend {
243         /* constructor */
244         Device(char *device_name) {
245             return device_open(device_name);
246         }
247
248         ~Device() {
249             g_object_unref(self);
250         }
251
252         gboolean
253         configure(gboolean use_global_config) {
254             return device_configure(self, use_global_config);
255         }
256
257         char *
258         error() {
259             return device_error(self);
260         }
261
262         char *
263         status_error() {
264             return device_status_error(self);
265         }
266
267         char *
268         error_or_status() {
269             return device_error_or_status(self);
270         }
271
272         DeviceStatusFlags
273         read_label() {
274             return device_read_label(self);
275         }
276
277         gboolean
278         start(DeviceAccessMode mode, char *label, char *timestamp) {
279             return device_start(self, mode, label, timestamp);
280         }
281
282         gboolean
283         finish() {
284             return device_finish(self);
285         }
286
287         gboolean
288         start_file(dumpfile_t *jobInfo) {
289             return device_start_file(self, jobInfo);
290         }
291
292         gboolean
293         write_block(guint size, gpointer data) {
294             return device_write_block(self, size, data);
295         }
296
297         gboolean
298         finish_file() {
299             return device_finish_file(self);
300         }
301
302         dumpfile_t*
303         seek_file(guint file) {
304             return device_seek_file(self, file);
305         }
306
307         gboolean
308         seek_block(guint64 block) {
309             return device_seek_block(self, block);
310         }
311
312         int
313         read_block(gpointer buffer, int *size) {
314             return device_read_block(self, buffer, size);
315         }
316
317         gboolean
318         erase() {
319             return device_erase(self);
320         }
321
322         gboolean
323         eject() {
324             return device_eject(self);
325         }
326
327         gboolean
328         directtcp_supported() {
329             return device_directtcp_supported(self);
330         }
331
332         void
333         listen(gboolean for_writing, DirectTCPAddr **addrs) {
334             /* ensure that the addresses are empty if there was an error */
335             if (!device_listen(self, for_writing, addrs))
336                 *addrs = NULL;
337         }
338
339         %newobject accept; /* connection is already ref'd, so we own it */
340         DirectTCPConnection *
341         accept() {
342             DirectTCPConnection *conn = NULL;
343             gboolean rv;
344
345             rv = device_accept(self, &conn, NULL, NULL);
346             if (!rv && conn) {
347                 /* conn is ref'd for our convenience, but we don't want it */
348                 g_object_unref(conn);
349                 conn = NULL;
350             }
351             return conn;
352         }
353
354         %newobject connect; /* connection is already ref'd, so we own it */
355         DirectTCPConnection *
356         connect(gboolean for_writing, DirectTCPAddr *addrs) {
357             DirectTCPConnection *conn = NULL;
358             gboolean rv;
359
360             rv = device_connect(self, for_writing, addrs, &conn, NULL, NULL);
361             if (!rv && conn) {
362                 /* conn is ref'd for our convenience, but we don't want it */
363                 g_object_unref(conn);
364                 conn = NULL;
365             }
366             return conn;
367         }
368
369         gboolean
370         use_connection(DirectTCPConnection *conn) {
371             return device_use_connection(self, conn);
372         }
373
374         %typemap(in,numinputs=0) guint64 *actual_size (guint64 sz) {
375             sz = 0;
376             $1 = &sz;
377         }
378         %typemap(argout) guint64 *actual_size {
379             SP += argvi; PUTBACK;
380             $result = sv_2mortal(amglue_newSVu64(*$1));
381             SPAGAIN; SP -= argvi; argvi++;
382         }
383         gboolean
384         write_from_connection(guint64 size, guint64 *actual_size) {
385             return device_write_from_connection(self, size, actual_size);
386         }
387
388         gboolean
389         read_to_connection(guint64 size, guint64 *actual_size) {
390             return device_read_to_connection(self, size, actual_size);
391         }
392
393         %typemap(out) const GSList * {
394             GSList *iter;
395
396             /* Count the DeviceProperties */
397             EXTEND(SP, g_slist_length($1)); /* make room for return values */
398
399             /* Note that we set $result several times. the nature of
400              * SWIG's wrapping is such that incrementing argvi points
401              * $result to the next location in perl's argument stack.
402              */
403
404             for (iter = $1; iter; iter = g_slist_next(iter)) {
405                 DeviceProperty *prop = iter->data;
406                 HV *hash = newHV();
407                 SV *rv = newRV_noinc((SV *)hash);
408
409                 hv_store(hash, "name", 4,
410                         newSVpv(prop->base->name, 0), 0);
411                 hv_store(hash, "description", 11,
412                         newSVpv(prop->base->description, 0), 0);
413                 hv_store(hash, "access", 6,
414                         newSViv(prop->access), 0);
415                 $result = sv_2mortal(rv);
416                 argvi++;
417             }
418         }
419         const GSList * property_list(void) {
420             return device_property_get_list(self);
421         }
422
423         %typemap(out) const GSList *; /* remove typemap */
424
425         /* A typemap to convert a property name to a DevicePropertyBase. */
426         %typemap(in) DevicePropertyBase * {
427             char *pname = NULL;
428
429             if (SvPOK($input))
430                 pname = SvPV_nolen($input);
431
432             if (pname)
433                 $1 = (DevicePropertyBase *)device_property_get_by_name(pname);
434             else
435                 $1 = NULL;
436         }
437
438         /* A typemap to convert the GValue in property_get to a return value.  The
439          * (in) typemap sets up storage for the parameters, while the (argout) converts
440          * them to a perl SV. */
441         %typemap(in,numinputs=0) (GValue *out_val, PropertySurety *surety,
442                                   PropertySource *source, gboolean *val_found)
443                             (GValue val,
444                              PropertySurety surety,
445                              PropertySource source,
446                              gboolean found) {
447             memset(&val, 0, sizeof(val));
448             $1 = &val;
449             if (GIMME_V == G_ARRAY) {
450                 $2 = &surety;
451                 $3 = &source;
452             }
453             $4 = &found;
454         }
455         %typemap(argout) (GValue *out_val, PropertySurety *surety,
456                           PropertySource *source, gboolean *val_found) {
457             /* if the result is valid */
458             if (*$4) {
459                 /* move data from $1 to $result, somehow, being careful to
460                  * save the perl stack while doing so */
461                 SP += argvi; PUTBACK;
462                 $result = set_sv_from_gvalue($1);
463                 SPAGAIN; SP -= argvi; argvi++;
464
465                 /* free any memory for the GValue */
466                 g_value_unset($1);
467
468                 if (GIMME_V == G_ARRAY) {
469                     $result = newSViv(*$2);
470                     argvi++;
471                     $result = newSViv(*$3);
472                     argvi++;
473                 }
474             }
475             /* otherwise, return nothing */
476         }
477
478         void
479         property_get(DevicePropertyBase *pbase, GValue *out_val, PropertySurety *surety,
480                      PropertySource *source, gboolean *val_found) {
481             if (pbase) {
482                 *val_found = device_property_get_ex(self, pbase->ID, out_val, surety, source);
483             } else {
484                 *val_found = FALSE;
485             }
486         }
487
488         /* delete typemaps */
489         %typemap(in) (GValue *out_val, gboolean *val_found);
490         %typemap(argout) (GValue *out_val, gboolean *val_found);
491
492         /* We cheat a little bit here and just pass the native Perl type in to
493          * the function.  This is the easiest way to make sure we know the property
494          * information (in particular, its type) before trying to convert the SV.  */
495         %typemap(in) SV *sv "$1 = $input;"
496
497         gboolean
498         property_set(DevicePropertyBase *pbase, SV *sv) {
499             GValue gval;
500
501             if (!pbase)
502                 goto fail;
503             memset(&gval, 0, sizeof(gval));
504             g_value_init(&gval, pbase->type);
505             if (!set_gvalue_from_sv(sv, &gval))
506                 goto failunset;
507
508             if (!device_property_set(self, pbase->ID, &gval))
509                 goto failunset;
510
511             g_value_unset(&gval);
512             return TRUE;
513         failunset:
514             g_value_unset(&gval);
515         fail:
516             return FALSE;
517         }
518
519         gboolean
520         property_set_ex(DevicePropertyBase *pbase, SV *sv,
521                         PropertySurety surety, PropertySource source) {
522             GValue gval;
523             memset(&gval, 0, sizeof(gval));
524             g_value_init(&gval, pbase->type);
525             if (!set_gvalue_from_sv(sv, &gval))
526                 goto fail;
527
528             if (!device_property_set_ex(self, pbase->ID, &gval, surety, source))
529                 goto fail;
530
531             g_value_unset(&gval);
532             return TRUE;
533         fail:
534             g_value_unset(&gval);
535             return FALSE;
536         }
537
538         gboolean recycle_file(guint filenum) {
539             return device_recycle_file(self, filenum);
540         }
541
542         /* accessor functions */
543
544         int file(void) { return self->file; }
545         guint64 block(void) { return self->block; }
546         gboolean in_file(void) { return self->in_file; }
547         char * device_name(void) { return self->device_name; }
548         DeviceAccessMode access_mode(void) { return self->access_mode; }
549         gboolean is_eof(void) { return self->is_eof; }
550         gboolean is_eom(void) { return self->is_eom; }
551         char * volume_label(void) { return self->volume_label; }
552         char * volume_time(void) { return self->volume_time; }
553         DeviceStatusFlags status(void) { return self->status; }
554         gsize min_block_size(void) { return self->min_block_size; }
555         gsize max_block_size(void) { return self->max_block_size; }
556         gsize block_size(void) { return self->block_size; }
557         gsize header_block_size(void) { return self->header_block_size; }
558         dumpfile_t *volume_header(void) { return self->volume_header; }
559     };
560
561 } Device;
562
563 /* An alternate constructor for RAIT devices */
564 %typemap(in) GSList *child_devices {
565     AV *av;
566     int i, len;
567
568     if (!SvROK($input) || SvTYPE(SvRV($input)) != SVt_PVAV) {
569         SWIG_exception(SWIG_TypeError, "Expected an arrayref");
570     }
571     av = (AV *)SvRV($input);
572
573     $1 = NULL;
574     len = av_len(av);
575     for (i = 0; i <= len; i++) {
576         SV **elt = av_fetch(av, i, 0);
577         Device *d;
578
579         if (elt && !SvOK(*elt)) {
580             $1 = g_slist_append($1, NULL); /* 'undef' => NULL */
581         } else if (!elt || SWIG_ConvertPtr(*elt, (void **)&d, $descriptor(Device *), 0) == -1) {
582             SWIG_exception(SWIG_TypeError, "array member is not a Device");
583         } else {
584             $1 = g_slist_append($1, d);
585         }
586     }
587 }
588 %typemap(freearg) GSList *child_devices {
589     g_slist_free($1);
590 }
591 %newobject rait_device_open_from_children;
592 Device *rait_device_open_from_children(GSList *child_devices);
593 %perlcode %{
594 sub new_rait_from_children {
595     my $class = shift; # strip the $class from the arguments
596     return rait_device_open_from_children([@_]);
597 }
598 %}
599
600 /*
601  * Utilities for installchecks (not described in POD)
602  */
603
604 %inline %{
605
606 /* write LENGTH bytes of random data to FILENAME, seeded with SEED */
607 gboolean
608 write_random_to_device(guint32 seed, size_t length, Device *device) {
609     simpleprng_state_t prng;
610     char *buf;
611     gsize block_size = device->block_size;
612     g_assert(block_size < G_MAXUINT);
613
614     buf = g_malloc(block_size);
615     simpleprng_seed(&prng, seed);
616
617     while (length) {
618         size_t to_write = min(block_size, length);
619
620         simpleprng_fill_buffer(&prng, buf, to_write);
621         if (!device_write_block(device, (guint)block_size, buf)) {
622             g_free(buf);
623             return FALSE;
624         }
625         length -= to_write;
626     }
627
628     g_free(buf);
629     return TRUE;
630 }
631
632 /* read LENGTH bytes of random data from FILENAME verifying it against
633  * a PRNG seeded with SEED.  Sends any error messages to stderr.
634  */
635 gboolean
636 verify_random_from_device(guint32 seed, size_t length, Device *device) {
637     simpleprng_state_t prng;
638     char *buf = NULL; /* first device_read_block will get the size */
639     int block_size = 0;
640
641     simpleprng_seed(&prng, seed);
642
643     while (length) {
644         int bytes_read;
645         int size = block_size;
646
647         bytes_read = device_read_block(device, buf, &size);
648         if (bytes_read == 0 && size > block_size) {
649             g_free(buf);
650             block_size = size;
651             buf = g_malloc(block_size);
652             continue;
653         }
654         if (bytes_read == -1) {
655             if (device->status == DEVICE_STATUS_SUCCESS) {
656                 g_assert(device->is_eof);
657                 g_debug("verify_random_from_device got unexpected EOF");
658             }
659             goto error;
660         }
661
662         /* strip padding */
663         bytes_read = min(bytes_read, length);
664
665         if (!simpleprng_verify_buffer(&prng, buf, bytes_read))
666             goto error;
667
668         length -= bytes_read;
669     }
670
671     g_free(buf);
672     return TRUE;
673
674 error:
675     g_free(buf);
676     return FALSE;
677 }
678 %}
679
680 /*
681  * Constants
682  */
683
684 amglue_add_flag_tag_fns(DeviceAccessMode);
685 amglue_add_constant_short(ACCESS_NULL, "NULL", DeviceAccessMode);
686 amglue_add_constant_short(ACCESS_READ, "READ", DeviceAccessMode);
687 amglue_add_constant_short(ACCESS_WRITE, "WRITE", DeviceAccessMode);
688 amglue_add_constant_short(ACCESS_APPEND, "APPEND", DeviceAccessMode);
689
690 /* (this is really a macro, but SWIG will Do The Right Thing */
691 gboolean IS_WRITABLE_ACCESS_MODE(DeviceAccessMode mode);
692 amglue_export_tag(DeviceAccessMode, IS_WRITABLE_ACCESS_MODE);
693 amglue_copy_to_tag(DeviceAccessMode, constants);
694
695 amglue_add_flag_tag_fns(DeviceStatusFlags);
696 amglue_add_constant_short(DEVICE_STATUS_SUCCESS, "SUCCESS", DeviceStatusFlags);
697 amglue_add_constant_short(DEVICE_STATUS_DEVICE_ERROR, "DEVICE_ERROR", DeviceStatusFlags);
698 amglue_add_constant_short(DEVICE_STATUS_DEVICE_BUSY, "DEVICE_BUSY", DeviceStatusFlags);
699 amglue_add_constant_short(DEVICE_STATUS_VOLUME_MISSING, "VOLUME_MISSING", DeviceStatusFlags);
700 amglue_add_constant_short(DEVICE_STATUS_VOLUME_UNLABELED, "VOLUME_UNLABELED", DeviceStatusFlags);
701 amglue_add_constant_short(DEVICE_STATUS_VOLUME_ERROR, "VOLUME_ERROR", DeviceStatusFlags);
702 amglue_add_constant_noshort(DEVICE_STATUS_FLAGS_MAX, DeviceStatusFlags);
703 amglue_copy_to_tag(DeviceStatusFlags, constants);
704
705 amglue_add_flag_tag_fns(PropertyPhaseFlags);
706 amglue_add_constant_short(PROPERTY_PHASE_BEFORE_START, "BEFORE_START", PropertyPhaseFlags);
707 amglue_add_constant_short(PROPERTY_PHASE_BETWEEN_FILE_WRITE, "BETWEEN_FILE_WRITE", PropertyPhaseFlags);
708 amglue_add_constant_short(PROPERTY_PHASE_INSIDE_FILE_WRITE, "INSIDE_FILE_WRITE", PropertyPhaseFlags);
709 amglue_add_constant_short(PROPERTY_PHASE_BETWEEN_FILE_READ, "BETWEEN_FILE_READ", PropertyPhaseFlags);
710 amglue_add_constant_short(PROPERTY_PHASE_INSIDE_FILE_READ, "INSIDE_FILE_READ", PropertyPhaseFlags);
711 amglue_add_constant_noshort(PROPERTY_PHASE_MAX, PropertyPhaseFlags);
712 amglue_add_constant_noshort(PROPERTY_PHASE_MASK, PropertyPhaseFlags);
713 amglue_add_constant_noshort(PROPERTY_PHASE_SHIFT, PropertyPhaseFlags);
714 amglue_copy_to_tag(PropertyPhaseFlags, constants);
715
716 amglue_add_flag_tag_fns(PropertyAccessFlags);
717 amglue_add_constant_short(PROPERTY_ACCESS_GET_BEFORE_START,
718                     "GET_BEFORE_START", PropertyAccessFlags);
719 amglue_add_constant_short(PROPERTY_ACCESS_GET_BETWEEN_FILE_WRITE,
720                     "GET_BETWEEN_FILE_WRITE", PropertyAccessFlags);
721 amglue_add_constant_short(PROPERTY_ACCESS_GET_INSIDE_FILE_WRITE,
722                     "GET_INSIDE_FILE_WRITE", PropertyAccessFlags);
723 amglue_add_constant_short(PROPERTY_ACCESS_GET_BETWEEN_FILE_READ,
724                     "GET_BETWEEN_FILE_READ", PropertyAccessFlags);
725 amglue_add_constant_short(PROPERTY_ACCESS_GET_INSIDE_FILE_READ,
726                     "GET_INSIDE_FILE_READ", PropertyAccessFlags);
727 amglue_add_constant_short(PROPERTY_ACCESS_SET_BEFORE_START,
728                     "SET_BEFORE_START", PropertyAccessFlags);
729 amglue_add_constant_short(PROPERTY_ACCESS_SET_BETWEEN_FILE_WRITE,
730                     "SET_BETWEEN_FILE_WRITE", PropertyAccessFlags);
731 amglue_add_constant_short(PROPERTY_ACCESS_SET_INSIDE_FILE_WRITE,
732                     "SET_INSIDE_FILE_WRITE", PropertyAccessFlags);
733 amglue_add_constant_short(PROPERTY_ACCESS_SET_BETWEEN_FILE_READ,
734                     "SET_BETWEEN_FILE_READ", PropertyAccessFlags);
735 amglue_add_constant_short(PROPERTY_ACCESS_SET_INSIDE_FILE_READ,
736                     "SET_INSIDE_FILE_READ", PropertyAccessFlags);
737 amglue_add_constant_noshort(PROPERTY_ACCESS_GET_MASK, PropertyAccessFlags);
738 amglue_add_constant_noshort(PROPERTY_ACCESS_SET_MASK, PropertyAccessFlags);
739 amglue_copy_to_tag(PropertyAccessFlags, constants);
740
741 amglue_add_enum_tag_fns(ConcurrencyParadigm);
742 amglue_add_constant_short(CONCURRENCY_PARADIGM_EXCLUSIVE, "EXCLUSIVE", ConcurrencyParadigm);
743 amglue_add_constant_short(CONCURRENCY_PARADIGM_SHARED_READ, "SHARED_READ", ConcurrencyParadigm);
744 amglue_add_constant_short(CONCURRENCY_PARADIGM_RANDOM_ACCESS, "RANDOM_ACCESS", ConcurrencyParadigm);
745 amglue_copy_to_tag(ConcurrencyParadigm, constants);
746
747 amglue_add_enum_tag_fns(StreamingRequirement);
748 amglue_add_constant_short(STREAMING_REQUIREMENT_NONE, "NONE", StreamingRequirement);
749 amglue_add_constant_short(STREAMING_REQUIREMENT_DESIRED, "DESIRED", StreamingRequirement);
750 amglue_add_constant_short(STREAMING_REQUIREMENT_REQUIRED, "REQUIRED", StreamingRequirement);
751 amglue_copy_to_tag(StreamingRequirement, constants);
752
753 amglue_add_enum_tag_fns(MediaAccessMode);
754 amglue_add_constant_short(MEDIA_ACCESS_MODE_READ_ONLY, "READ_ONLY", MediaAccessMode);
755 amglue_add_constant_short(MEDIA_ACCESS_MODE_WORM, "WORM", MediaAccessMode);
756 amglue_add_constant_short(MEDIA_ACCESS_MODE_READ_WRITE, "READ_WRITE", MediaAccessMode);
757 amglue_add_constant_short(MEDIA_ACCESS_MODE_WRITE_ONLY, "WRITE_ONLY", MediaAccessMode);
758 amglue_copy_to_tag(MediaAccessMode, constants);
759
760 amglue_add_flag_tag_fns(PropertySurety);
761 amglue_add_constant_short(PROPERTY_SURETY_BAD, "SURETY_BAD", PropertySurety);
762 amglue_add_constant_short(PROPERTY_SURETY_GOOD, "SURETY_GOOD", PropertySurety);
763 amglue_copy_to_tag(PropertySurety, constants);
764
765 amglue_add_flag_tag_fns(PropertySource);
766 amglue_add_constant_short(PROPERTY_SOURCE_DEFAULT, "SOURCE_DEFAULT", PropertySource);
767 amglue_add_constant_short(PROPERTY_SOURCE_DETECTED, "SOURCE_DETECTED", PropertySource);
768 amglue_add_constant_short(PROPERTY_SOURCE_USER, "SOURCE_USER", PropertySource);
769 amglue_copy_to_tag(PropertySource, constants);
770
771 %perlcode %{
772
773 # SWIG produces a sub-package for the Device "class", in this case named
774 # Amanda::Device::Device.  For user convenience, we allow Amanda::Device->new(..) to
775 # do the same thing.  This is a wrapper function, and not just a typeglob assignment,
776 # because we want to get the right blessing.
777 sub new {
778     my $pkg = shift;
779     Amanda::Device::Device->new(@_);
780 }
781 %}