WModuleContainer.h 3.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WMODULECONTAINER_H
#define WMODULECONTAINER_H

28 29 30 31 32 33 34 35
#include <set>
#include <string>

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>

class WModule;

36 37 38 39 40 41
/**
 * Class able to contain other modules. It manages several tasks like finding appropriate modules, managing data modules and
 * module initialization.
 *
 * \ingroup Kernel
 */
42
class WModuleContainer: public boost::enable_shared_from_this< WModuleContainer >
43 44 45 46
{
public:

    /**
47 48 49 50
     * Constructor. Initializes container.
     * 
     * \param name  name of the container
     * \param description short description.
51
     */
52
    WModuleContainer( std::string name, std::string description );
53 54 55 56 57 58

    /**
     * Destructor.
     */
    virtual ~WModuleContainer();

59
    /**
60 61
     * Add a module to this container and start it. Please note, that a module can be added only once. If it already is 
     * associated with this container nothing happens.
62 63 64 65 66 67 68 69 70 71 72 73 74
     * 
     * \param module the module to add.
     * \throw WModuleUninitialized thrown whenever someone wants to add a module not yet initialized.
     */
    virtual void add( boost::shared_ptr< WModule > module );

    /**
     * Remove the given module from this container if it is associated with it. TODO(ebaum): deep removal? flat removal?
     * 
     * \param module the module to remove.
     */
    virtual void remove( boost::shared_ptr< WModule > module );

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    /**
     * Stops all modules inside this container. Note that this function could take some time, since it waits until the last module
     * has quit.
     */
    virtual void stop();

    /**
     * Gives back the name of this module.
     * \return the module's name.
     */
    virtual const std::string getName() const;

    /**
     * Gives back a description of this module.
     * \return description to module.
     */
    virtual const std::string getDescription() const;

93 94 95 96 97 98 99
    /**
     * Signal fired whenever a module main thread is ready.
     * 
     * \return the signal.
     */
    virtual boost::signal1< void, boost::shared_ptr< WModule > >* getModuleReadySignal();

100 101
protected:

102 103 104 105 106 107 108 109 110 111
    /**
     * Lock for module set.
     */
    boost::shared_mutex m_moduleSetLock;

    /**
     * The modules associated with this container.
     */
    std::set< boost::shared_ptr< WModule > > m_modules;

112 113 114 115 116 117 118 119 120
    /**
     * Name of the module.
     */
    std::string m_name;

    /**
     * Description of the module.
     */
    std::string m_description;
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
121

122 123 124 125 126 127 128 129 130 131 132 133
    /**
     * Signal fired whenever a module main thread is ready.
     */
    boost::signal1< void, boost::shared_ptr< WModule> > m_moduleReadySignal;

    /**
     * Gets called whenever a module has finished.
     * 
     * \param module the module which is now ready.
     */
    virtual void slotModuleReady( boost::shared_ptr< WModule > module );

134 135 136 137 138
private:
};

#endif  // WMODULECONTAINER_H