📄 device.swg
字号:
/* * Copyright (c) Zmanda, Inc. All Rights Reserved. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com */%module "Amanda::Device"%include "amglue/amglue.swg"%include "exception.i"%{#include "device.h"#include "property.h"#include "fileheader.h"%}/* import dumptype_t, among others */%import "Amanda/Types.swg";%perlcode %{=head1 NAMEAmanda::Device - interact with Amanda data-storage devices=head1 SYNOPSIS use Amanda::Device qw( :constants ); my $dev = Amanda::Device->new($device_name); $dev->set_startup_properties_from_config(); if ($dev->read_label() == $READ_LABEL_STATUS_SUCCESS) { print "Label on $device_name is '$dev->volume_label'\n"; } See L<http://wiki.zmanda.com/index.php/Device_API> for details on how Devices are used.=head1 API STATUSStable=head1 Amanda::Device Objects=head2 Instance Variables=over=item C<$file>=item C<$block>=item C<$in_file>=item C<$device_name>=item C<$access_mode>=item C<$is_eof>=item C<$volume_label>=item C<$volume_time>=back=head2 MethodsSee the wiki for descriptions of these functions=over=item C<read_label()>=item C<start($mode, $label, $timestamp)>=item C<finish()>=item C<start_file($jobinfo)>where C<$jobinfo> is a C<dumpfile_t> (see L<Amanda::Datatypes)=item C<write_min_size()>=item C<write_max_size()>=item C<read_max_size()>=item C<write_block($size, $data, $short_block)>Note that Perl code is not expected to handle on-device data, so thereis currently no way to provide data to this function from Perl. This maychange in future revisions.=item C<write_from_fd($fd)>where C<$fd> is an integer file descriptor, not a filehandle=item C<finish_file()>=item C<seek_file($file)>=item C<seek_block($block)>=item C<read_block($size)>=item C<read_to_fd($fd)>where C<$fd> is an integer file descriptor, not a filehandleNote that Perl code is not expected to handle on-device data, so thereis currently no way to access the data this function returns. This maychange in future revisions.=item C<property_list()>returns a list of property names.=item C<property_get($property_name)>returns the property as the appropriate Perl type.=item C<property_set($property_name, $value)>where $value is of an appropriate type for the given property=item C<recycle_file($filenum)>=item C<set_startup_properties_from_config()>=back=head1 CONSTANTSThis module defines a large number of constants. Again, consult thewiki or C<device.h> for the details on their meaning. These constantsare available from the package namespace (e.g.,C<Amanda::Device::ACCESS_WRITE>), of imported with the C<:constant>import tag.=cut%}%init %{ /* Initialize the Device API on load */ device_api_init();%}%{/* Utility functions for typemaps, below */static SV *set_sv_from_gvalue(GValue *value){ GType fundamental = G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value)); SV *sv = NULL; /* complex reference types */ switch (fundamental) { case G_TYPE_LONG: sv = sv_2mortal(amglue_newSVi64(g_value_get_long(value))); break; case G_TYPE_ULONG: sv = sv_2mortal(amglue_newSVu64(g_value_get_ulong(value))); break; case G_TYPE_INT64: sv = sv_2mortal(amglue_newSVi64(g_value_get_int64(value))); break; case G_TYPE_UINT64: sv = sv_2mortal(amglue_newSVu64(g_value_get_uint64(value))); break; case G_TYPE_BOXED: { GType boxed_type = G_VALUE_TYPE(value); QualifiedSize qs; HV *hv; if (boxed_type == QUALIFIED_SIZE_TYPE) { qs = *(QualifiedSize*)(g_value_get_boxed(value)); /* build a hash */ hv = (HV *)sv_2mortal((SV *)newHV()); hv_store(hv, "accuracy", 8, newSViv(qs.accuracy), 0); hv_store(hv, "bytes", 5, amglue_newSVi64(qs.bytes), 0); sv = newRV((SV *)hv); return newRV((SV *)hv); } else { warn("Unsupported boxed property type #%d", boxed_type); sv = sv_newmortal(); sv_setsv(sv, &PL_sv_undef); return sv; } } } /* simple types that can be constructed with sv_set*v */ sv = sv_newmortal(); switch (fundamental) { case G_TYPE_CHAR: sv_setiv(sv, g_value_get_char(value)); break; case G_TYPE_UCHAR: sv_setuv(sv, g_value_get_uchar(value)); break; case G_TYPE_BOOLEAN: sv_setiv(sv, g_value_get_boolean(value)); break; case G_TYPE_INT: sv_setiv(sv, g_value_get_int(value)); break; case G_TYPE_UINT: sv_setuv(sv, g_value_get_uint(value)); break; case G_TYPE_FLOAT: sv_setnv(sv, g_value_get_float(value)); break; case G_TYPE_DOUBLE: sv_setnv(sv, g_value_get_double(value)); break; case G_TYPE_STRING: sv_setpv(sv, g_value_get_string(value)); break; case G_TYPE_ENUM: sv_setiv(sv, g_value_get_enum(value)); break; case G_TYPE_FLAGS: sv_setiv(sv, g_value_get_flags(value)); break; /* Unsupported */ default: case G_TYPE_POINTER: case G_TYPE_INTERFACE: case G_TYPE_OBJECT: case G_TYPE_PARAM: warn("Unsupported fundamental property type #%d", fundamental); sv_setsv(sv, &PL_sv_undef); break; } return sv;}static gbooleanset_gvalue_from_sv(SV *sv, GValue *value){ GType fundamental = G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value)); switch (fundamental) { case G_TYPE_CHAR: if (!SvIOK(sv)) return FALSE; g_value_set_char(value, SvIV(sv)); break; case G_TYPE_UCHAR: if (!SvIOK(sv)) return FALSE; g_value_set_uchar(value, SvUV(sv)); break; case G_TYPE_BOOLEAN: if (!SvIOK(sv)) return FALSE; g_value_set_boolean(value, SvIV(sv)); break; case G_TYPE_INT: g_value_set_int(value, amglue_SvI32(sv)); break; case G_TYPE_UINT: g_value_set_uint(value, amglue_SvU32(sv)); break; case G_TYPE_LONG: g_value_set_int64(value, amglue_SvI64(sv)); break; case G_TYPE_ULONG: g_value_set_uint64(value, amglue_SvU64(sv)); break; case G_TYPE_INT64: g_value_set_int64(value, amglue_SvI64(sv)); break; case G_TYPE_UINT64: g_value_set_uint64(value, amglue_SvU64(sv)); break; case G_TYPE_FLOAT: if (!SvNOK(sv)) return FALSE; g_value_set_float(value, SvNV(sv)); break; case G_TYPE_DOUBLE: if (!SvNOK(sv)) return FALSE; g_value_set_double(value, SvNV(sv)); break; case G_TYPE_STRING: if (!SvPOK(sv)) return FALSE; g_value_set_string(value, SvPV_nolen(sv)); break; case G_TYPE_ENUM: if (!SvIOK(sv)) return FALSE; g_value_set_enum(value, SvIV(sv)); break; case G_TYPE_FLAGS: if (!SvIOK(sv)) return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -