1 # File: Stem/Cell/Sequence.pm
3 # This file is part of Stem.
4 # Copyright (C) 1999, 2000, 2001 Stem Systems, Inc.
6 # Stem is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Stem is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Stem; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # For a license to use the Stem under conditions other than those
21 # described here, to purchase support for this software, or to purchase a
22 # commercial warranty contract, please contact Stem Systems at:
24 # Stem Systems, Inc. 781-643-7504
25 # 79 Everett St. info@stemsystems.com
33 sub cell_set_sequence {
35 my( $self, @sequence ) = @_ ;
37 my $cell_info = $self->_get_cell_info() ;
39 #print "@sequence\n" ;
41 $cell_info->{'sequence'} = [ @sequence ] ;
42 $cell_info->{'sequence_left'} = [ @sequence ] ;
48 sub cell_reset_sequence {
52 my $cell_info = $self->_get_cell_info() ;
54 $cell_info->{'sequence_left'} = [ @{$cell_info->{'sequence'}} ] ;
59 sub cell_replace_next_sequence {
61 my( $self, $method ) = @_ ;
63 my $cell_info = $self->_get_cell_info() ;
65 $cell_info->{'sequence_left'}[0] = $method;
71 # This method lets you basically set up loops. For example, method X
72 # could insert itself as the next next method in the sequence. Then,
73 # when it is called again it can decide whether or not to insert
76 # A more complex example might see method X might say "now execute Y,
77 # Z, M, and X", which allows you to create loops. Then method Z might
78 # say "now execute Q and Z".
80 # Obviously, most loops will also need a break condition where method
81 # X decides _not_ to insert itself into the sequence.
83 sub cell_insert_next_sequence {
85 my( $self, @sequence ) = @_ ;
87 my $cell_info = $self->_get_cell_info() ;
89 unshift @{ $cell_info->{'sequence_left'} }, @sequence;
94 sub cell_skip_next_sequence {
96 my( $self, $count ) = @_ ;
100 my $cell_info = $self->_get_cell_info() ;
102 shift @{ $cell_info->{'sequence_left'} } for 1..$count;
107 sub cell_skip_until_method {
109 my( $self, $method ) = @_ ;
111 my $cell_info = $self->_get_cell_info() ;
113 my $seq_left = $cell_info->{'sequence_left'} ;
115 while( @{$seq_left} ) {
117 return if $seq_left->[0] eq $method ;
121 die "skip sequence method $method is not found" ;
125 sub cell_next_sequence_in {
127 my( $self, $msg ) = @_ ;
129 #print $msg->dump( "NEXT IN" ) if $msg ;
131 my $cell_info = $self->_get_cell_info() ;
133 $cell_info->cell_next_sequence( $msg ) ;
136 sub cell_next_sequence {
138 my( $self, $in_msg ) = @_ ;
140 #print caller(), "\n" ;
142 #print $in_msg->dump('SEQ IN') if $in_msg ;
144 my $cell_info = $self->_get_cell_info() ;
146 my $owner_obj = $cell_info->{'owner_obj'} ;
149 while( my $next_sequence = shift @{$cell_info->{'sequence_left'}} ) {
151 #print "LEFT @{$cell_info->{'sequence_left'}}\n" ;
153 die "cannot call sequence method $next_sequence"
154 unless $owner_obj->can( $next_sequence ) ;
156 #print "SEQ: $next_sequence\n" ;
158 my $seq_val = $owner_obj->$next_sequence( $in_msg ) ;
160 # don't pass in the message more than once.
164 next unless $seq_val ;
166 if ( ref $seq_val eq 'Stem::Msg' ) {
170 #print $seq_val->dump( 'SEQ: MSG' ) ;
171 $seq_val->reply_type( 'cell_next_sequence' ) ;
173 $seq_val->dispatch() ;
178 if ( ref $seq_val eq 'HASH' ) {
180 my $delay = $seq_val->{'delay'} ;
182 if ( defined( $delay ) ) {
184 $cell_info->cell_sequence_delay( $delay ) ;
190 if ( my $seq_done_method = $cell_info->{'sequence_done_method'} ) {
192 $owner_obj->$seq_done_method() ;
197 #warn "FELL off end of sequence" ;
202 sub cell_sequence_delay {
204 my( $self, $delay ) = @_ ;
206 my $cell_info = $self->_get_cell_info() ;
208 #print "SEQ DELAY $delay\n" ;
210 $cell_info->{'timer'} = Stem::Event::Timer->new(
211 'object' => $cell_info,
212 'method' => 'cell_next_sequence',