|
1 /* |
|
2 * Copyright (c) 2002 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: CLandmarkObserver class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <liwgenericparam.h> |
|
21 #include <liwcommon.h> |
|
22 #include "clandmarkobserver.h" |
|
23 #include "clandmarkiterable.h" |
|
24 #include "clandmarkcategoryiterable.h" |
|
25 #include "landmarkinterface.h" |
|
26 #include "landmarkliwparams.hrh" |
|
27 #include "../../inc/serviceerrno.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CLandmarkObserver::NewL( CLandmarkInterface* aLmIface ) |
|
33 // Two-phased constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CLandmarkObserver* CLandmarkObserver::NewL( CLandmarkInterface* aLmIface ) |
|
37 { |
|
38 CLandmarkObserver* self = new (ELeave) CLandmarkObserver(aLmIface); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CLandmarkObserver::CLandmarkObserver( CLandmarkInterface* aLmIface ) |
|
44 // C++ default constructor can NOT contain any code, that might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CLandmarkObserver::CLandmarkObserver( CLandmarkInterface* aLmIface ) |
|
48 : iLmIface(aLmIface) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CLandmarkObserver::HandleCategoryItems( CPosLmItemIterator* aIterator, |
|
54 // TInt32 aTransactionId, TInt aError, const TDesC aDatabaseUri ) |
|
55 // Pack the outputs and call the callback function. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CLandmarkObserver::HandleLandmarkItemsL( CPosLmItemIterator* aIterator, |
|
59 TInt32 aTransactionId, TInt aError, const TDesC& aDatabaseUri ) |
|
60 { |
|
61 TInt SapiErr = SErrNone; |
|
62 //retrieve callback |
|
63 MLiwNotifyCallback* callback = iLmIface->Callback(aTransactionId); |
|
64 if( !callback ) |
|
65 { |
|
66 //how to flag error |
|
67 return; |
|
68 } |
|
69 //Create param list |
|
70 CLiwGenericParamList* eventParamList = CLiwGenericParamList::NewL(); |
|
71 CleanupStack::PushL(eventParamList); |
|
72 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
73 CleanupStack::PushL(inParamList); |
|
74 |
|
75 if ( aError != KErrNone ) |
|
76 { |
|
77 SapiErr = iLmIface->SapiError(aError); |
|
78 eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr))); |
|
79 callback->HandleNotifyL(aTransactionId,KLiwEventError,*eventParamList,*inParamList); |
|
80 } |
|
81 else |
|
82 { |
|
83 //instantiate CLandmarkIterable |
|
84 CLiwIterable* iterable = CLandmarkIterable::NewL(aIterator,aDatabaseUri); |
|
85 CleanupClosePushL(*iterable); |
|
86 //pack to aOutParamList |
|
87 eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr))); |
|
88 eventParamList->AppendL(TLiwGenericParam(KReturnValue,TLiwVariant(iterable))); |
|
89 callback->HandleNotifyL(aTransactionId,KLiwEventCompleted,*eventParamList,*inParamList); |
|
90 CleanupStack::PopAndDestroy(iterable); |
|
91 } |
|
92 CleanupStack::PopAndDestroy(inParamList); |
|
93 CleanupStack::PopAndDestroy(eventParamList); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CLandmarkObserver::HandleCategoryItems( CPosLmItemIterator* aIterator, |
|
98 // TInt32 aTransactionId, TInt aError, const TDesC aDatabaseUri ) |
|
99 // Pack the outputs and call the callback function. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CLandmarkObserver::HandleCategoryItemsL( CPosLmItemIterator* aIterator, |
|
103 TInt32 aTransactionId, TInt aError, const TDesC& aDatabaseUri ) |
|
104 { |
|
105 TInt SapiErr = SErrNone; |
|
106 //retrieve callback |
|
107 MLiwNotifyCallback* callback = iLmIface->Callback(aTransactionId); |
|
108 if( !callback ) |
|
109 { |
|
110 //how to flag error |
|
111 return; |
|
112 } |
|
113 //Create param list |
|
114 CLiwGenericParamList* eventParamList = CLiwGenericParamList::NewL(); |
|
115 CleanupStack::PushL(eventParamList); |
|
116 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
117 CleanupStack::PushL(inParamList); |
|
118 |
|
119 if ( aError != KErrNone ) |
|
120 { |
|
121 SapiErr = iLmIface->SapiError(aError); |
|
122 eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr))); |
|
123 callback->HandleNotifyL(aTransactionId,KLiwEventError,*eventParamList,*inParamList); |
|
124 } |
|
125 else |
|
126 { |
|
127 //instantiate CLandmarkIterable |
|
128 CLiwIterable* iterable = CLandmarkCategoryIterable::NewL(aIterator,aDatabaseUri); |
|
129 CleanupClosePushL(*iterable); |
|
130 //pack to aOutParamList |
|
131 eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr))); |
|
132 eventParamList->AppendL(TLiwGenericParam(KReturnValue,TLiwVariant(iterable))); |
|
133 callback->HandleNotifyL(aTransactionId,KLiwEventCompleted,*eventParamList,*inParamList); |
|
134 CleanupStack::PopAndDestroy(iterable); |
|
135 } |
|
136 CleanupStack::PopAndDestroy(inParamList); |
|
137 CleanupStack::PopAndDestroy(eventParamList); |
|
138 } |
|
139 |
|
140 //End of file |