|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __WSPLUGINMANAGER_H__ |
|
17 #define __WSPLUGINMANAGER_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "Graphics/WSPLUGIN.H" |
|
21 #include <graphics/wsgraphicdrawerinterface.h> |
|
22 |
|
23 /** |
|
24 The window server has a single plugin manager object, which maintains the set |
|
25 of loaded plugins. |
|
26 */ |
|
27 class CWsPluginManager : public CBase, public MWsPluginManager |
|
28 { |
|
29 private: |
|
30 class CPluginInfo : public CBase |
|
31 { |
|
32 public: |
|
33 CPluginInfo(); |
|
34 ~CPluginInfo(); |
|
35 CWsPlugin * iPlugin; |
|
36 }; |
|
37 public: |
|
38 static CWsPluginManager* NewL(MWsGraphicDrawerEnvironment& aEnvironment); |
|
39 ~CWsPluginManager(); |
|
40 |
|
41 CWsPlugin * CreatePluginL(const TDesC& aSection); |
|
42 template <class T> T * FindImplementation(TInt & aStart); |
|
43 template <class T> T * FindNamedImplementation(const TDesC& aName); |
|
44 |
|
45 public: // from MWsObjectProvider: |
|
46 TAny * ResolveObjectInterface(TUint aId); |
|
47 |
|
48 public: // from MWsPluginManager |
|
49 TAny * ResolvePluginInterface(TUint aId); |
|
50 |
|
51 private: |
|
52 CWsPluginManager(MWsGraphicDrawerEnvironment& aEnvironment); |
|
53 void ConstructL(); |
|
54 |
|
55 private: |
|
56 RPointerArray<CPluginInfo> iPlugins; |
|
57 MWsGraphicDrawerEnvironment& iEnvironment; |
|
58 }; |
|
59 |
|
60 /** |
|
61 This searches for any plugin which implements a specified interface. |
|
62 Calling this function modifies the value of aStart, and passing it back in |
|
63 allows the next implementation to be found. |
|
64 */ |
|
65 template <class T> T * CWsPluginManager::FindImplementation(TInt & aStart) |
|
66 { |
|
67 while (aStart < iPlugins.Count()) |
|
68 { |
|
69 T * impl = iPlugins[aStart]->iPlugin->ObjectInterface<T>(); |
|
70 ++aStart; |
|
71 if (impl) |
|
72 { |
|
73 return impl; |
|
74 } |
|
75 } |
|
76 return NULL; |
|
77 } |
|
78 |
|
79 /** |
|
80 This searches for any plugin which implements a specified interface and |
|
81 has the specified name returned from PluginName. |
|
82 |
|
83 Maybe plugin name should be a function on an MWsNamed class instead of CWsPlugin? |
|
84 */ |
|
85 template <class T> T * CWsPluginManager::FindNamedImplementation(const TDesC& aName) |
|
86 { |
|
87 TInt pos = 0; |
|
88 while (pos < iPlugins.Count()) |
|
89 { |
|
90 T * impl = iPlugins[pos]->iPlugin->ObjectInterface<T>(); |
|
91 if (impl && iPlugins[pos]->iPlugin->PluginName() == aName) |
|
92 { |
|
93 return impl; |
|
94 } |
|
95 ++pos; |
|
96 } |
|
97 return NULL; |
|
98 } |
|
99 |
|
100 #endif // __WSPLUGINMANAGER_H__ |