// {{{ the iWear header 
/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework 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 as in version 2 of the License.

 * 
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
// }}}

#ifndef __DAEMONCONTROLLER_H
#define __DAEMONCONTROLLER_H

#ifndef __APPLICATION_H
#include <iwear_uiservices/application.h>
#endif

#include <set>
#include <queue>

// Our namespaces
using namespace iwear;
using namespace std;

namespace iwear{
    namespace uiservices{

	// Forward declarations (namespace iwear::uiservices)
	class SimpleMenuFunctor;
	class DaemonHandle;
	class Daemon;


class DaemonController : public Application{

    friend class SimpleMenuFunctor;

public:

    DaemonController(ApplicationService* application_service);

    virtual ~DaemonController( void );

    virtual void Run( void );

protected:

    void Init_Application( void );

    void Final_Application( void );

    virtual void set_default_configuration( void );

    virtual void scan_dynamic_daemons( void );

    /**
     * This method handles the automatic start of
     * caertain daemons which have been set appropriatly
     * in the configuration file by the user
     */   
    virtual void handle_autostart( void );

    /**
     * This method starts/stopps a daemon depending on its
     * current status.
     */
    virtual void toggle_daemon( uint32_t id );


private:

    /**
     * This set contains the currently available dynamic apps
     */
    set<string> daemon_libs;

    /**
     * Mapping from button IDs to corresponding pair
     * of Daemon Handle and Daemon. Note that the Daemon
     * pointer might be NULL which is an indicator for the fact that
     * no daemon created by the associated Daemon Handle is active
     * at the moment. 
     * Within the current concept Daemons are singletons. It remains
     * to be discussed whether this design decision makes sense for
     * real world situation, especially since the situation is handled
     * different for applications. However this design decision
     * reflects the toggle character of the Daemon Controller
     */
    map<const uint32_t, pair<DaemonHandle*, Daemon*> > button_id2managed_daemons;

    map<string, uint32_t> daemon_name2button_id;

    SimpleMenuFunctor* menu_functor;

};


    } // namespace uiservices
} // namespace iwear

#endif


