File: pluginHandler.h

package info (click to toggle)
ball 1.4.3~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 318,984 kB
  • sloc: cpp: 346,579; ansic: 4,097; python: 2,664; yacc: 1,778; lex: 1,099; xml: 964; sh: 688; sql: 316; awk: 118; makefile: 108
file content (108 lines) | stat: -rw-r--r-- 3,304 bytes parent folder | download | duplicates (7)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef BALL_PLUGIN_PLUGINHANDLER_H
#define BALL_PLUGIN_PLUGINHANDLER_H


#ifndef BALL_COMMON_GLOBAL_H
# include <BALL/COMMON/global.h>
#endif

#include <list>
#include <QtCore/QReadWriteLock>

namespace BALL
{
	class BALLPlugin;

	/**
	 * A PluginHandler is a class that is responsible for initializing
	 * a certain plugin type. It provides the method canHandle() that
	 * checks whether a plugin can be initialized by the handler and
	 * has the purely virtual methods specificSetup_() and specificShutdown_()
	 * that provide plugin type specific initializations.
	 *
	 * Implementing a suitable PluginHandler is the second step besides
	 * defining the plugin interface itsself that is needed to create
	 * a new plugin api for BALL.
	 */
	class BALL_EXPORT PluginHandler
	{
		public:
			/**
			 * A virtual destructor. Does nothing at the moment.
			 */
			virtual ~PluginHandler();

			/**
			 * This function is used to check whether this PluginHandler can initialize
			 * the passed plugin. A usual implementation would be something like:
			 *
			 *   return qobject_cast<MyPlugin*>(plugin) != 0;
			 *
			 * @return true if the handler can make use of the plugin, false otherwise
			 */
			virtual bool canHandle(BALLPlugin* plugin) const = 0;

			/**
			 * This function checks whether the plugin can be handled and
			 * if it is not already running. Then the specificSetup()_ routine
			 * is called which should take care of all plugin specific initilizations.
			 *
			 * If specificSetup_() returns true, the plugin is added to the list of
			 * already running plugins.
			 *
			 * @return true if the plugin could be started, false otherwise.
			 */
			bool startPlugin(BALLPlugin* plugin);

			/**
			 * This function checks whether the plugin is currently running
			 * and atempts to stop it via the specificShutdown_() method. On
			 * success the plugin is removed from the list of running plugins.
			 *
			 * @return true if the plugin could be stopped, false otherwise.
			 */
			bool stopPlugin(BALLPlugin* plugin);

			/**
			 * This function must check if the passed plugin has been started
			 * by this handler
			 *
			 * @return true if the handler started the plugin, false otherwise
			 */
			virtual bool isRunning(BALLPlugin* plugin) const;

		protected:
			/**
			 * A purely virtual function which is responsible for
			 * properly initialising the passed plugin instance.
			 *
			 * The passed plugin may be assumed to be of a type that
			 * can be handled by this PluginHandler.
			 *
			 * @return true if the setup succeeded, false otherwise
			 */
			virtual bool specificSetup_(BALLPlugin* plugin) = 0;

			/**
			 * A purely virtual function which is responsible for
			 * properly deinitialising the passed plugin instance.
			 *
			 * The passed plugin may be assumed to be of a type that
			 * can be handled by this PluginHandler.
			 *
			 * @return true if the deinitialization succeeded, false otherwise
			 */
			virtual bool specificShutdown_(BALLPlugin* plugin) = 0;

			/**
			 * The list of plugins this handler is responsible for. Plugins should only
			 * be added/removed by using start/stopPlugin
			 */
			std::list<BALLPlugin*> running_plugins_;
		private:
			mutable QReadWriteLock mutex_;
	};
}

#endif //BALL_PLUGIN_PLUGINHANDLER_H