|
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 * ============================================================================ |
|
19 * TODO: Appropriate header needs to go here |
|
20 * ============================================================================ |
|
21 */ |
|
22 |
|
23 #include <ecompluginnotifier.h> |
|
24 #include <coemain.h> |
|
25 |
|
26 |
|
27 EXPORT_C TEComPluginInfo::TEComPluginInfo(const TUid& aUid, const TInt aVersion, const TDriveUnit& aDrive) |
|
28 : iUid(aUid), iVersion(aVersion), iDrive(aDrive) |
|
29 { |
|
30 } |
|
31 |
|
32 |
|
33 |
|
34 CEComPluginNotifier::CEComPluginNotifier(const TUid& aInterfaceId, TCallBack& aCallBack) |
|
35 :CActive(EActivePriorityDefault), iInterfaceId(aInterfaceId), iCallBack(aCallBack) |
|
36 { |
|
37 // TODO: What happens if this fails? |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 |
|
42 void CEComPluginNotifier::ConstructL() |
|
43 { |
|
44 iEComSession = &REComSession::OpenL(); |
|
45 } |
|
46 |
|
47 |
|
48 CEComPluginNotifier::~CEComPluginNotifier() |
|
49 { |
|
50 Cancel(); |
|
51 if (iEComSession) |
|
52 { |
|
53 iEComSession->Close(); |
|
54 iEComSession = NULL; |
|
55 } |
|
56 iPreviousPlugins.Reset(); |
|
57 } |
|
58 |
|
59 |
|
60 EXPORT_C CEComPluginNotifier* CEComPluginNotifier::NewL(const TUid& iInterfaceId, TCallBack& aCallBack) |
|
61 { |
|
62 CEComPluginNotifier* self = CEComPluginNotifier::NewLC(iInterfaceId, aCallBack); |
|
63 CleanupStack::Pop(self); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 EXPORT_C CEComPluginNotifier* CEComPluginNotifier::NewLC(const TUid& iInterfaceId, TCallBack& aCallBack) |
|
69 { |
|
70 CEComPluginNotifier* self = new (ELeave) CEComPluginNotifier(iInterfaceId, aCallBack); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 |
|
77 EXPORT_C void CEComPluginNotifier::Start() |
|
78 { |
|
79 // Load initial list of plugins for the UID |
|
80 if(iInterfaceId.iUid != 0) |
|
81 EComPluginUtils::GetInfoArrayL(iInterfaceId, iPreviousPlugins); |
|
82 |
|
83 if (!IsActive()) |
|
84 { |
|
85 iEComSession->NotifyOnChange(iStatus); |
|
86 SetActive(); |
|
87 } |
|
88 } |
|
89 |
|
90 |
|
91 void CEComPluginNotifier::RunL() |
|
92 { |
|
93 // TODO: Should the client be notified if there was an error? |
|
94 if (iStatus.Int() == KErrNone ) |
|
95 { |
|
96 if(iInterfaceId.iUid == 0) |
|
97 { |
|
98 RunCallBack(); |
|
99 } |
|
100 else |
|
101 { |
|
102 TRAP_IGNORE(CheckForEComPluginChangeL()) |
|
103 } |
|
104 // TODO: Should this be outside the if? What if there was a connection error? |
|
105 Start(); |
|
106 } |
|
107 } |
|
108 |
|
109 |
|
110 void CEComPluginNotifier::DoCancel() |
|
111 { |
|
112 iEComSession->CancelNotifyOnChange(iStatus); |
|
113 } |
|
114 |
|
115 |
|
116 void CEComPluginNotifier::CheckForEComPluginChangeL() |
|
117 { |
|
118 // TODO: Deal with errors here |
|
119 REComPluginInfoArray newPlugins; |
|
120 EComPluginUtils::GetInfoArrayL(iInterfaceId, newPlugins); |
|
121 |
|
122 TBool pluginsChanged = EFalse; |
|
123 |
|
124 TInt prevCount = iPreviousPlugins.Count(); |
|
125 TInt newCount = newPlugins.Count(); |
|
126 |
|
127 if(newCount != prevCount) |
|
128 { |
|
129 pluginsChanged = ETrue; |
|
130 } |
|
131 else |
|
132 { |
|
133 while(prevCount>0) |
|
134 { |
|
135 prevCount--; |
|
136 |
|
137 TUid prevUid = (iPreviousPlugins[prevCount]).iUid; |
|
138 TInt prevVer = (iPreviousPlugins[prevCount]).iVersion; |
|
139 TBool found = EFalse; |
|
140 |
|
141 newCount = newPlugins.Count(); |
|
142 while(newCount>0) |
|
143 { |
|
144 newCount--; |
|
145 TUid newUid = (newPlugins[newCount]).iUid; |
|
146 TInt newVer = (newPlugins[newCount]).iVersion; |
|
147 if(prevUid == newUid && prevVer == newVer) |
|
148 { |
|
149 found = ETrue; |
|
150 } |
|
151 } |
|
152 |
|
153 if(!found) |
|
154 { |
|
155 pluginsChanged = ETrue; |
|
156 break; |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 if(pluginsChanged) |
|
162 { |
|
163 RunCallBack(); |
|
164 } |
|
165 |
|
166 iPreviousPlugins.Reset(); |
|
167 iPreviousPlugins = newPlugins; |
|
168 } |
|
169 |
|
170 |
|
171 void CEComPluginNotifier::RunCallBack() |
|
172 { |
|
173 (iCallBack.iFunction)(iCallBack.iPtr); |
|
174 } |
|
175 |
|
176 |
|
177 |
|
178 // a kind of cleanup item for ecom info array |
|
179 NONSHARABLE_CLASS(CCleanupEComArray) : public CBase |
|
180 { |
|
181 public: |
|
182 ~CCleanupEComArray() |
|
183 { |
|
184 iArray.ResetAndDestroy(); |
|
185 iArray.Close(); |
|
186 } |
|
187 RImplInfoPtrArray iArray; |
|
188 }; |
|
189 |
|
190 /** |
|
191 * Reusable utility functions from here, exported as static functions |
|
192 * of CEComPluginUtils |
|
193 **/ |
|
194 EXPORT_C TInt EComPluginUtils::GetInfoArrayL(const TUid aInterfaceId, REComPluginInfoArray& aReturnArray) |
|
195 { |
|
196 CCleanupEComArray* plugins = new (ELeave) CCleanupEComArray; |
|
197 CleanupStack::PushL(plugins); |
|
198 REComSession::ListImplementationsL(aInterfaceId, plugins->iArray); |
|
199 CreateInfoArray(plugins->iArray, aReturnArray); |
|
200 CleanupStack::PopAndDestroy(plugins); |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 |
|
205 EXPORT_C TInt EComPluginUtils::CreateInfoArray(const RImplInfoPtrArray aEComArray, REComPluginInfoArray& aReturnArray) |
|
206 { |
|
207 for(TInt i=0; i<aEComArray.Count(); i++) |
|
208 { |
|
209 TUid uid = (aEComArray[i])->ImplementationUid(); |
|
210 TInt ver = (aEComArray[i])->Version(); |
|
211 TDriveUnit drive = (aEComArray[i])->Drive(); |
|
212 TEComPluginInfo info(uid, ver, drive); |
|
213 aReturnArray.Append(info); |
|
214 } |
|
215 return KErrNone; |
|
216 } |