homescreensrv_plat/servicemodel_api/servicefinder.h
changeset 66 32469d7d46ff
parent 61 8e5041d13c84
child 73 4bc7b118b3df
equal deleted inserted replaced
61:8e5041d13c84 66:32469d7d46ff
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  HsService Finder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SERVICEFINDER_H
       
    20 #define SERVICEFINDER_H
       
    21 
       
    22 #include <QObject>
       
    23 #include "serviceinterfaceid.h"
       
    24 #include "hsiserviceprovider.h"
       
    25 #include "servicemodel_global.h"
       
    26 
       
    27 class IHsServiceBase;
       
    28 class HsServiceFinderPrivate;
       
    29 class HsService;
       
    30 
       
    31 /**
       
    32  * @ingroup group_hsservicemodel group_service_api_candidates
       
    33  * @brief Helper class to search and create services.
       
    34  * HsService adapter is the component to find different platform service implementations
       
    35  * and offer interface to use services.
       
    36  */
       
    37 class HSSERVICEMODEL_EXPORT HsServiceFinder : public QObject
       
    38 {
       
    39 	Q_OBJECT
       
    40 
       
    41 public:
       
    42 
       
    43     /**
       
    44      * Constructor.
       
    45      * @since S60 ?S60_version.
       
    46      * @param aPluginManifestDirectory Directory that contains plugin manifests.
       
    47      * @param aPluginDirectory Directory that contains plugin binaries.
       
    48      * @param aParent Parent object.
       
    49      */
       
    50     HsServiceFinder(const QString& aPluginManifestDirectory,
       
    51                   const QString& aPluginDirectory,
       
    52                   QObject* aParent = 0);
       
    53 
       
    54   
       
    55     /**
       
    56     * Destructor    
       
    57     */
       
    58     virtual ~HsServiceFinder();
       
    59 
       
    60 public:
       
    61 
       
    62     /**
       
    63      * Get list of all services in the device implemented according the service architecture.
       
    64      * @return list of services (empty list if no services in the device).
       
    65      */
       
    66     QList<HsServiceToken> getServiceList();
       
    67 
       
    68     /**
       
    69      * Get list of all services in the device implemented according the service architecture.
       
    70      * @param aService for example 'BackupService'
       
    71      * @return list of matched services (empty list if no services in the device).
       
    72      * @code
       
    73      * if (!mServiceFinder)
       
    74      *     {
       
    75      *     mServiceFinder = new HsServiceFinder("c:/hsplugins","c:/hsplugins",this);
       
    76      *     }
       
    77      * IBackupService* service = 0;
       
    78      * QList<HsServiceToken> serviceList = mServiceFinder->getServiceList(IBackupService::type().mImplementationId );
       
    79      * if ( serviceList.count() )
       
    80      *     {
       
    81      *     // use first found service
       
    82      *     service = mServiceFinder->getService<IBackupService>(IBackupService::type(), serviceList.at(0));
       
    83      *     }
       
    84      *
       
    85      * @endcode
       
    86      */
       
    87     QList<HsServiceToken> getServiceList(const QString &aService);
       
    88 
       
    89     /**
       
    90      * Get service. This method returns the service as a QObject.
       
    91      * @param aService for example 'HsService.Messaging'
       
    92      * @param aInterface for example 'IMessaging'
       
    93      * @return pointer to HsService object. Ownership is NOT transferred to caller.
       
    94      * @see releaseService
       
    95      * @code
       
    96      * if (!mServiceFinder)
       
    97      *     {
       
    98      *     mServiceFinder = new HsServiceFinder("c:/hsplugins","c:/hsplugins",this);
       
    99      *     }
       
   100      * HsService* servicePtr = mServiceFinder->getService("HsService.Messaging", "IMessaging");
       
   101      * @endcode
       
   102      */
       
   103     HsService *getService(const QString &aService, const QString &aInterface);
       
   104 
       
   105     /**
       
   106      * Get service. This method returns the service as an abstract interface.
       
   107      * @param aInterfaceId service interface identifier
       
   108      * @param aPluginName which plugin implements this service, if empty, then first found interface is used.
       
   109      * @return pointer to service interface object. Ownership is NOT transferred to caller.
       
   110      *
       
   111      * Example in source code:
       
   112      * @code
       
   113      * if (!mServiceFinder)
       
   114      *     {
       
   115      *     mServiceFinder = new HsServiceFinder("c:/hsplugins","c:/hsplugins",this);
       
   116      *     }
       
   117      * IBackupService* service = 0;
       
   118      * service = mServiceFinder->getService<IBackupService>(IBackupService::type(), "backupservice");
       
   119      * if ( service )
       
   120      *     {
       
   121      *     service->backupPage();
       
   122      *     }
       
   123      * @endcode
       
   124      * where IBackupService is defined in header file:
       
   125      * @code
       
   126      * static const HsServiceInterfaceId Identifier=
       
   127      *     {
       
   128      *     0,"persistanceservice"
       
   129      *     };
       
   130      *
       
   131      * class IBackupService: public IHsServiceBase
       
   132      * {
       
   133      * public:
       
   134      * static inline const HsServiceInterfaceId& type()
       
   135      *     {
       
   136      *     return Identifier;
       
   137      *     }
       
   138      * public:
       
   139      * virtual void backupPage() = 0;
       
   140      * virtual IHsServiceBase* resolveService(const HsServiceInterfaceId& aType) = 0;
       
   141      * ... other possible API functions
       
   142      * @endcode
       
   143      * @see more details in example backupservice implementation, IBackupService, PersistanceService...
       
   144      */
       
   145     template<class T> T *getService(const HsServiceInterfaceId &aInterfaceId, const QString &aPluginName)
       
   146     {
       
   147         return static_cast<T*>(getService(aInterfaceId, aPluginName));
       
   148     }
       
   149 
       
   150     /**
       
   151      * Get service. This method returns the service as an abstract interface.
       
   152      * @param aInterfaceId service interface identifier
       
   153      * @param aToken which plugin implements this service
       
   154      * @return pointer to service interface object. Ownership is NOT transferred to caller.
       
   155      *
       
   156      * @code
       
   157      * if (!mServiceFinder)
       
   158      *     {
       
   159      *     mServiceFinder = new HsServiceFinder("c:/hsplugins","c:/hsplugins",this);
       
   160      *     }
       
   161      * IBackupService* service = 0;
       
   162      * QList<HsServiceToken> serviceList = mServiceFinder->getServiceList(IBackupService::type().mImplementationId);
       
   163      * if ( serviceList.count() )
       
   164      *     {
       
   165      *     // use first found service
       
   166      *     service = mServiceFinder->getService<IBackupService>(IBackupService::type(), serviceList.at(0));
       
   167      *     }
       
   168      * if ( service )
       
   169      *     {
       
   170      *     service->backupPage();
       
   171      *     }
       
   172      * @endcode
       
   173      */
       
   174     template<class T> T *getService(const HsServiceInterfaceId &aInterfaceId, const HsServiceToken &aToken)
       
   175     {
       
   176         return static_cast<T*>(getService(aInterfaceId, aToken));
       
   177     }
       
   178 
       
   179     /**
       
   180      * Get service. This method returns the service as an Base interface of the all services.
       
   181      * @param aInterfaceId service interface identifier
       
   182      * @param aPluginName which plugin implements this service
       
   183      * @return pointer to service interface object. Ownership is NOT transferred to caller.
       
   184      */
       
   185     IHsServiceBase *getService(const HsServiceInterfaceId &aInterfaceId, const QString &aPluginName);
       
   186 
       
   187     /**
       
   188      * Get service. This method returns the service as an Base interface of the all services.
       
   189      * @param aInterfaceId service interface identifier
       
   190      * @param aToken which plugin implements this service
       
   191      * @return pointer to service interface object. Ownership is NOT transferred to caller.
       
   192      */
       
   193     IHsServiceBase *getService(const HsServiceInterfaceId &aInterfaceId, const HsServiceToken &aToken);
       
   194 
       
   195     /**
       
   196      * Release service
       
   197      * @param aService service to be released and deleted. HsService is QObject based service.
       
   198      */
       
   199     void releaseService(HsService *aService);
       
   200 
       
   201     /**
       
   202      * Cancels asynchronous service requests.
       
   203      * @param aService QObject based service.
       
   204      */
       
   205     void cancel(HsService *aService);
       
   206 
       
   207 private:
       
   208 
       
   209     /**
       
   210      * The private implementation.
       
   211      */
       
   212     HsServiceFinderPrivate *mServiceFinderPrivate;
       
   213 
       
   214 };
       
   215 
       
   216 #endif