qtecomplugins/xqplugins/src/xqpluginloader.cpp
changeset 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:  Class implement extended wrapper for ECom framework
       
    19 *
       
    20 */
       
    21 
       
    22 #include "xqpluginloader.h"
       
    23 #include "xqpluginloaderprivate.h"
       
    24 
       
    25 #include <qfileinfo.h>
       
    26 #include "qdebug.h"
       
    27 // -----------------------------------------------------------------------------
       
    28 // XQPluginLoader()
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 XQPluginLoader::XQPluginLoader(QObject* parent) 
       
    32 : 
       
    33 QObject(parent),
       
    34 d(0),
       
    35 did_load( false )
       
    36 {
       
    37 }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // XQPluginLoader(int, QObject*)
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 XQPluginLoader::XQPluginLoader(int requestedUid, QObject* parent) 
       
    44 : 
       
    45 QObject(parent),
       
    46 d(XQPluginLoaderPrivate::findOrCreate(requestedUid)), 
       
    47 did_load( false )
       
    48 {
       
    49 }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // ~XQPluginLoader2()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 XQPluginLoader::~XQPluginLoader()
       
    56 {
       
    57     if(d) {
       
    58         d->release();
       
    59     }
       
    60 }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // listImplementations(const QString &interfaceName, QList<XQPluginInfo> &impls)
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 bool XQPluginLoader::listImplementations(
       
    67         const QString &interfaceName, 
       
    68         QList< XQPluginInfo > &impls)
       
    69 {
       
    70     RImplInfoPtrArray infoArr;
       
    71     TRAPD( errCode, XQPluginLoaderPrivate::listImplementationsL( infoArr, interfaceName, impls ) );
       
    72     infoArr.ResetAndDestroy();
       
    73     return ( KErrNone == errCode );
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // uid()
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 int XQPluginLoader::uid()const
       
    81 {
       
    82     return ( d ? d->uid : KNullUid.iUid );
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // instance()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 QObject* XQPluginLoader::instance()
       
    90 {
       
    91     if (!load())
       
    92         return 0;
       
    93 #ifndef Q_OS_SYMBIAN
       
    94     if (d->instance)
       
    95         return d->instance();
       
    96 	else
       
    97 		return 0;
       
    98 #else
       
    99     return d->instance();
       
   100 #endif
       
   101     
       
   102 }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // isLoaded()
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 bool XQPluginLoader::isLoaded() const
       
   109 {
       
   110     return d && d->pHnd
       
   111 #ifndef Q_OS_SYMBIAN
       
   112         && d->instance;
       
   113 #else
       
   114         ;
       
   115 #endif    
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // load()
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 bool XQPluginLoader::load()
       
   123 {
       
   124     if (!d)
       
   125         return false;
       
   126     if (did_load)
       
   127         return d->pHnd;
       
   128     did_load = true;
       
   129     return d->loadPlugin();
       
   130 }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // unload()
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 bool XQPluginLoader::unload()
       
   137 {
       
   138     if (did_load) {
       
   139         did_load = false;
       
   140         return d->unload();
       
   141     }
       
   142     if (d)  // Ouch
       
   143         d->errorString = tr("The plugin was not loaded.");
       
   144     return false;
       
   145 }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // setUid ( int )
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void XQPluginLoader::setUid ( int uid )
       
   152 {
       
   153     if (d) {
       
   154         d->release();
       
   155         d = 0;
       
   156         did_load = false;
       
   157     }
       
   158     d = XQPluginLoaderPrivate::findOrCreate( uid );
       
   159 }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // errorString ()
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 QString XQPluginLoader::errorString () const
       
   166 {
       
   167     return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString;
       
   168 }