4 # This is the new fundamental protocol engine handler
6 # This is where all the new things (and eventually all the old things
11 # Copyright (c) 2004 Dirk Koopman G1TLH
18 use vars qw($VERSION $BRANCH @queue @permin @persec);
20 main::mkver($VERSION = q$Revision$);
22 @queue = (); # the input / processing queue
25 # these are set up using the Thingy->add_second_process($addr, $name)
26 # and Thingy->add_minute_process($addr, $name)
28 # They replace the old cycle in cluster.pl
31 @persec = (); # this replaces the cycle in cluster.pl
32 @permin = (); # this is an extra per minute cycle
40 # we expect all thingies to be subclassed
50 # send it out in the format asked for, if available
58 } elsif ($dxchan->isa('DXChannel')) {
63 if ($thing->can('out_filter')) {
64 return unless $thing->out_filter($dxchan);
67 # generate the line which may (or not) be cached
69 if (my $ref = $thing->{class}) {
70 push @out, ref $ref ? @$ref : $ref;
73 my $sub = "gen_$class";
74 push @out, $thing->$sub($dxchan) if $thing->can($sub);
76 $dxchan->send(@out) if @out;
79 # broadcast to all except @_
83 dbg("Thingy::broadcast: " . $thing->ascii) if isdbg('thing');
85 foreach my $dxchan (DXChannel::get_all()) {
86 next if $dxchan == $main::me;
87 next if grep $dxchan == $_, @_;
88 $thing->send($dxchan);
92 # queue this thing for processing
97 $thing->{dxchan} = $dxchan->call;
101 # this is the main commutator loop. In due course it will
102 # become the *only* commutator loop
107 $thing = shift @queue;
108 my $dxchan = DXChannel->get($thing->{dxchan});
110 if ($thing->can('in_filter')) {
111 next unless $thing->in_filter($dxchan);
114 # remember any useful routes
115 RouteDB::update($thing->{origin}, $dxchan->{call}, $thing->{hopsaway});
116 RouteDB::update($thing->{user}, $dxchan->{call}, $thing->{hopsaway}) if exists $thing->{user};
118 $thing->handle($dxchan);
122 # per second and per minute processing
123 if ($main::systime != $lastsec) {
124 if ($main::systime >= $lastmin+60) {
125 foreach my $r (@permin) {
128 $lastmin = $main::systime;
130 foreach my $r (@persec) {
133 $lastsec = $main::systime;
137 sub add_minute_process
142 dbg('Adding $name to Thingy per minute queue');
143 push @permin, [$addr, $name];
146 sub add_second_process
151 dbg('Adding $name to Thingy per second queue');
152 push @persec, [$addr, $name];
159 my $dd = new Data::Dumper([$thing]);
163 $dd->Quotekeys($] < 5.005 ? 1 : 0);