18 Stem::Event::start_loop() ;
20 # no return from here.
21 ######################
25 $hub_name = "Stem_msg_$$" ;
27 Stem::Route::register_class( __PACKAGE__ ) ;
29 Stem::Hub->new( 'reg_name' => $hub_name ) ;
33 push @portal_args, ( 'host' => $args{'host'} ) if $args{'host'} ;
34 push @portal_args, ( 'port' => $args{'port'} ) if $args{'port'} ;
36 #print "portal args: @portal_args\n" ;
38 $portal = Stem::Portal->new( @portal_args ) ;
40 die "Can't create Portal: $portal" if $portal ;
45 my ( @msg_args, @target ) ;
49 @msg_args = ( 'type' => 'cmd', 'cmd' => $args{'cmd'} ) ;
53 @msg_args = ( 'type' => 'data' ) ;
56 @target = ( 'to_target' => $args{'target'} ) if $args{'target'} ;
58 push( @msg_args, ( 'ack_req' => 1 ) ) if $args{'ack'} ;
60 my $data = exists( $args{'data'} ) ? $args{'data'} : '' ;
62 my $msg = Stem::Msg->new(
63 'to_hub' => 'DEFAULT',
64 'to_cell' => $args{'cell'},
66 'from_cell' => __PACKAGE__,
67 'from_hub' => $hub_name,
75 # this is the class method that gets back the response and ack messages.
79 my( $class, $msg ) = @_ ;
81 if( $msg->type() eq 'msg_ack' ) {
87 if ( my $data = $msg->data() ) {
92 # $portal->shut_down() ;
94 exit unless $args{'ack'} ;
102 Getopt::Long::Configure( 'no_ignore_case' ) ;
116 #print map "$_ => $args{$_}\n", sort keys %args ;
118 usage( '' ) if $args{ 'help' } ;
120 usage( 'Missing Cell address' ) unless $args{ 'cell' } ;
125 my $err_msg = shift ;
127 my $usage = <<'=cut' ;
132 stem_msg - Inject a message into a Stem Hub
136 stem_msg -cell <cell> [-hub <hub>] [-target <target>]
137 [-cmd <cmd>] [-data <data>] [-ack]
138 [-host <host>] [-port <port>]
140 -C <cell> The Stem Cell to send this message to.
141 -cell <cell> This is required.
143 -H <hub> The hub which has the addressed Stem Cell.
146 -T <target> The target address of the Stem Cell
149 -c <cmd> The cmd type to send in the message
150 -cmd <cmd> If no cmd is set, it will be a data type
153 -d <data> The data to be sent in the message.
154 -data <data> Default is an empty string.
156 -a Wait for an acknowledge message before
159 -h <host> The host which the Stem Hub is on.
160 -host <host> Default: localhost
162 -p <port> The port which the Stem Portal is listening
164 Default: 10,000 (probably will change)
168 This program is meant to inject a single message into a Stem Hub. You
169 set the Cell address with the command line options and then which
170 command to execute in that Cell. If you don't set a command, then a
171 data message will be sent. You can send data in the message as well.
173 If the Cell generates a response message, then its data will be
176 If the -ack option is set, then the message will have the ack_req flag
177 will be set in the outgoing message. This will cause an 'ack' type
178 message to be sent back after the original message has been
179 delivered. This is meant for when you send a message to a Cell which
180 doesn't generate a response. It lets this program know that it can
185 $usage =~ s/^=\w+.*$//mg ;
187 $usage =~ s/\n{2,}/\n\n/ ;
188 $usage =~ s/\A\n+/\n/ ;
190 die "$err_msg\n$usage" ;