|
1 // Copyright (c) 2005-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 // @file |
|
15 // |
|
16 // |
|
17 |
|
18 #include <aprulebased.h> |
|
19 #include <aplaunchchecker.h> |
|
20 #include "APFSTD.H" // Panics etc. |
|
21 |
|
22 void CleanUpEComInfoArray(TAny* aInfoArray); |
|
23 |
|
24 // |
|
25 // CApaRuleBasedDll |
|
26 // |
|
27 /** The rule-based framework. Mantain all rule-based plug-ins available in the system */ |
|
28 class CApaRuleBasedDll : public CBase |
|
29 { |
|
30 public: |
|
31 CApaRuleBasedDll(); |
|
32 ~CApaRuleBasedDll(); // closes lib and deletes next |
|
33 public: |
|
34 enum TPresence { ENotPresent, EIsPresent }; |
|
35 inline TPresence Present() const { return iPresent; } |
|
36 inline void Present(TPresence aPresence) { iPresent = aPresence; } |
|
37 inline TUid Uid() const { return iUid; } |
|
38 inline void Uid(TUid aUid) { iUid = aUid; } |
|
39 inline CAppLaunchChecker* LaunchChecker() { return iLaunchChecker; } |
|
40 inline void LaunchChecker(CAppLaunchChecker* aLaunchChecker) { iLaunchChecker = aLaunchChecker; } |
|
41 private: |
|
42 TPresence iPresent; |
|
43 TUid iUid; |
|
44 CAppLaunchChecker* iLaunchChecker; // pointer to plug-in implementation |
|
45 }; |
|
46 |
|
47 CApaRuleBasedDll::CApaRuleBasedDll() |
|
48 { |
|
49 } |
|
50 |
|
51 CApaRuleBasedDll::~CApaRuleBasedDll() |
|
52 { |
|
53 delete iLaunchChecker; |
|
54 } |
|
55 |
|
56 /** The function provides access to launch checker interface by index */ |
|
57 EXPORT_C CAppLaunchChecker* CApaScanningRuleBasedPlugIns::operator[](TInt aIndex) const |
|
58 { |
|
59 return iRuleBasedLib[aIndex]->LaunchChecker(); |
|
60 } |
|
61 |
|
62 EXPORT_C CApaScanningRuleBasedPlugIns* CApaScanningRuleBasedPlugIns::NewL() |
|
63 { |
|
64 CApaScanningRuleBasedPlugIns* self = new(ELeave) CApaScanningRuleBasedPlugIns(); |
|
65 CleanupStack::PushL(self); |
|
66 self -> ScanForRuleBasedPlugInsL(); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 EXPORT_C CApaScanningRuleBasedPlugIns::~CApaScanningRuleBasedPlugIns() |
|
72 { |
|
73 iRuleBasedLib.ResetAndDestroy(); |
|
74 } |
|
75 |
|
76 /** The function loads the ecom rule-based plug-ins */ |
|
77 void CApaScanningRuleBasedPlugIns::LoadEcomRuleBasedPlugInL(TUid aUid) |
|
78 { |
|
79 // check we haven't loaded this one already |
|
80 for(TInt index = 0; index < iRuleBasedLib.Count(); index++) |
|
81 { |
|
82 CApaRuleBasedDll* lib = iRuleBasedLib[index]; |
|
83 if (lib->Uid() == aUid) |
|
84 {// already found |
|
85 lib -> Present(CApaRuleBasedDll::EIsPresent); |
|
86 return; |
|
87 } |
|
88 } |
|
89 |
|
90 // load the library |
|
91 CApaRuleBasedDll* lib = new(ELeave) CApaRuleBasedDll(); |
|
92 CleanupStack::PushL(lib); |
|
93 TRAPD(error, lib -> LaunchChecker(CAppLaunchChecker::NewL(aUid))); |
|
94 if((error == KErrNone) && lib -> LaunchChecker()) |
|
95 { |
|
96 lib->Present(CApaRuleBasedDll::EIsPresent); |
|
97 lib->Uid(aUid); |
|
98 |
|
99 // add lib to the library list |
|
100 iRuleBasedLib.Append(lib); |
|
101 CleanupStack::Pop(lib); |
|
102 } |
|
103 else |
|
104 { |
|
105 CleanupStack::PopAndDestroy(lib); |
|
106 } |
|
107 } |
|
108 |
|
109 /** The function scans and initializes all rule-based plug-ins available in the system */ |
|
110 EXPORT_C void CApaScanningRuleBasedPlugIns::ScanForRuleBasedPlugInsL() |
|
111 { |
|
112 // set all rule based plug-ins to not present - pending rediscoivery |
|
113 TInt index; |
|
114 for (index = 0; index < iRuleBasedLib.Count(); index++) |
|
115 { |
|
116 CApaRuleBasedDll* rule = iRuleBasedLib[index]; |
|
117 rule -> Present(CApaRuleBasedDll::ENotPresent); |
|
118 } |
|
119 |
|
120 //scan ecom plugin |
|
121 RImplInfoPtrArray implementationArray; |
|
122 TCleanupItem cleanup(CleanUpEComInfoArray, &implementationArray); |
|
123 CleanupStack::PushL(cleanup); |
|
124 REComSession::ListImplementationsL(KUidRuleBasedInterfaceUid, implementationArray); |
|
125 const TInt availCount = implementationArray.Count(); |
|
126 for (TInt count = 0; count < availCount; ++count) |
|
127 { |
|
128 const CImplementationInformation* info = implementationArray[count]; |
|
129 TUid uid = info -> ImplementationUid(); |
|
130 LoadEcomRuleBasedPlugInL(uid); |
|
131 } |
|
132 CleanupStack::PopAndDestroy(&implementationArray); |
|
133 |
|
134 // remove any rule based plug-ins that are no longer present |
|
135 index = 0; |
|
136 while (index < iRuleBasedLib.Count()) |
|
137 { |
|
138 CApaRuleBasedDll* rule = iRuleBasedLib[index]; |
|
139 if (rule -> Present() == CApaRuleBasedDll::ENotPresent) |
|
140 { |
|
141 iRuleBasedLib.Remove(index); |
|
142 delete rule; |
|
143 } |
|
144 else |
|
145 { |
|
146 index++; |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 /** The function returns number of plug-ins available in the system*/ |
|
152 EXPORT_C TInt CApaScanningRuleBasedPlugIns::ImplementationCount() const |
|
153 { |
|
154 return iRuleBasedLib.Count(); |
|
155 } |
|
156 |
|
157 |