RTXI 1.3
include/plugin.h
Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
00003 
00004  This program is free software: you can redistribute it and/or modify
00005  it under the terms of the GNU General Public License as published by
00006  the Free Software Foundation, either version 3 of the License, or
00007  (at your option) any later version.
00008 
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU General Public License for more details.
00013 
00014  You should have received a copy of the GNU General Public License
00015  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017  */
00018 
00019 #ifndef PLUGIN_H
00020 #define PLUGIN_H
00021 
00022 #include <list>
00023 #include <mutex.h>
00024 #include <settings.h>
00025 #include <string>
00026 #include <qobject.h>
00027 
00028 #include <sys/types.h>
00029 
00031 
00034 namespace Plugin {
00035 
00036     class Object;
00037 
00041     class Manager : public QObject {
00042 
00043         Q_OBJECT
00044 
00045         friend class Object;
00046 
00047     public:
00048 
00055         static Manager *getInstance(void);
00056 
00065         Object *load(const std::string &library);
00071         void unload(Object *object);
00075         void unloadAll(void);
00076 
00087         void foreachPlugin(void (*callback)(Plugin::Object *,void *),void *param);
00088 
00089     public slots:
00090 
00094         void customEvent(QCustomEvent *);
00095 
00096     private:
00097 
00098         /*****************************************************************
00099          * The constructor, destructor, and assignment operator are made *
00100          *   private to control instantiation of the class.              *
00101          *****************************************************************/
00102 
00103         Manager(void) : mutex(Mutex::RECURSIVE) {};
00104         ~Manager(void) {};
00105         Manager(const Manager &) {};
00106         Manager &operator=(const Manager &) { return *getInstance(); };
00107 
00108         static Manager *instance;
00109 
00110         void insertPlugin(Object *);
00111         void removePlugin(Object *);
00112 
00113         static const QEvent::Type CloseEvent = QEvent::User;
00114 
00115         Mutex mutex;
00116         std::list<Object *> pluginList;
00117 
00118     }; // class Manager
00119 
00123     class Object : public virtual Settings::Object {
00124 
00125         friend class Manager;
00126 
00127     public:
00128 
00129         Object(void);
00130         virtual ~Object(void);
00131 
00137         std::string getLibrary(void) const;
00138 
00143         void unload(void);
00144 
00145     private:
00146 
00147         static const u_int32_t MAGIC_NUMBER = 0xCA24CB3F;
00148 
00149         u_int32_t magic_number;
00150         std::string library;
00151         void *handle;
00152 
00153     }; // class Object
00154 
00155 }; // namespace Plugin
00156 
00157 #endif // PLUGIN_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines