Marcus Daniels June 18, 2001 swarm-support email Here's an example of a repeating schedule for a day's events. (There's a separate schedule for killing the model that runs on a multiplied timescale.) #import #import #import #import #define LASTDAY 5 @interface Model: Swarm { unsigned day; id schedule; id stopSchedule; } @end @implementation Model + createBegin: aZone { Model *obj = [super createBegin: aZone]; obj->day = 0; return obj; } - (void)die { [getCurrentSwarmActivity () terminate]; } - (void)newDay { printf ("new day #%u @ %u\n", day, getCurrentTime ()); day++; } - (void)wakeUp { printf ("wake up @ %u\n", getCurrentTime ()); } - (void)startWork { printf ("start work @ %u\n", getCurrentTime ()); } - (void)lunch { printf ("lunch @ %u\n", getCurrentTime ()); } - (void)resumeWork { printf ("resume work @ %u\n", getCurrentTime ()); } - (void)goHome { printf ("go home @ %u\n", getCurrentTime ()); } - (void)sleep { printf ("sleep @ %u\n", getCurrentTime ()); } - buildActions { stopSchedule = [Schedule create: self]; [stopSchedule at: LASTDAY * 24 createActionTo: self message: M(die)]; schedule = [Schedule create: self setRepeatInterval: 24]; [schedule at: 0 createActionTo: self message: M(newDay)]; [schedule at: 7 createActionTo: self message: M(wakeUp)]; [schedule at: 8 createActionTo: self message: M(startWork)]; [schedule at: 12 createActionTo: self message: M(lunch)]; [schedule at: 13 createActionTo: self message: M(resumeWork)]; [schedule at: 17 createActionTo: self message: M(goHome)]; [schedule at: 23 createActionTo: self message: M(sleep)]; return self; } - (id )activateIn: (id )swarmContext { [super activateIn: swarmContext]; [stopSchedule activateIn: self]; [schedule activateIn: self]; return [self getActivity]; } @end int main (int argc, const char **argv) { initSwarmBatch (argc, argv); { id model = [Model create: globalZone]; [model buildObjects]; [model buildActions]; [[model activateIn: nil] run]; } } /* Local Variables: compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -DAPPNAME=timeofday -D_GNU_SOURCE -o timeofday -g -Wno-import -I$SWARMHOME/include -L$SWARMHOME/lib timeofday.m -lswarm -lobjc" End: */