/*
 * --- GSMP-COPYRIGHT-NOTE-BEGIN ---
 * 
 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
 * Please add additional copyright information _after_ the line containing
 * the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
 * the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
 * 
 * GSMP: dam/include/State.hh
 * General Sound Manipulation Program is Copyright (C) 2000 - 2004
 *   Valentin Ziegler and René Rebe
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2. A copy of the GNU General
 * Public License can be found in the file LICENSE.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
 * ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * 
 * --- GSMP-COPYRIGHT-NOTE-END ---
 */


#ifndef DAM__STATE_HH__
#define DAM__STATE_HH__

#include "Logging.hh"
#include "TypeInformation.hh"
#include "Signals.hh"

namespace DAM
{
  struct State
  {
    const char* name;
    bool available;
  };

  struct Notification
  {
    const char* name;
  };

  struct Query
  {
    const char* name;
  };

  template <typename STATES, typename WL_TRAITS=DefaultLogging_Automaton>
  class Automaton
  {
  public:
    typedef typename STATES::state_id state_id;
    typedef typename STATES::notif_id notif_id;
    typedef typename STATES::query_id query_id;
    typedef typename STATES::Controler Controler;
    typedef typename STATES::Master Master;
    typedef typename STATES::NotificationData NotificationData;
    typedef typename STATES::QueryData QueryData;

    state_id GetState () {return current_state;}
    Event2 <Master*, state_id> StateChanged;
    Event3 <Master*, notif_id, const NotificationData&> Notification;
    Request3 <Master*, query_id, const QueryData&> Question;
    Event1 <Master*> Terminated;

  protected:
    Automaton (Master* i_master);
    ~Automaton ();

    void SetState (state_id id);
    void Notify (notif_id id, const NotificationData& data);
    bool Ask (query_id id, const QueryData& data);

    ObjectLogger<WL_TRAITS, Automaton> m_logger;
  private:
    state_id current_state;
    bool state_changing;
    Master* m_master;
  };

} // end namespace DAM


/* include template implementation */
#define DAM__STATE_TMPL__
#include "template/State.tcc"
#undef DAM__STATE_TMPL__

#endif // DAM__STATE_HH__
