1: // Definition of a session that traverses a path in a state graph.  05/25/98 rj@elilabs.com

  3: #ifndef __session__H__
  4: #define __session__H__

  6: class state;

  8: class session {

 10: public:

 12:   session() {                        // constructor
 13:   }

 15:   virtual ~session() {                // destructor
 16:   }


 19:   // A typical event handler.
 20:   //
 21:   // Every possible event must have a handler as a method in the session object.
 22:   // Each state object in the state graph must have 3 sub-handlers for each event:
 23:   // a guard handler, an exit handler, and a next state handler.
 24:   //
 25:   // It is hoped that automatic tools can aid the coding of the
 26:   // session's event handlers, and the state's sub-handlers.
 27:   //
 28:   // nb. if any special handling of the event at the session level is required,
 29:   //     the code to do this may be inserted at the appropriate places in the example
 30:   //     below for the foo event.  If session types exist in a class heirarchy,
 31:   //     virtual functions may be used to implement polymorphic behaviour across
 32:   //     members of the heirarchy.
 33:   //
 34:   //  bar* foo(blatz* boz, float zot) {
 35:   //
 36:   //    // Test the guard condition.
 37:   //    if (!current_state->foo__guard(this, boz, zot)) {
 38:   //      return event_ignored;                // event not handled because of guard
 39:   //    }
 40:   //
 41:   //    // Perform the exit action associated with the event in the current state.
 42:   //    bar* return_value = current_state->foo__exit_action(this, boz, zot);
 43:   //
 44:   //    // Enter to the next state.
 45:   //    current_state = current_state->foo__next_state();
 46:   //    entry_action();
 47:   //
 48:   //    return return_value;
 49:   //  }

 51: }; // end of class session

 53: #endif // __session__H__