|
1 /* |
|
2 * Copyright (c) 2004-2007 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: Notifier app server implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <AknNotifierWrapperDefs.h> |
|
19 #include "AknNotifierAppServer.h" |
|
20 #include "AknNotifierAppServerSession.h" |
|
21 #include "AknNotiferAppServerApplication.h" |
|
22 |
|
23 typedef CArrayPtr<MEikSrvNotifierBase2>* (*CreateEikSrvNotifierBase)(); |
|
24 |
|
25 class CNotifierNames: public CBase |
|
26 { |
|
27 public: |
|
28 ~CNotifierNames() |
|
29 { |
|
30 for (TInt i = 0; i < iNotifierNames.Count(); i++) |
|
31 { |
|
32 delete (iNotifierNames[i]); |
|
33 } |
|
34 |
|
35 iNotifierNames.Close(); |
|
36 } |
|
37 |
|
38 MNotifLibraryOwningServer* iFinder; |
|
39 RPointerArray<HBufC> iNotifierNames; |
|
40 }; |
|
41 |
|
42 |
|
43 EXPORT_C CAknNotifierAppServer::CAknNotifierAppServer() |
|
44 { |
|
45 } |
|
46 |
|
47 EXPORT_C CAknNotifierAppServer::~CAknNotifierAppServer() |
|
48 { |
|
49 TInt i; |
|
50 |
|
51 delete iNotifierNames; |
|
52 |
|
53 for (i = 0; i < iNotifierArray.Count(); i++) |
|
54 { |
|
55 iNotifierArray[i]->Release(); |
|
56 } |
|
57 |
|
58 iNotifierArray.Close(); |
|
59 |
|
60 for (i = 0; i < iLibraries.Count(); i++) |
|
61 { |
|
62 iLibraries[i].Close(); |
|
63 } |
|
64 |
|
65 iLibraries.Close(); |
|
66 } |
|
67 |
|
68 |
|
69 EXPORT_C void CAknNotifierAppServer::StartNotifierL(TUid aNotifierUid, const TDesC8& aBuffer, |
|
70 TDes8& aResponse) |
|
71 { |
|
72 MEikSrvNotifierBase2* impl = FindImplementation(aNotifierUid); |
|
73 User::LeaveIfNull(impl); |
|
74 aResponse.Copy(impl->StartL(aBuffer)); |
|
75 } |
|
76 |
|
77 |
|
78 EXPORT_C void CAknNotifierAppServer::CancelNotifier(TUid aNotifierUid) |
|
79 { |
|
80 MEikSrvNotifierBase2* impl = FindImplementation(aNotifierUid); |
|
81 if (impl) |
|
82 { |
|
83 impl->Cancel(); |
|
84 } |
|
85 } |
|
86 |
|
87 |
|
88 EXPORT_C void CAknNotifierAppServer::StartNotifierAndGetResponseL(TUid aNotifierUid, |
|
89 TDesC8& aBuffer, const RMessagePtr2& aMsg, TInt aReplySlot) |
|
90 { |
|
91 MEikSrvNotifierBase2* impl = FindImplementation(aNotifierUid); |
|
92 User::LeaveIfNull(impl); |
|
93 impl->StartL(aBuffer,aReplySlot,aMsg); |
|
94 } |
|
95 |
|
96 |
|
97 EXPORT_C void CAknNotifierAppServer::UpdateNotifierL(TUid aNotifierUid, const TDesC8& aBuffer, |
|
98 TDes8& aResponse) |
|
99 { |
|
100 MEikSrvNotifierBase2* impl = FindImplementation(aNotifierUid); |
|
101 User::LeaveIfNull(impl); |
|
102 aResponse.Copy(impl->UpdateL(aBuffer)); |
|
103 } |
|
104 |
|
105 EXPORT_C void CAknNotifierAppServer::UpdateNotifierAndGetResponseL(TUid aNotifierUid, |
|
106 TDesC8& aBuffer, const RMessagePtr2& aMsg, TInt aReplySlot) |
|
107 { |
|
108 MEikSrvNotifierBase2* impl = FindImplementation(aNotifierUid); |
|
109 User::LeaveIfNull(impl); |
|
110 impl->UpdateL( aBuffer, aReplySlot, aMsg ); |
|
111 } |
|
112 |
|
113 LOCAL_C void DeleteTempMArray(TAny* aPtr) |
|
114 { |
|
115 CArrayPtr<MEikSrvNotifierBase2>* const array = |
|
116 reinterpret_cast<CArrayPtr<MEikSrvNotifierBase2>*>(aPtr); |
|
117 |
|
118 for (TInt i = array->Count()-1; i >= 0 ; i--) |
|
119 { |
|
120 array->At(i)->Release(); // effectively delete |
|
121 } |
|
122 |
|
123 delete array; |
|
124 } |
|
125 |
|
126 |
|
127 EXPORT_C void CAknNotifierAppServer::LoadNotifiersL() |
|
128 { |
|
129 __ASSERT_DEBUG(iNotifierNames && iNotifierNames->iNotifierNames.Count(), User::Invariant()); |
|
130 |
|
131 TInt i, j; |
|
132 CArrayPtr<MEikSrvNotifierBase2>* notArray; |
|
133 |
|
134 const TUid KDllUid = {0x10000079}; |
|
135 |
|
136 for (i = 0; i < iNotifierNames->iNotifierNames.Count(); i++) |
|
137 { |
|
138 notArray = CreateImplementationsL( |
|
139 *(iNotifierNames->iNotifierNames[i]), |
|
140 TUidType(KDllUid, KUidNotifierPlugInV2, KNullUid)); |
|
141 |
|
142 User::LeaveIfNull(notArray); |
|
143 CleanupStack::PushL(TCleanupItem(DeleteTempMArray,notArray)); |
|
144 const TInt count = notArray->Count(); |
|
145 for (j = count-1; j >= 0 ; j--) |
|
146 { |
|
147 notArray->At(j)->RegisterL(); |
|
148 User::LeaveIfError(iNotifierArray.Append(notArray->At(j))); |
|
149 |
|
150 notArray->At(j)=0; |
|
151 notArray->Delete(j); |
|
152 } |
|
153 |
|
154 CleanupStack::PopAndDestroy(notArray); |
|
155 } |
|
156 } |
|
157 |
|
158 |
|
159 EXPORT_C void CAknNotifierAppServer::AppendNotifierLibNameL(const TDesC& aLibraryName) |
|
160 { |
|
161 if (!iNotifierNames) |
|
162 { |
|
163 iNotifierNames = new (ELeave) CNotifierNames; |
|
164 } |
|
165 |
|
166 HBufC* libName = aLibraryName.AllocLC(); |
|
167 User::LeaveIfError(iNotifierNames->iNotifierNames.Append(libName)); |
|
168 CleanupStack::Pop(); |
|
169 } |
|
170 |
|
171 |
|
172 MEikSrvNotifierBase2* CAknNotifierAppServer::FindImplementation(TUid aUid) const |
|
173 { |
|
174 if (iNotifierNames && iNotifierNames->iFinder) |
|
175 { |
|
176 return iNotifierNames->iFinder->FindImplementation(aUid); |
|
177 } |
|
178 for (TInt i = 0; i < iNotifierArray.Count(); i++) |
|
179 { |
|
180 if (iNotifierArray[i]->Info().iUid == aUid) |
|
181 { |
|
182 return iNotifierArray[i]; |
|
183 } |
|
184 } |
|
185 |
|
186 return NULL; |
|
187 } |
|
188 |
|
189 |
|
190 CArrayPtr<MEikSrvNotifierBase2>* CAknNotifierAppServer::CreateImplementationsL( |
|
191 const TDesC& aLibName, const TUidType& aUidType) |
|
192 { |
|
193 RLibrary lib; |
|
194 |
|
195 CleanupClosePushL(lib); |
|
196 User::LeaveIfError(lib.Load(aLibName,_L("z:\\sys\\bin\\"),aUidType)); |
|
197 CreateEikSrvNotifierBase libEntry =(CreateEikSrvNotifierBase)(lib.Lookup(1)); |
|
198 |
|
199 CArrayPtr<MEikSrvNotifierBase2>* array = |
|
200 reinterpret_cast<CArrayPtr<MEikSrvNotifierBase2>*>((libEntry)()); |
|
201 |
|
202 iLibraries.AppendL(lib); |
|
203 CleanupStack::Pop(); // lib |
|
204 |
|
205 return array; |
|
206 } |
|
207 |
|
208 |
|
209 EXPORT_C CApaAppServiceBase* CAknNotifierAppServer::CreateServiceL(TUid aServiceType) const |
|
210 { |
|
211 if (aServiceType == KAknNotifierServiceUid) |
|
212 { |
|
213 return new (ELeave) CAknNotifierServerAppService(*this); |
|
214 } |
|
215 else |
|
216 { |
|
217 return CAknAppServer::CreateServiceL(aServiceType); |
|
218 } |
|
219 } |
|
220 |
|
221 EXPORT_C void CAknNotifierAppServer::SetImplementationFinderL(MNotifLibraryOwningServer* aFinder) |
|
222 { |
|
223 if (!iNotifierNames) |
|
224 { |
|
225 iNotifierNames = new (ELeave) CNotifierNames; |
|
226 } |
|
227 iNotifierNames->iFinder = aFinder; |
|
228 } |
|
229 |
|
230 EXPORT_C void CAknNotifierAppServer::UnbalanceReferenceCountForNotif(TUid aUid, TBool aAddCount) |
|
231 { |
|
232 if(iNotifierNames && iNotifierNames->iFinder) |
|
233 { |
|
234 iNotifierNames->iFinder->UnbalanceReferenceCount(aUid, aAddCount); |
|
235 } |
|
236 } |
|
237 |
|
238 // End of file |