/* * --- 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/template/Watcher.tcc * 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 --- */ // -*- c++ -*- #ifndef DAM__WATCHER_TMPL__ #error "This file is included by Watcher.hh." #error "Include that file instead." #endif namespace DAM { template AutomatonWatcher ::AutomatonWatcher (REACTOR* reactor, Automaton* automaton, StateSlot state_slot, NotifSlot notif_slot, QuerySlot query_slot, TermSlot term_slot) : m_logger (this) { this -> reactor = reactor; this -> state_slot = state_slot; this -> notif_slot = notif_slot; this -> query_slot = query_slot; this -> term_slot = term_slot; this -> automaton = 0; // the reference is set to NIL which ensures that // the initial call to SwitchAutomaton () will not // try to disconnect the slots Q_LOG(m_logger) << "watching " << FilteredTypeName () << " for " << FilteredTypeName () << " " << reactor << std::endl; SwitchAutomaton (automaton); } template typename AutomatonWatcher ::state_id AutomatonWatcher ::CurrentState () { if (!automaton) { if (m_logger.DoWarn () && !automaton) Q_WARN(m_logger) << "CurrentState () called for NIL automaton" << std::endl; return (state_id) 0; } return automaton -> GetState (); } template typename AutomatonWatcher ::Automaton* AutomatonWatcher ::CurrentAutomaton () { return automaton; } template void AutomatonWatcher ::SwitchAutomaton (Automaton* automaton) { Q_LOG(m_logger) << "switching automaton from " << this -> automaton << " to " << automaton << std::endl; if (this -> automaton) { conn_state_slot.disconnect (); conn_notif_slot.disconnect (); conn_query_slot.disconnect (); conn_term_slot.disconnect (); } this -> automaton = automaton; if (automaton) { conn_state_slot = automaton -> StateChanged.connect (sigc::mem_fun (reactor, state_slot)); conn_notif_slot = automaton -> Notification.connect (sigc::mem_fun (reactor, notif_slot)); conn_query_slot = automaton -> Question.connect (sigc::mem_fun (reactor, query_slot)); conn_term_slot = automaton -> Terminated.connect (sigc::mem_fun (reactor, term_slot)); Q_LOG(m_logger) << "current state is " << STATES::FullState (CurrentState ()).name << std::endl; } } } // end namespace DAM