|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "nmapiheaders.h" |
|
19 |
|
20 |
|
21 |
|
22 /*! |
|
23 \class NmApiDataPluginFactory |
|
24 \brief The NmApiDataPluginFactory class creates NmDataPlugin instance. |
|
25 |
|
26 */ |
|
27 NmApiDataPluginFactory *NmApiDataPluginFactory::mInstance = NULL; |
|
28 int NmApiDataPluginFactory::mReferenceCount = 0; |
|
29 QObject *NmApiDataPluginFactory::mPlugin = NULL; |
|
30 QPluginLoader *NmApiDataPluginFactory::mPluginLoader = NULL; |
|
31 |
|
32 /*! |
|
33 |
|
34 */ |
|
35 NmApiDataPluginFactory::NmApiDataPluginFactory() |
|
36 { |
|
37 NM_FUNCTION; |
|
38 } |
|
39 |
|
40 /*! |
|
41 |
|
42 */ |
|
43 NmApiDataPluginFactory::~NmApiDataPluginFactory() |
|
44 { |
|
45 NM_FUNCTION; |
|
46 |
|
47 if (mPlugin) { |
|
48 delete mPlugin; |
|
49 mPlugin = NULL; |
|
50 } |
|
51 |
|
52 if(mPluginLoader){ |
|
53 delete mPluginLoader; |
|
54 mPluginLoader = NULL; |
|
55 } |
|
56 } |
|
57 |
|
58 /*! |
|
59 |
|
60 */ |
|
61 NmApiDataPluginFactory *NmApiDataPluginFactory::instance() |
|
62 { |
|
63 NM_FUNCTION; |
|
64 |
|
65 if (!mInstance) { |
|
66 mInstance = new NmApiDataPluginFactory(); |
|
67 } |
|
68 mReferenceCount++; |
|
69 return mInstance; |
|
70 } |
|
71 |
|
72 /*! |
|
73 |
|
74 */ |
|
75 void NmApiDataPluginFactory::releaseInstance(NmApiDataPluginFactory *&instance) |
|
76 { |
|
77 NM_FUNCTION; |
|
78 |
|
79 //can't have passed out instances if we don't have any |
|
80 if (mInstance) { |
|
81 if (instance == mInstance) { |
|
82 instance = NULL; |
|
83 mReferenceCount--; |
|
84 } |
|
85 if (0 >= mReferenceCount) { |
|
86 delete mInstance; |
|
87 mInstance = NULL; |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 |
|
93 /*! |
|
94 |
|
95 */ |
|
96 NmDataPluginInterface *NmApiDataPluginFactory::interfaceInstance() |
|
97 { |
|
98 NM_FUNCTION; |
|
99 |
|
100 if (!mPlugin) { |
|
101 mPlugin = loadPlugin(); |
|
102 } |
|
103 return qobject_cast<NmDataPluginInterface*> (mPlugin); |
|
104 } |
|
105 |
|
106 /*! |
|
107 |
|
108 */ |
|
109 QObject *NmApiDataPluginFactory::loadPlugin() |
|
110 { |
|
111 NM_FUNCTION; |
|
112 |
|
113 if (!mPluginLoader) { |
|
114 const QString KPluginDirectory = "c:\\resource\\plugins"; |
|
115 QDir pluginDir = QDir(KPluginDirectory); |
|
116 const QString KFrameworkPluginName = "nmframeworkadapter.qtplugin"; |
|
117 /*! |
|
118 This creates plugin entity. |
|
119 */ |
|
120 mPluginLoader = new QPluginLoader(pluginDir.absoluteFilePath(KFrameworkPluginName)); |
|
121 |
|
122 mPlugin = mPluginLoader->instance(); |
|
123 if(!mPlugin){ |
|
124 // We don't have proper plugin instance, so we don't need it's loader. |
|
125 delete mPluginLoader; |
|
126 mPluginLoader = NULL; |
|
127 } |
|
128 } |
|
129 return mPlugin; |
|
130 } |
|
131 |
|
132 QObject *NmApiDataPluginFactory::plugin() |
|
133 { |
|
134 NM_FUNCTION; |
|
135 |
|
136 if (!mPlugin) { |
|
137 mPlugin = loadPlugin(); |
|
138 } |
|
139 return mPlugin; |
|
140 } |