|
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 the License "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 #include "messaginginterface.h" |
|
20 #include<LiwCommon.h> |
|
21 #include<LiwVariant.h> |
|
22 #include<LiwServiceHandler.h> |
|
23 |
|
24 #include"notify.h" |
|
25 |
|
26 _LIT8(KTestInterface, "IMessaging"); |
|
27 _LIT8(KTestContent, "Service.Messaging"); |
|
28 _LIT8(KCmd, "RegisterNotification"); |
|
29 _LIT8(KCmdCancel, "CancelNotification"); |
|
30 _LIT8(KMessageId, "MessageId"); |
|
31 _LIT8(KMap, "Type"); |
|
32 _LIT8(KMessageList, "MessageList" ); |
|
33 _LIT8(KMessage, "Message" ); |
|
34 |
|
35 _LIT(KMsgType,"NewMessage"); |
|
36 |
|
37 |
|
38 |
|
39 CMsgCallback* CMsgCallback::NewL(CActiveSchedulerWait* aWaitSchedular, MLiwInterface* aInterface) |
|
40 { |
|
41 return new (ELeave) CMsgCallback(aWaitSchedular, aInterface); |
|
42 } |
|
43 |
|
44 TInt CMsgCallback::HandleNotifyL(TInt aCmdId, |
|
45 TInt aEventId, |
|
46 CLiwGenericParamList& aEventParamList, |
|
47 const CLiwGenericParamList& aInParamList) |
|
48 { |
|
49 TInt pos = 0; |
|
50 TInt result = KErrNone; |
|
51 const TLiwGenericParam* output = aEventParamList.FindFirst( pos,_L8("ReturnValue")); |
|
52 |
|
53 const CLiwMap* header = output->Value().AsMap(); |
|
54 TInt32 newmessageid = -1; |
|
55 if ( header ) |
|
56 { |
|
57 TLiwVariant mesageid; |
|
58 if( header->FindL(KMessageId, mesageid)) |
|
59 { |
|
60 newmessageid = mesageid.AsTInt32(); |
|
61 } |
|
62 mesageid.Reset(); |
|
63 } |
|
64 |
|
65 if ( newmessageid ) |
|
66 { |
|
67 |
|
68 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
69 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL(); |
|
70 |
|
71 TLiwVariant content(_L8("Inbox")); |
|
72 TLiwGenericParam elem ; |
|
73 elem.SetNameAndValueL(_L8("Type"),content); |
|
74 inParamList->AppendL(elem); |
|
75 content.Reset(); |
|
76 elem.Reset(); |
|
77 |
|
78 CLiwDefaultMap* filtermap = CLiwDefaultMap::NewL(); |
|
79 CleanupStack::PushL(filtermap); |
|
80 |
|
81 TLiwVariant filterid( newmessageid ); |
|
82 filtermap->InsertL(KMessageId, filterid); // Mtmtype is added |
|
83 filterid.Reset(); |
|
84 |
|
85 |
|
86 TLiwVariant filterparam(filtermap); |
|
87 TLiwGenericParam element ; |
|
88 element.SetNameAndValueL(_L8("Filter"),filterparam); |
|
89 filterparam.Reset(); |
|
90 |
|
91 inParamList->AppendL(element); |
|
92 element.Reset(); |
|
93 |
|
94 filtermap->DecRef(); |
|
95 CleanupStack::Pop(filtermap); |
|
96 |
|
97 |
|
98 TInt err = 0; |
|
99 TRAP(err,iInterface->ExecuteCmdL( _L8("GetList") ,*inParamList ,*outParamList)); |
|
100 |
|
101 pos = 0 ; |
|
102 |
|
103 const TLiwGenericParam* finaloutput = outParamList->FindFirst( pos,_L8("ReturnValue")); |
|
104 |
|
105 if ( finaloutput ) |
|
106 { |
|
107 CLiwIterable* iterlist = finaloutput->Value().AsIterable(); |
|
108 |
|
109 if(iterlist) |
|
110 { |
|
111 TLiwVariant data; |
|
112 |
|
113 if ( iterlist->NextL(data) ) |
|
114 result = KErrNone; |
|
115 |
|
116 data.Reset(); |
|
117 |
|
118 } |
|
119 } |
|
120 |
|
121 inParamList->Reset(); |
|
122 outParamList->Reset(); |
|
123 |
|
124 delete inParamList; |
|
125 delete outParamList; |
|
126 |
|
127 } |
|
128 |
|
129 if ( iWaitSchedular && iWaitSchedular->IsStarted()) |
|
130 { |
|
131 iWaitSchedular->AsyncStop(); |
|
132 } |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 CTestAsync* CTestAsync::NewL() |
|
138 { |
|
139 CTestAsync* self = new (ELeave) CTestAsync(); |
|
140 self->ConstructL(); |
|
141 return self; |
|
142 } |
|
143 |
|
144 CTestAsync::~CTestAsync() |
|
145 { |
|
146 Cancel(); |
|
147 |
|
148 interface->Close(); |
|
149 |
|
150 delete iServiceHandler; |
|
151 |
|
152 delete iCallback; |
|
153 |
|
154 if(iWaitSchedular->IsStarted()) |
|
155 iWaitSchedular->AsyncStop(); |
|
156 |
|
157 delete iWaitSchedular; |
|
158 } |
|
159 |
|
160 |
|
161 void CTestAsync::ConstructL() |
|
162 { |
|
163 CActiveScheduler::Add(this); |
|
164 iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
165 } |
|
166 |
|
167 |
|
168 CTestAsync::CTestAsync() : |
|
169 CActive(EPriorityStandard) |
|
170 { |
|
171 interface = NULL ; |
|
172 } |
|
173 |
|
174 void CTestAsync::DoCancel() |
|
175 { |
|
176 |
|
177 } |
|
178 |
|
179 void CTestAsync::RunL() |
|
180 { |
|
181 TestFunc(); |
|
182 } |
|
183 |
|
184 |
|
185 void CTestAsync::Start() |
|
186 { |
|
187 SetActive(); |
|
188 TRequestStatus* temp = &iStatus; |
|
189 User::RequestComplete(temp, KErrNone); |
|
190 iWaitSchedular->Start(); |
|
191 } |
|
192 |
|
193 |
|
194 void CTestAsync::TestFunc() |
|
195 { |
|
196 iServiceHandler = CLiwServiceHandler::NewL(); |
|
197 |
|
198 CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
199 CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
200 |
|
201 |
|
202 TInt err; |
|
203 |
|
204 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KTestInterface,KTestContent); |
|
205 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
206 |
|
207 RCriteriaArray a; |
|
208 a.AppendL(crit); |
|
209 |
|
210 iServiceHandler->AttachL(a); |
|
211 iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
212 |
|
213 a.Reset(); |
|
214 delete crit; |
|
215 |
|
216 TInt pos = 0; |
|
217 |
|
218 outparam->FindFirst( pos, KTestInterface ); |
|
219 if(pos != KErrNotFound) |
|
220 { |
|
221 interface = (*outparam)[pos].Value().AsInterface(); |
|
222 } |
|
223 |
|
224 outparam->Reset(); |
|
225 inparam->Reset(); |
|
226 |
|
227 TLiwGenericParam element ; |
|
228 element.SetNameAndValueL(KMap, TLiwVariant(KMsgType)); |
|
229 inparam->AppendL(element); |
|
230 element.Reset(); |
|
231 |
|
232 iCallback = CMsgCallback::NewL(iWaitSchedular, interface); |
|
233 |
|
234 TRAPD(err1 ,interface->ExecuteCmdL(KCmd, *inparam, *outparam, KLiwOptASyncronous, iCallback)); |
|
235 inparam->Reset(); |
|
236 outparam->Reset(); |
|
237 } |
|
238 |
|
239 |
|
240 int ReqNotification(int, char**) |
|
241 { |
|
242 __UHEAP_MARK; |
|
243 CTestAsync* test = CTestAsync::NewL(); |
|
244 test->Start(); |
|
245 delete test; |
|
246 __UHEAP_MARKEND; |
|
247 return 0; |
|
248 |
|
249 } |