/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * 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 __IWEAR_SERVICEMANAGER_H
#define __IWEAR_SERVICEMANAGER_H

#ifndef __IWEAR_SERVICE_H
#include <iwear/service.h>
#endif

#include <iwear/threadlocked.h>
#include <iwear/exceptions.h>
#include <set>

using std::map;
using std::set;


namespace iwear {

class Configuration;
/**
 * This class is there to handle all the services known to the system. Since we
 * do not have abstraction layers like those of the modules, this manager does
 * also incorporate the dynamic loading of .so files.
 */    
class ServiceManager : public ThreadLocked
{
private:
protected:
    map<uid,Service*> map_uid;

    set<Service*> set_services;

    Configuration& conf;
public:

    ServiceManager( Configuration& c);

    Configuration& get_config( void ) { 
	IWASSERT(&conf != NULL );
	return conf; }
    const Configuration& get_config( void ) const { return conf; }
    virtual ~ServiceManager();

    Service* get_service( const uid& );
    const Service* get_service( const uid&) const;

    set<Service*>& get_services( void );
    const set<Service*>& get_services( void ) const;

    void register_service( Service* );
    void deregister_service( Service* );

    /**
     * Stops all non-system services.
     * @warning this can severely damage your system
     */
    void Stop();

    /**
     * (Re)Starts all non-system services.
     * @warning this can severely damage your system
     */
    void Restart();
};

}
#endif
