6 # Copyright (c) Dirk Koopman, G1TLH
20 use vars qw($VERSION $BRANCH $xs $id);
21 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
22 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
23 $main::build += $VERSION;
24 $main::branch += $BRANCH;
26 $xs = undef; # the XML::Simple parser instance
27 $id = 0; # the next ID to be used
29 # generate a new XML sentence structure
33 my $class = ref $pkg || $pkg;
34 return bless{@_}, $class;
38 # note that this a function not a method
42 return unless $main::do_xml;
44 eval { require XML::Simple; };
47 $DXProt::handle_xml = 1;
48 $xs = new XML::Simple();
54 # note that this a function not a method
61 unless ($main::do_xml) {
62 dbg("xml not enabled, IGNORED") if isdbg('chanerr');
66 my ($rootname) = $line =~ '<(\w+) ';
67 my $pkg = "DXXml::" . ucfirst lc "$rootname";
69 unless (defined *{"${pkg}::"} && $pkg->can('handle_input')) {
70 dbg("xml sentence $rootname not recognised, IGNORED") if isdbg('chanerr');
75 unless ($xref = $pkg->decode_xml($dxchan, $line)) {
76 dbg("invalid XML ($@), IGNORED") if isdbg('chanerr');
81 # mark the handle as accepting xml (but only if they
82 # have at least one right)
83 $dxchan->handle_xml(1);
85 $xref = bless $xref, $pkg;
86 $xref->{'-xml'} = $line;
87 $xref->handle_input($dxchan);
91 # note that this a function not a method
105 eval {$xref = $xs->XMLin($line)};
112 $id = 0 if $id > 999;
120 $self->{o} ||= $main::mycall;
121 $self->{t} ||= IsoTime::dayms();
122 $self->{id} ||= nextid();
124 my ($name) = ref $self =~ /::(\w+)$/;
125 my $s = $xs->XMLout($self, RootName =>lc $name, NumericEscape=>1);
126 return $self->{'-xml'} = $s;
131 return exists $_[0]->{'-xml'};
136 return exists $_[0]->{'-pcxx'};
141 return exists $_[0]->{'-cmd'};