1 /* |
|
2 * Copyright (c) 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: This class handles dynamic search label-key pair storing. |
|
15 * |
|
16 */ |
|
17 |
|
18 //For malloc |
|
19 #include <stdlib.h> |
|
20 //For protocol connection host |
|
21 #include <ximpprotocolconnectionhost.h> |
|
22 //For Connection manager |
|
23 #include "cossprotocolconnectionmanager.h" |
|
24 #include "csearchgetsearchkeys.h" |
|
25 #include "msg_enums.h" |
|
26 |
|
27 #include "ossprotocolpluginlogger.h" |
|
28 //For Converting C style string to S60 style HBufC |
|
29 #include "ossprotocoladaptutils.h" |
|
30 //For open c string functions |
|
31 #include <string.h> |
|
32 |
|
33 #include <searchkeyinfo.h> |
|
34 |
|
35 #include <searchobjectfactory.h> |
|
36 #include <ximpobjectcollection.h> |
|
37 #include <protocolsearchdatahost.h> |
|
38 #include <protocolsearchfeaturedatahost.h> |
|
39 #include <ximpobjectfactory.h> |
|
40 |
|
41 /*! /brief Documented in header file |
|
42 */ |
|
43 CSearchGetSearchKeys* CSearchGetSearchKeys::NewL( |
|
44 MOSSProtocolConnectionManager& aConnMan, |
|
45 TXIMPRequestId aRequestId ) |
|
46 { |
|
47 LOGGER ( TXT("::CSearchGetSearchKeys NewL Start") ); |
|
48 |
|
49 CSearchGetSearchKeys* self = new ( ELeave ) CSearchGetSearchKeys( |
|
50 aConnMan, aRequestId ); |
|
51 |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop( self ); |
|
55 |
|
56 LOGGER ( TXT("::CSearchGetSearchKeys NewL End") ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 /*! /brief Documented in header file |
|
62 */ |
|
63 CSearchGetSearchKeys::CSearchGetSearchKeys( |
|
64 MOSSProtocolConnectionManager& aConnMan, |
|
65 TXIMPRequestId aRequestId ) : CActive ( EPriorityNormal ), |
|
66 iRequestId ( aRequestId ), |
|
67 iConnMan ( aConnMan ) |
|
68 { |
|
69 |
|
70 LOGGER ( TXT("::CSearchGetSearchKeys Start") ); |
|
71 |
|
72 CActiveScheduler::Add( this ); |
|
73 |
|
74 LOGGER ( TXT("::CSearchGetSearchKeys End") ); |
|
75 |
|
76 } |
|
77 |
|
78 /*! /brief Documented in header file |
|
79 */ |
|
80 CSearchGetSearchKeys::~CSearchGetSearchKeys() |
|
81 { |
|
82 |
|
83 } |
|
84 |
|
85 /*! /brief Documented in header file |
|
86 */ |
|
87 void CSearchGetSearchKeys::DoCancel() |
|
88 { |
|
89 |
|
90 } |
|
91 |
|
92 /*! /brief Documented in header file |
|
93 */ |
|
94 void CSearchGetSearchKeys::RunL() |
|
95 { |
|
96 LOGGER( TXT( "CSearchGetSearchKeys::RunL start" ) ); |
|
97 |
|
98 User::LeaveIfError( iStatus.Int() ); |
|
99 message_hdr_resp* msg_resp = NULL; |
|
100 |
|
101 char* response = NULL; |
|
102 CSearchKeyStore& keyStore = iConnMan.GetSearchKeyStore(); |
|
103 |
|
104 response = iConnMan.DataHandler().ResponseL( iSendId ); |
|
105 |
|
106 msg_resp = ( message_hdr_resp* ) response; |
|
107 |
|
108 if ( !msg_resp->response ) |
|
109 { |
|
110 if ( msg_resp->error_type ) |
|
111 { |
|
112 //Complete the request with an error |
|
113 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, |
|
114 KErrNotSupported ); |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 |
|
120 { |
|
121 //This part reads all the possible labels from cen rep and tries to |
|
122 //match the search labels got to those.. If match found search labels |
|
123 //are assigned appropriate Enum values |
|
124 TInt index = sizeof( message_hdr_resp ); |
|
125 char* keyStr = NULL; |
|
126 RPointerArray<TDesC> keyList; |
|
127 TInt len = 0; |
|
128 |
|
129 while( !( *( response + index ) == '\0' |
|
130 && *( response + index + 1 ) == '\0' ) ) |
|
131 { |
|
132 len = strlen( response + index ) + 1; |
|
133 keyStr = ( char* ) User::AllocLC( len ); |
|
134 strcpy ( keyStr, response + index ); |
|
135 index += len; |
|
136 |
|
137 HBufC* key = OssProtocolAdapUtils::ConvertCharToTUint16LC( keyStr ); |
|
138 keyList.Append( key ); |
|
139 CleanupStack::Pop(); //key |
|
140 CleanupStack::PopAndDestroy(); //keyStr |
|
141 } |
|
142 |
|
143 keyStore.MapLabelsToEnumL( keyList ); |
|
144 } |
|
145 //Send all the labels to XIMP/UI |
|
146 MXIMPObjectFactory& objFact = iConnMan.HandleToHost().ObjectFactory(); |
|
147 MSearchObjectFactory& searchObjFact = iConnMan.GetSearchHost().SearchObjectFactory(); |
|
148 MXIMPObjectCollection* labelArray = objFact.NewObjectCollectionLC(); |
|
149 |
|
150 RPointerArray<TSearchKey> lablEnum = keyStore.GetSupportedEnums(); |
|
151 |
|
152 for ( TInt i = 0; i < lablEnum.Count(); i++ ) |
|
153 { |
|
154 MSearchKeyInfo* srchKey = searchObjFact.NewSearchKeyInfoLC(); |
|
155 srchKey->SetType( EKey ); |
|
156 srchKey->SetKey((TSearchKey) *( lablEnum[i] ) ); |
|
157 labelArray->AddObjectL( srchKey );//ownership transfered |
|
158 CleanupStack::Pop(); //srchKey |
|
159 } |
|
160 |
|
161 RPointerArray<TDesC> label = keyStore.GetNotSupportedLabels(); |
|
162 |
|
163 for ( TInt i = 0; i < label.Count(); i++ ) |
|
164 { |
|
165 MSearchKeyInfo* srchLabel = searchObjFact.NewSearchKeyInfoLC(); |
|
166 srchLabel->SetType( ELabel ); |
|
167 srchLabel->SetLabelL( *( label[i] ) ); |
|
168 labelArray->AddObjectL( srchLabel );//ownership transfered |
|
169 CleanupStack::Pop(); //srchLabel |
|
170 } |
|
171 |
|
172 |
|
173 iConnMan.GetSearchHost().SearchFeatureDataAccess().HandleSearchKeysL ( |
|
174 labelArray );//ownership transfered |
|
175 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrNone ); |
|
176 |
|
177 CleanupStack::Pop( ); //labelArray |
|
178 } |
|
179 |
|
180 free( response ); |
|
181 |
|
182 LOGGER( TXT( "CSearchGetSearchKeys::RunL end" ) ); |
|
183 delete this; |
|
184 |
|
185 } |
|
186 |
|
187 /*! /brief Documented in header file |
|
188 */ |
|
189 TInt CSearchGetSearchKeys::RunError( TInt aError ) |
|
190 { |
|
191 LOGGER( TXT( "CSearchGetSearchKeys::RunError start" ) ); |
|
192 |
|
193 iConnMan.HandleToHost().HandleRequestCompleted( iRequestId, aError ); |
|
194 |
|
195 LOGGER( TXT( "CSearchGetSearchKeys::RunError end" ) ); |
|
196 |
|
197 return 0; |
|
198 } |
|
199 |
|
200 /*! /brief Documented in header file |
|
201 */ |
|
202 void CSearchGetSearchKeys::ConstructL() |
|
203 { |
|
204 |
|
205 } |
|
206 |
|
207 /*! /brief Documented in header file |
|
208 */ |
|
209 void CSearchGetSearchKeys::GetSearchKeysL() |
|
210 { |
|
211 LOGGER ( TXT("::CSearchGetSearchKeys GetSearchKeysL Start") ); |
|
212 |
|
213 TInt len = sizeof ( message_hdr_req ); |
|
214 message_hdr_req* msgHdr = ( message_hdr_req* ) User::AllocLC( len ); |
|
215 |
|
216 msgHdr->message_type = ESearch_Get_Keys; |
|
217 |
|
218 iSendId = iConnMan.DataHandler().SendDataL( iStatus, ( char* )msgHdr, |
|
219 len ); |
|
220 |
|
221 SetActive(); |
|
222 |
|
223 CleanupStack::PopAndDestroy ( 1 );//msgHdr |
|
224 |
|
225 LOGGER ( TXT("::CSearchGetSearchKeys GetSearchKeysL End") ); |
|
226 } |
|
227 |
|
228 // End of file |
|