|
1 /* |
|
2 * Copyright (c) 2008 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: CCFPublishContextCmd implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 |
|
21 // USER INCLUDES |
|
22 #include "cfpublishcontextcmd.h" |
|
23 #include "CFContextManager.h" |
|
24 #include "CFContextDataProxy.h" |
|
25 #include "cftrace.h" |
|
26 |
|
27 #include <cfcontextobject.h> |
|
28 #include <s32mem.h> |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // C++ constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CCFPublishContextCmd::CCFPublishContextCmd( CCFContextManager& aContextManager ) |
|
37 : iContextManager( aContextManager ) |
|
38 { |
|
39 FUNC_LOG; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Symbian 2nd phase constructor. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 void CCFPublishContextCmd::ConstructL( const CCFContextObject& aContext ) |
|
47 { |
|
48 FUNC_LOG; |
|
49 |
|
50 iContextObject = CCFContextObject::NewL(); |
|
51 iContextObject->CopyL( aContext ); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Symbian 2nd phase constructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CCFPublishContextCmd::ConstructL( const CCFContextObject& aContext, |
|
59 CCFContextDataObject& aData ) |
|
60 { |
|
61 FUNC_LOG; |
|
62 |
|
63 iContextObject = CCFContextObject::NewL(); |
|
64 iContextObject->CopyL( aContext ); |
|
65 |
|
66 HBufC8* data = HBufC8::NewLC( aData.Size() ); // CLEANUP<< data |
|
67 TPtr8 dataPtr( data->Des() ); |
|
68 RDesWriteStream writeStream( dataPtr ); |
|
69 CleanupClosePushL( writeStream ); // CLEANUP<< writeStream |
|
70 aData.ExternalizeL( writeStream ); |
|
71 CleanupStack::PopAndDestroy( &writeStream ); // CLEANUP>> writeStream |
|
72 iData = CCFContextDataProxy::NewL(); |
|
73 iData->SetContextData( data ); // Transfers ownership. |
|
74 CleanupStack::Pop( data ); // CLEANUP>> data |
|
75 iData->SetContextDataUid( aData.Uid() ); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Symbian two phased constructor. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CCFPublishContextCmd* CCFPublishContextCmd::NewL( |
|
83 CCFContextManager& aContextManager, |
|
84 const CCFContextObject& aContext ) |
|
85 { |
|
86 FUNC_LOG; |
|
87 |
|
88 CCFPublishContextCmd* self |
|
89 = CCFPublishContextCmd::NewLC( aContextManager, aContext ); |
|
90 CleanupStack::Pop ( self ); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Symbian two phased constructor. |
|
96 // Leaves pointer in the cleanup stack. |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CCFPublishContextCmd* CCFPublishContextCmd::NewLC( |
|
100 CCFContextManager& aContextManager, |
|
101 const CCFContextObject& aContext ) |
|
102 { |
|
103 FUNC_LOG; |
|
104 |
|
105 CCFPublishContextCmd* self |
|
106 = new( ELeave ) CCFPublishContextCmd( aContextManager ); |
|
107 CleanupStack::PushL ( self ); |
|
108 self->ConstructL( aContext ); |
|
109 return self; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Symbian two phased constructor. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 CCFPublishContextCmd* CCFPublishContextCmd::NewL( |
|
117 CCFContextManager& aContextManager, |
|
118 const CCFContextObject& aContext, |
|
119 CCFContextDataObject& aData ) |
|
120 { |
|
121 FUNC_LOG; |
|
122 |
|
123 CCFPublishContextCmd* self |
|
124 = CCFPublishContextCmd::NewLC( aContextManager, aContext, aData ); |
|
125 CleanupStack::Pop ( self ); |
|
126 return self; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Symbian two phased constructor. |
|
131 // Leaves pointer in the cleanup stack. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CCFPublishContextCmd* CCFPublishContextCmd::NewLC( |
|
135 CCFContextManager& aContextManager, |
|
136 const CCFContextObject& aContext, |
|
137 CCFContextDataObject& aData ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 |
|
141 CCFPublishContextCmd* self |
|
142 = new( ELeave ) CCFPublishContextCmd( aContextManager ); |
|
143 CleanupStack::PushL ( self ); |
|
144 self->ConstructL( aContext, aData ); |
|
145 return self; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // C++ destructor. |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 CCFPublishContextCmd::~CCFPublishContextCmd( ) |
|
153 { |
|
154 FUNC_LOG; |
|
155 |
|
156 delete iContextObject; |
|
157 delete iData; |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CCFPublishContextCmd::ExecuteL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CCFPublishContextCmd::ExecuteL() |
|
166 { |
|
167 FUNC_LOG; |
|
168 |
|
169 INFO_3( "CCFPublishContextCmd::Execute - Publishing context: [%S: %S: %S]", |
|
170 &iContextObject->Source(), |
|
171 &iContextObject->Type(), |
|
172 &iContextObject->Value() ); |
|
173 if ( iData ) |
|
174 { |
|
175 INFO_1( "CCFPublishContextCmd::Execute - Publishing context data object: [0x%x]", |
|
176 static_cast< CCFContextDataObject* >( iData )->Uid() ); |
|
177 } |
|
178 |
|
179 iContextManager.DoPublishContextL( *iContextObject, iData ); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CCFPublishContextCmd::LogError |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CCFPublishContextCmd::LogError( TInt aError ) |
|
187 { |
|
188 FUNC_LOG; |
|
189 |
|
190 if( aError != KErrNone ) |
|
191 { |
|
192 ERROR_3( aError, "CCFPublishContextCmd::LogError - Failed to publish context [%S: %S: %S] as command.", |
|
193 &iContextObject->Source(), |
|
194 &iContextObject->Type(), |
|
195 &iContextObject->Value() ); |
|
196 if ( iData ) |
|
197 { |
|
198 ERROR_1( aError, "CCFPublishContextCmd::LogError - Failed to publish with context data object: [0x%x]", |
|
199 static_cast< CCFContextDataObject* >( iData )->Uid() ); |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 // End of file |