RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
plugin.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef PLUGIN_H
21 #define PLUGIN_H
22 
23 #include <list>
24 #include <mutex.h>
25 #include <settings.h>
26 #include <string>
27 #include <sys/types.h>
28 #include <QObject>
29 #include <QtWidgets>
30 
32 
35 namespace Plugin
36 {
37 
38 class Object;
39 
40 static const QEvent::Type CloseEvent = QEvent::User;
41 
46 class RTXIEvent : public QEvent
47 {
48 
49 public:
50  RTXIEvent() : QEvent((QEvent::Type) CloseEvent) {}
51  void *data;
52 };
53 
57 class Manager : public QObject
58 {
59 
60  Q_OBJECT
61 
62  friend class Object;
63 
64 public:
65 
72  static Manager *getInstance(void);
73 
82  Object *load(const QString &library);
83 
89  void unload(Object *object);
90 
94  void unloadAll(void);
95 
106  void foreachPlugin(void (*callback)(Plugin::Object *,void *),void *param);
107 
108 public slots:
109 
113  void customEvent(QEvent *);
114 
115 private:
116 
117  /*****************************************************************
118  * The constructor, destructor, and assignment operator are made *
119  * private to control instantiation of the class. *
120  *****************************************************************/
121 
122  Manager(void) : mutex(Mutex::RECURSIVE) {};
123  ~Manager(void) {};
124  Manager(const Manager &) {};
126  {
127  return *getInstance();
128  };
129 
130  static Manager *instance;
131 
132  void insertPlugin(Object *);
133  void removePlugin(Object *);
134 
135  //static const QEvent::Type CloseEvent = QEvent::User;
136 
138  std::list<Object *> pluginList;
139 
140 }; // class Manager
141 
145 class Object : public virtual Settings::Object
146 {
147 
148  friend class Manager;
149 
150 public:
151 
152  Object(void);
153  virtual ~Object(void);
154 
160  std::string getLibrary(void) const;
161 
166  void unload(void);
167 
168 private:
169 
170  static const u_int32_t MAGIC_NUMBER = 0xCA24CB3F;
171  u_int32_t magic_number;
172  std::string library;
173  void *handle;
174 
175 }; // class Object
176 
177 }; // namespace Plugin
178 
179 #endif // PLUGIN_H
Object(void)
Definition: plugin.cpp:26
static const u_int32_t MAGIC_NUMBER
Definition: plugin.h:170
Manager(void)
Definition: plugin.h:122
void removePlugin(Object *)
Definition: plugin.cpp:150
Manager(const Manager &)
Definition: plugin.h:124
void * data
Definition: plugin.h:51
Mutex mutex
Definition: plugin.h:137
std::list< Object * > pluginList
Definition: plugin.h:138
Definition: mutex.h:28
static Manager * instance
Definition: plugin.h:128
void unload(void)
Definition: plugin.cpp:41
void unload(Object *object)
Definition: plugin.cpp:99
Manager & operator=(const Manager &)
Definition: plugin.h:125
Object * load(const QString &library)
Definition: plugin.cpp:46
void unloadAll(void)
Definition: plugin.cpp:116
~Manager(void)
Definition: plugin.h:123
static Manager * getInstance(void)
Definition: plugin.cpp:186
void foreachPlugin(void(*callback)(Plugin::Object *, void *), void *param)
Definition: plugin.cpp:131
std::string library
Definition: plugin.h:172
virtual ~Object(void)
Definition: plugin.cpp:31
void * handle
Definition: plugin.h:173
void customEvent(QEvent *)
Definition: plugin.cpp:162
Classes associated with the loading/unloading of binaries at run-time.
Definition: plugin.h:35
std::string getLibrary(void) const
Definition: plugin.cpp:36
u_int32_t magic_number
Definition: plugin.h:171
void insertPlugin(Object *)
Definition: plugin.cpp:138