module.h

Go to the documentation of this file.
00001 /* A brick.
00002  *
00003  * PegSoft modules subsystem library (c) 2005 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software (the COPYING file); if not, write to the
00017  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
00018  * USA.
00019  *
00020  */
00021 
00027 #ifndef MODULES_MODULE_H
00028 #define MODULES_MODULE_H
00029 
00030 /*************************************************************************/
00031 
00032 #include <string>
00033 
00034 #include <modules/interface.h>
00035 
00036 /*************************************************************************/
00037 
00038 namespace conf { class ConfQ; class ConfGlobalQ; }
00039 namespace modules { class Core; }
00040 
00041 /*************************************************************************/
00042 
00043 namespace modules
00044 {
00045 
00046 /*************************************************************************/
00047 
00049 
00084 class Module
00085 {
00086     public:
00088 
00102         virtual int version() const = 0;
00103     
00104     public:
00106 
00118         Module(std::string const &name, std::string const &description,
00119                 std::string const &author = "", std::string const &url = "") :
00120                 m_name(name), m_description(description), m_author(author),
00121                 m_url(url), m_references(0), m_state(0), m_data(0) { }
00123         virtual ~Module() { }
00124         
00126 
00137         virtual conf::ConfQ *config(Core &core,
00138                 conf::ConfGlobalQ &global) { return 0; }
00139         
00141 
00158         virtual Interface *factory(PSIID iid) { return 0; }
00159         
00161 
00178         virtual Interface *interface(PSIID iid) { return 0; }
00179         
00181 
00203         virtual bool load(Core &core);
00204         
00206 
00211         ssize_t memory_usage() const { return -1; }
00212         
00214         enum
00215         {
00217             mnNone = 0,
00219             mnLoaded = 1,
00221             mnStarted = 2,
00223             mnStopped = 3,
00225 
00228             mnSync = 4,
00230 
00233             mnReconfig = 5,
00234             
00236             mnCoreDefined = 512,
00238             mnUserDefined = 4096
00239         };
00240         
00242 
00268         virtual void notify(Module &sender, int msg, void *arg) { }
00269         
00271 
00288         virtual bool query(std::string const &query, std::string &feedback)
00289                 { return false; }
00290         
00292 
00303         virtual void start(Core &core);
00304         
00306 
00325         virtual bool stop(Core &core);
00326                 
00328 
00340         virtual void unload(Core &core);
00341         
00343         virtual std::string const &name() const { return m_name; }
00345         virtual std::string const &description() const { return m_description; }
00347         virtual std::string const &author() const { return m_author; }
00349         virtual std::string const &url() const { return m_url; }
00350         
00352 
00357         int references() const { return m_references; }
00359 
00375         int references_add() { return ++m_references; }
00377 
00381         int references_remove() { return --m_references; }
00382         
00384         enum
00385         {
00387             msLoaded = 0x1,
00389             msStarted = 0x2
00390         };
00391         
00393 
00401         virtual int state() const { return m_state; }
00402         
00404         void *data() const { return m_data; }
00406         void data(void *data) { m_data = data; }
00407     protected:
00409         std::string m_name;
00411         std::string m_description;
00413         std::string m_author;
00415         std::string m_url;
00416         
00418         int m_references;
00419         
00421         int m_state;
00422     private:
00423         void *m_data;
00424     
00425         Module(Module const&);
00426         Module &operator=(Module const &);
00427 };
00428 
00429 /*************************************************************************/
00430 
00431 } /* namespace modules */
00432 
00433 /*************************************************************************/
00434 
00435 #endif /* MODULES_MODULE_H */

Generated on Sun May 20 21:32:14 2007 for Epona API by  doxygen 1.4.6