ButeoSynchronizationFramework
PluginManager.h
1 /*
2  * This file is part of buteo-syncfw package
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  * Copyright (C) 2014-2015 Jolla Ltd.
6  *
7  * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 #ifndef PLUGINMANAGER_H
25 #define PLUGINMANAGER_H
26 
27 #include <QString>
28 #include <QMap>
29 #include <QReadWriteLock>
30 #include <QProcess>
31 
32 namespace Buteo {
33 
34 class StorageChangeNotifierPlugin;
35 class StoragePlugin;
36 class ClientPlugin;
37 class ServerPlugin;
38 class PluginCbInterface;
39 class SyncProfile;
40 class Profile;
41 
42 class ClientPluginTest;
43 class ServerPluginTest;
44 class StoragePluginTest;
45 
46 // Location filters of plugin maps
47 const QString STORAGEMAP_LOCATION = "-storage.so";
48 const QString CLIENTMAP_LOCATION = "-client.so";
49 const QString SERVERMAP_LOCATION = "-server.so";
50 const QString STORAGECHANGENOTIFIERMAP_LOCATION = "-changenotifier.so";
51 
52 // OOP plugins binary name suffix
53 const QString OOP_CLIENT_SUFFIX = "-client";
54 const QString OOP_SERVER_SUFFIX = "-server";
55 
56 // Default directory from which to look for plugins
57 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
58 const QString DEFAULT_PLUGIN_PATH = "/usr/lib/buteo-plugins-qt5/";
59 const QString DEFAULT_OOP_PLUGIN_PATH = "/usr/lib/buteo-plugins-qt5/oopp";
60 #else
61 const QString DEFAULT_PLUGIN_PATH = "/usr/lib/buteo-plugins/";
62 #endif
63 
64 // The name of the function which is used to create a plugin
65 const QString CREATE_FUNCTION = "createPlugin";
66 
67 // The name of the function which is used to destroy a plugin
68 const QString DESTROY_FUNCTION = "destroyPlugin";
69 
70 typedef ClientPlugin* (*FUNC_CREATE_CLIENT)( const QString&,
71  const SyncProfile&,
72  PluginCbInterface* );
73 typedef void (*FUNC_DESTROY_CLIENT)( ClientPlugin* );
74 
75 typedef ServerPlugin* (*FUNC_CREATE_SERVER)( const QString&,
76  const Profile&,
77  PluginCbInterface* );
78 typedef void (*FUNC_DESTROY_SERVER)( ServerPlugin* );
79 
80 typedef StoragePlugin* (*FUNC_CREATE_STORAGE)(const QString&);
81 typedef void (*FUNC_DESTROY_STORAGE)(StoragePlugin*);
82 
83 typedef StorageChangeNotifierPlugin* (*FUNC_CREATE_STORAGECHANGENOTIFIER)(const QString&);
84 typedef void (*FUNC_DESTROY_STORAGECHANGENOTIFIER)(StorageChangeNotifierPlugin*);
85 
91 class PluginManager : public QObject
92 {
93  Q_OBJECT
94 
95 public:
100  PluginManager( const QString &aPluginPath = DEFAULT_PLUGIN_PATH );
101 
105  ~PluginManager();
106 
112  StorageChangeNotifierPlugin* createStorageChangeNotifier( const QString& aStorageName );
113 
119 
125  StoragePlugin* createStorage( const QString& aPluginName );
126 
131  void destroyStorage( StoragePlugin* aPlugin );
132 
140  ClientPlugin* createClient( const QString& aPluginName,
141  const SyncProfile& aProfile,
142  PluginCbInterface *aCbInterface );
143 
148  void destroyClient( ClientPlugin* aPlugin );
149 
157  ServerPlugin* createServer( const QString& aPluginName,
158  const Profile& aProfile,
159  PluginCbInterface *aCbInterface );
160 
165  void destroyServer( ServerPlugin *aPlugin );
166 
167 protected slots:
168 
169  void onProcessFinished( int exitCode, QProcess::ExitStatus exitStatus );
170 
171 private:
172 
173  struct DllInfo
174  {
175  QString iPath;
176  void* iHandle;
177  int iRefCount;
178 
179  DllInfo() : iHandle( NULL ), iRefCount( 0 ) { }
180  };
181 
182 
183  void loadPluginMaps( const QString aFilter, QMap<QString, QString>& aTargetMap );
184 
185  void loadOOPPluginMaps( const QString aFilter, QMap<QString, QString>& aTargetMap );
186 
187  void* loadDll( const QString& aPath );
188 
189  void* getDllHandle( const QString& aPath );
190 
191  void unloadDll( const QString& aPath );
192 
193  static bool killProcess( const QString& aPath );
194 
195  QProcess* startOOPPlugin( const QString& aPath,
196  const QString& aPluginName,
197  const QString& aProfileName );
198 
199  void stopOOPPlugin( const QString& aPath );
200 
201  QString iPluginPath;
202 
203  QMap<QString, QString> iStorageChangeNotifierMaps;
204  QMap<QString, QString> iStorageMaps;
205  QMap<QString, QString> iClientMaps;
206  QMap<QString, QString> iServerMaps;
207 
208  QMap<QString, QString> iOopClientMaps;
209  QMap<QString, QString> iOoPServerMaps;
210 
211  QList<DllInfo> iLoadedDlls;
212 
213  QReadWriteLock iDllLock;
214 
215  QString iProcBinaryPath;
216 
217 #ifdef SYNCFW_UNIT_TESTS
218  friend class ClientPluginTest;
219  friend class ServerPluginTest;
220  friend class StoragePluginTest;
221 #endif
222 
223 };
224 
225 }
226 
227 #endif
PluginManager(const QString &aPluginPath=DEFAULT_PLUGIN_PATH)
Constructor.
Definition: PluginManager.cpp:45
Manages plugins.
Definition: PluginManager.h:91
ServerPlugin * createServer(const QString &aPluginName, const Profile &aProfile, PluginCbInterface *aCbInterface)
Creates a new server plugin instance.
Definition: PluginManager.cpp:350
void destroyClient(ClientPlugin *aPlugin)
Destroys a client plugin instance.
Definition: PluginManager.cpp:304
Definition: AccountsHelper.h:31
~PluginManager()
Destructor.
Definition: PluginManager.cpp:63
void destroyStorage(StoragePlugin *aPlugin)
Destroys a storage plugin instance.
Definition: PluginManager.cpp:196
StorageChangeNotifierPlugin * createStorageChangeNotifier(const QString &aStorageName)
Creates a new storage change notifier plugin for the storage aStoragName.
Definition: PluginManager.cpp:77
Base class for server plugins.
Definition: ServerPlugin.h:36
void destroyStorageChangeNotifier(StorageChangeNotifierPlugin *aPlugin)
Destroys a storage change notifier plugin instance.
Definition: PluginManager.cpp:117
Interface which client and server plugins can use to communicate with synchronization daemon...
Definition: PluginCbInterface.h:38
Base class for client plugins.
Definition: ClientPlugin.h:37
Base class for storage plugins.
Definition: StoragePlugin.h:38
void destroyServer(ServerPlugin *aPlugin)
Destroys a server plugin.
Definition: PluginManager.cpp:419
StoragePlugin * createStorage(const QString &aPluginName)
Creates a new storage plugin instance.
Definition: PluginManager.cpp:155
ClientPlugin * createClient(const QString &aPluginName, const SyncProfile &aProfile, PluginCbInterface *aCbInterface)
Creates a new client plugin instance.
Definition: PluginManager.cpp:235
Implement this class to notify about changes in a specific storage - contacts/calendar/sms, or even custom ones like a facebook storage, if there&#39;s such a storage on the device.
Definition: StorageChangeNotifierPlugin.h:15