smf/smfservermodule/smfserver/pluginmgr/smfpluginmanager.h
changeset 14 a469c0e6e7fb
parent 7 be09cf1f39dd
child 18 013a02bf2bb0
equal deleted inserted replaced
13:b5d63d5fc252 14:a469c0e6e7fb
    20 #ifndef SMFPLUGINMANAGER_H_
    20 #ifndef SMFPLUGINMANAGER_H_
    21 #define SMFPLUGINMANAGER_H_
    21 #define SMFPLUGINMANAGER_H_
    22 
    22 
    23 #include <QtSql>
    23 #include <QtSql>
    24 #include <smfglobal.h>
    24 #include <smfglobal.h>
    25 #include <smfserverglobal.h>
    25 #include "smfserverglobal.h"
    26 #include "smfserver.h"
    26 #include "smfserver.h"
    27 
    27 
    28 // Forward declaration
    28 // Forward declaration
    29 class SmfPluginManagerUtil;
    29 class SmfPluginManagerUtil;
    30 class SmfTransportManagerUtil;
    30 class SmfTransportManagerUtil;
    62 	/**
    62 	/**
    63 	 * The input data for this request (if request need to be send again)
    63 	 * The input data for this request (if request need to be send again)
    64 	 */
    64 	 */
    65 	QByteArray iInputData;
    65 	QByteArray iInputData;
    66 	
    66 	
    67 	/**
       
    68 	 * The list of valid Urls accessible for this plugin
       
    69 	 */
       
    70 	QList<QUrl> iUrlList;
       
    71 
       
    72 	};
    67 	};
    73 
    68 
    74 
    69 
    75 /**
    70 /**
    76  * The Plugin Manager class manages the loading and unloading of plug-ins
    71  * The Plugin Manager class manages the loading and unloading of plug-ins
   106 	 * Manager to send the network request.
   101 	 * Manager to send the network request.
   107 	 * @param aSessionID The session ID provided by Smf Server
   102 	 * @param aSessionID The session ID provided by Smf Server
   108 	 * @param aPluginID The plugin ID that need to perform this operation
   103 	 * @param aPluginID The plugin ID that need to perform this operation
   109 	 * @param aOperation The type of operation to be performed
   104 	 * @param aOperation The type of operation to be performed
   110 	 * @param aInputData The data required to create the web query
   105 	 * @param aInputData The data required to create the web query
   111 	 * @return SmfPluginManagerResult The result of the operation
   106 	 * @return SmfError The result of the operation. It can be :-
   112 	 * @see smfglobal.h
   107 	 * SmfPluginNoError (if the request is sent successfully) or 
   113 	 */
   108 	 * SmfPluginLoadError (if plugin could not be loaded) or
   114 	SmfPluginManagerResult createRequest ( const quint32& aSessionID, 
   109 	 * SmfPluginNotAuthorised (if the plugin is not authorised) or
       
   110 	 * SmfPluginUnknownPluginService (if the requested service is not known or unsupported) or
       
   111 	 * SmfPluginRequestCreationFailed (if request creation has failed) or
       
   112 	 * SmfPluginSOPCheckFailed (if plugins request doesnot comply to the Same Origin Policy) or
       
   113 	 * SmfPluginRequestSendingFailed (if request could not be sent) or 
       
   114 	 * SmfPluginUnknownHttpService (if the plugin requested any unknown http 
       
   115 	 * method other than get, post, put, head or delete)  
       
   116 	 */
       
   117 	SmfError createRequest ( const quint32& aSessionID, 
   115 			const QString& aPluginID, 
   118 			const QString& aPluginID, 
   116 			const SmfRequestTypeID& aOperation, 
   119 			const SmfRequestTypeID& aOperation, 
   117 			QByteArray& aInputData );
   120 			QByteArray& aInputData );
   118 	
   121 	
   119 	/**
   122 	/**
   120 	 * Method called by Transport Manager when network response 
   123 	 * Method called by Transport Manager when network response is available
   121 	 * is available
       
   122 	 * @param aTransportResult The result of Transport Operation
   124 	 * @param aTransportResult The result of Transport Operation
   123 	 * @param aReply The QNetworkReply instance that requested 
   125 	 * @param aReply The QNetworkReply instance that requested 
   124 	 * this transaction
   126 	 * this transaction
   125 	 * @param aResponse The network response data
   127 	 * @param aResponse The network response data, may be NULL for error
   126 	 */
   128 	 */
   127 	void responseAvailable ( const SmfTransportResult &aTransportResult, 
   129 	void responseAvailable ( const SmfTransportResult &aTransportResult, 
   128 			QNetworkReply *aReply,
   130 			QNetworkReply *aReply,
   129 			QByteArray *aResponse );
   131 			QByteArray *aResponse );
   130 	
   132 	
   131 	/**
   133 	/**
   132 	 * Method to cancel the service request
   134 	 * Method to cancel the service request
   133 	 * @param aPluginId The plugin whose current operation 
   135 	 * @param aPluginId The plugin whose current operation is to be cancelled.
   134 	 * is to be cancelled
   136 	 * If the plugin is not loaded currently, this method just returns true.
       
   137 	 * @return Returns true if the plugin operation could be cancelled 
       
   138 	 * else returns false.
   135 	 */
   139 	 */
   136 	bool cancelRequest ( const QString& aPluginId );
   140 	bool cancelRequest ( const QString& aPluginId );
   137 	
   141 	
   138 	/**
   142 	/**
   139 	 * Method to get the list of the SmfProvider for all the plugins that implement 
   143 	 * Method to get the list of the SmfProvider for all the plugins that implement 
   140 	 * the mentioned Interface 
   144 	 * the mentioned Interface 
   141 	 * @param aInterface The interface for which list of plugins is required 
   145 	 * @param aInterface The interface for which list of plugins is required 
   142 	 * @param aMap The map of pluginID and its corresponding SmfProvider
   146 	 * @param aMap The map of pluginID and its corresponding SmfProvider. The Map 
       
   147 	 * will be empty if no plugins for the given interface could be found.
   143 	 */
   148 	 */
   144 	void getPlugins ( const QString& aInterface, 
   149 	void getPlugins ( const QString& aInterface, 
   145 			QMap<QString,SmfProvider>& aMap );
   150 			QMap<QString,SmfProvider>& aMap );
   146 	
   151 	
   147 	/**
   152 	/**
   148 	 * Method to get the pluginID for the mentioned interface and service provider 
   153 	 * Method to get the pluginID for the mentioned interface and service provider 
   149 	 * @param aInterface The interface implemented by the plugin
   154 	 * @param aInterface The interface implemented by the plugin
   150 	 * @param aProv The plugin's service provider
   155 	 * @param aProv The plugin's service provider
   151 	 * @param aPluginId The required pluginID
   156 	 * @param aPluginId The required pluginID. This argument will be empty if no plugin
       
   157 	 * for the given interface and service provider could be found.
   152 	 */
   158 	 */
   153 	void getPluginId ( const QString& aInterface, 
   159 	void getPluginId ( const QString& aInterface, 
   154 			const SmfProvider& aProv, QString& aPluginId );
   160 			const SmfProvider& aProv, QString& aPluginId );
   155 	
   161 	
   156 private:
   162 private:
   162 	
   168 	
   163 	/**
   169 	/**
   164 	 * Method called to initialize the database holding the plugin 
   170 	 * Method called to initialize the database holding the plugin 
   165 	 * directory sructure information. This is called only once when 
   171 	 * directory sructure information. This is called only once when 
   166 	 * the Plugin Manager is instantiated.
   172 	 * the Plugin Manager is instantiated.
   167 	 * This method creates and updates iPluginIdPathHash member 
   173 	 * This method creates and updates m_pluginIdPathHash member 
   168 	 * of this class
   174 	 * of this class
   169 	 * @return Retuns true if success else false
   175 	 * @return Returns true the database is successfully created and updated, 
       
   176 	 * else returns false
   170 	 */
   177 	 */
   171 	bool initializeSmfPluginDataBase ( );
   178 	bool initializeSmfPluginDataBase ( );
   172 	
   179 	
   173 	/**
   180 	/**
   174 	 * Method to load a plugin using its Plugin Id.
   181 	 * Method to load a plugin using its Plugin Id.
   175 	 * @param aPluginId The unique ID of the plugin 
   182 	 * @param aPluginId The unique ID of the plugin 
   176 	 * @param aLoadResult [out] Output paramater indicating the result 
   183 	 * @param aLoadResult [out] Output paramater indicating the result 
   177 	 * of the loading
   184 	 * of the loading. It can be:-
       
   185 	 * SmfPluginNoError (if plugin was loaded successfully) or 
       
   186 	 * SmfPluginNotLoaded (if plugin could not be loaded) or 
       
   187 	 * SmfPluginNotFound (if plugin with the given id could not be found)
   178 	 * @return The instance of the loaded plugin if loaded, else NULL
   188 	 * @return The instance of the loaded plugin if loaded, else NULL
   179 	 */
   189 	 */
   180 	QObject* load ( const QString &aPluginId, 
   190 	QObject* load ( const QString &aPluginId, 
   181 			SmfPluginManagerResult &aLoadResult);
   191 			SmfError &aLoadResult);
   182 	
   192 	
   183 	/**
   193 	/**
   184 	 * Method to unload a loaded plugin. Returns true if success, else 
   194 	 * Method to unload a loaded plugin. Returns true if success, else 
   185 	 * returns false.
   195 	 * returns false.
   186 	 * @param aPlugin The plugin instance to be unloaded
   196 	 * @param aPlugin The plugin instance to be unloaded
   187 	 * @return Returns true if success, else returns false
   197 	 * @return Returns true if the mentioned plugin could be unloaded. Returns 
       
   198 	 * false, if the plugin instance is NULL, or if it could not be unloaded.
   188 	 */
   199 	 */
   189 	bool unload ( SmfPluginBase *aPlugin ); 
   200 	bool unload ( SmfPluginBase *aPlugin ); 
   190 	
   201 	
   191 	/**
   202 	/**
   192 	 * Method to unload the list of loaded plugins. Returns true if all are 
   203 	 * Method to unload the list of loaded plugins. Returns true if all unload 
   193 	 * success, else returns false if any one fails.
   204 	 * are success, else returns false if any one fails.
   194 	 * @param aPluginList The list of instances for all plugins that are 
   205 	 * @param aPluginList The list of instances for all plugins that are 
   195 	 * to be unloaded
   206 	 * to be unloaded. This method does nothing and returns false if the list is empty.
   196 	 * @return Returns true if all are success, else returns false if any 
   207 	 * @return Returns true if all are success, else returns false if any 
   197 	 * one fails.
   208 	 * one fails. Also returns false if the input list is empty.
   198 	 */
   209 	 */
   199 	bool unload ( const QList<SmfPluginBase*> &aPluginList);
   210 	bool unload ( const QList<SmfPluginBase*> &aPluginList);
   200 	
   211 	
   201 	/**
   212 	/**
   202 	 * Method that calls the Transport Manager Utility class method to 
   213 	 * Method that calls the Transport Manager Utility class method to 
   203 	 * send the request created by the plugins over the network
   214 	 * send the request created by the plugins over the network
   204 	 * @param aReqData The request data created by the plugin
   215 	 * @param aReqData The request data created by the plugin
   205 	 * @param aResult [out] The output parameter indicating the result 
   216 	 * @param aResult [out] The output parameter indicating the result 
   206 	 * of this method
   217 	 * of this method. This can be :-
       
   218 	 * SmfPluginNoError (if the request is sent successfully) or 
       
   219 	 * SmfPluginSOPCheckFailed (if plugins request doesnot comply to 
       
   220 	 * the Same Origin Policy) or 
       
   221 	 * SmfPluginRequestSendingFailed (if request could not be sent) or 
       
   222 	 * SmfPluginUnknownHttpService (if the plugin requested any unknown http 
       
   223 	 * method other than get, post, put, head or delete)  
   207 	 * @param aUrlList The list of accessible Urls for this plugin
   224 	 * @param aUrlList The list of accessible Urls for this plugin
   208 	 * @see smfglobal.h
       
   209 	 */
   225 	 */
   210 	void sendRequest ( SmfPluginRequestData &aReqData, 
   226 	void sendRequest ( SmfPluginRequestData &aReqData, 
   211 			SmfPluginManagerResult &aResult,
   227 			SmfError &aResult,
   212 			const QList<QUrl> &aUrlList );
   228 			const QList<QUrl> &aUrlList );
   213 	
   229 	
   214 	/**
   230 	/**
   215 	 * Method that checks if a plugin is authorised to make a request. 
   231 	 * Method that checks if a plugin is authorised to make a request. 
   216 	 * This method communicates with Credential and Settings Manager 
   232 	 * This method communicates with Credential and Settings Manager 
   217 	 * through Smf server, giving the registration token and getting 
   233 	 * through Smf server, giving the registration token and getting 
   218 	 * the valid url list if available for this plugin.
   234 	 * the valid url list if available for this plugin.
   219 	 * @param aRegToken The registration token given by the plugin
   235 	 * @param aRegToken The registration token given by the plugin
   220 	 * @param aUrlList [out] The list of Urls that the plugin can send 
   236 	 * @param aUrlList [out] The list of Urls that the plugin can send 
   221 	 * request to (to be filled by CSM)
   237 	 * request to (to be filled by CSM). This list will be empty if 
       
   238 	 * aRegToken is empty
   222 	 * @return Returns true if plugin is authorised, else returns false.
   239 	 * @return Returns true if plugin is authorised, else returns false.
       
   240 	 * Also returns false if aRegToken is empty.
   223 	 */
   241 	 */
   224 	bool authorisePlugin( const QString &aRegToken, 
   242 	bool authorisePlugin( const QString &aRegToken, 
   225 			QList<QUrl> &aUrlList );
   243 			QList<QUrl> &aUrlList );
   226 	
   244 	
   227 	/**
   245 	/**
   228 	 * Method to serialize the result of parsing (which is done by the 
   246 	 * Method to serialize the result of parsing (which is done by the 
   229 	 * plugins) to QByteArray to be sent to Smf server.
   247 	 * plugins) to QByteArray to be sent to Smf server.
   230 	 * @param aOperation The type of operation to be performed
   248 	 * @param aOperation The type of operation to be performed
   231 	 * @param aResult The data to be serialized
   249 	 * @param aResult The data to be serialized (should not be NULL)
   232 	 * @param aDataStream Stream to be written
   250 	 * @param aDataStream Stream to be written to
   233 	 */
   251 	 */
   234 	void serializeResult ( const SmfRequestTypeID &aOperation, 
   252 	void serializeResult ( const SmfRequestTypeID &aOperation, 
   235 			QVariant* aResult,
   253 			QVariant* aResult,
   236 			QDataStream &aDataStream );
   254 			QDataStream &aDataStream );
   237 	
   255