Program Listing for File BondSM_sm.hpp

Return to documentation for file (/tmp/ws/src/bond_core/bondcpp/include/bondcpp/BondSM_sm.hpp)

/*
 * Copyright (c) 2009, Willow Garage, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Willow Garage, Inc. nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef BONDCPP__BONDSM_SM_HPP_
#define BONDCPP__BONDSM_SM_HPP_

/*
 * ex: set ro:
 * DO NOT EDIT.
 * generated by smc (http://smc.sourceforge.net/)
 * from file : BondSM_sm.sm
 */


#define SMC_USES_IOSTREAMS

#include "smclib/statemap.hpp"

// Forward declarations.
class SM;
class SM_WaitingForSister;
class SM_Alive;
class SM_AwaitSisterDeath;
class SM_Dead;
class SM_Default;
class BondSMState;
class BondSMContext;
struct BondSM;

class BondSMState
  : public statemap::State
{
public:
  BondSMState(const char * name, int stateId)
  : statemap::State(name, stateId)
  {}

  virtual void Entry(BondSMContext &) {}
  virtual void Exit(BondSMContext &) {}

  virtual void ConnectTimeout(BondSMContext & context);
  virtual void Die(BondSMContext & context);
  virtual void DisconnectTimeout(BondSMContext & context);
  virtual void HeartbeatTimeout(BondSMContext & context);
  virtual void SisterAlive(BondSMContext & context);
  virtual void SisterDead(BondSMContext & context);

protected:
  virtual void Default(BondSMContext & context);
};

class SM
{
public:
  static SM_WaitingForSister WaitingForSister;
  static SM_Alive Alive;
  static SM_AwaitSisterDeath AwaitSisterDeath;
  static SM_Dead Dead;
};

class SM_Default
  : public BondSMState
{
public:
  SM_Default(const char * name, int stateId)
  : BondSMState(name, stateId)
  {}
};

class SM_WaitingForSister
  : public SM_Default
{
public:
  SM_WaitingForSister(const char * name, int stateId)
  : SM_Default(name, stateId)
  {}

  void ConnectTimeout(BondSMContext & context);
  void Die(BondSMContext & context);
  void SisterAlive(BondSMContext & context);
  void SisterDead(BondSMContext & context);
};

class SM_Alive
  : public SM_Default
{
public:
  SM_Alive(const char * name, int stateId)
  : SM_Default(name, stateId)
  {}

  void Die(BondSMContext & context);
  void HeartbeatTimeout(BondSMContext & context);
  void SisterAlive(BondSMContext & context);
  void SisterDead(BondSMContext & context);
};

class SM_AwaitSisterDeath
  : public SM_Default
{
public:
  SM_AwaitSisterDeath(const char * name, int stateId)
  : SM_Default(name, stateId)
  {}

  void Die(BondSMContext & context);
  void DisconnectTimeout(BondSMContext & context);
  void HeartbeatTimeout(BondSMContext & context);
  void SisterAlive(BondSMContext & context);
  void SisterDead(BondSMContext & context);
};

class SM_Dead
  : public SM_Default
{
public:
  SM_Dead(const char * name, int stateId)
  : SM_Default(name, stateId)
  {}

  void ConnectTimeout(BondSMContext & context);
  void Die(BondSMContext & context);
  void DisconnectTimeout(BondSMContext & context);
  void HeartbeatTimeout(BondSMContext & context);
  void SisterAlive(BondSMContext & context);
  void SisterDead(BondSMContext & context);
};

class BondSMContext
  : public statemap::FSMContext
{
public:
  explicit BondSMContext(BondSM & owner)
  : FSMContext(SM::WaitingForSister),
    _owner(owner)
  {}

  BondSMContext(BondSM & owner, const statemap::State & state)
  : FSMContext(state),
    _owner(owner)
  {}

  virtual void enterStartState()
  {
    getState().Entry(*this);
  }

  BondSM & getOwner() const
  {
    return _owner;
  }

  BondSMState & getState() const
  {
    if (_state == NULL) {
      throw statemap::StateUndefinedException();
    }

    return dynamic_cast<BondSMState &>(*_state);
  }

  void ConnectTimeout()
  {
    (getState()).ConnectTimeout(*this);
  }

  void Die()
  {
    (getState()).Die(*this);
  }

  void DisconnectTimeout()
  {
    (getState()).DisconnectTimeout(*this);
  }

  void HeartbeatTimeout()
  {
    (getState()).HeartbeatTimeout(*this);
  }

  void SisterAlive()
  {
    (getState()).SisterAlive(*this);
  }

  void SisterDead()
  {
    (getState()).SisterDead(*this);
  }

private:
  BondSM & _owner;
};


/*
 * Local variables:
 *  buffer-read-only: t
 * End:
 */

#endif  // BONDCPP__BONDSM_SM_HPP_