| 1 |
cvsjoko |
1.1 |
package MJAM::Command::Router; |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
use warnings; |
| 5 |
|
|
|
| 6 |
|
|
use POE; |
| 7 |
|
|
|
| 8 |
|
|
sub routecmd { |
| 9 |
|
|
|
| 10 |
|
|
my ( $kernel, $session, $heap, $cmd, $conn ) = @_[ KERNEL, SESSION, HEAP, ARG0, ARG1 ]; |
| 11 |
|
|
|
| 12 |
|
|
# routing logic |
| 13 |
|
|
my $target_type; |
| 14 |
|
|
if ($conn->{connected}) { |
| 15 |
|
|
$target_type = $conn->{type}; |
| 16 |
|
|
} else { |
| 17 |
|
|
$target_type = "ce"; |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
|
print "routing command \"$cmd\" to \"$target_type\"", "\n"; |
| 21 |
|
|
|
| 22 |
|
|
if ($target_type eq 'ce') { |
| 23 |
|
|
print "posting to ce: $cmd", "\n"; |
| 24 |
|
|
$kernel->post('ce', 'docmd', $cmd); |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
if ($target_type eq 'cmdfd') { |
| 28 |
|
|
print "posting to cmdfile: $cmd", "\n"; |
| 29 |
|
|
my $xmlreq = RPC::XML::request->new( 'spoo', |
| 30 |
|
|
R::X::a->new( 8, 6, 7, 5, 3, 0, 9 ), |
| 31 |
|
|
); |
| 32 |
|
|
$kernel->post( rpcxmla => call => $xmlreq => 'response' ); |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
if ($target_type eq 'rpc') { |
| 36 |
|
|
print "posting to rpc", "\n"; |
| 37 |
|
|
my $xmlreq = RPC::XML::request->new( 'spoo', |
| 38 |
|
|
R::X::a->new( 8, 6, 7, 5, 3, 0, 9 ), |
| 39 |
|
|
); |
| 40 |
|
|
$kernel->post( rpcxmla => call => $xmlreq => 'response' ); |
| 41 |
|
|
} |
| 42 |
|
|
|
| 43 |
|
|
} |
| 44 |
|
|
|
| 45 |
|
|
1; |