|
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 "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 #include <s32mem.h> |
|
18 |
|
19 #include "afstorageasynctask.h" |
|
20 #include "afcmd.h" |
|
21 |
|
22 _LIT(KUnsupportedStorageAsyncTask, "Unsupported async storage task"); |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 /** |
|
26 * Constructor for performing 1st stage construction |
|
27 */ |
|
28 CAfStorageAsyncTask::CAfStorageAsyncTask() |
|
29 { |
|
30 // No implementation required |
|
31 } |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 /** |
|
35 * Destructor. |
|
36 */ |
|
37 CAfStorageAsyncTask::~CAfStorageAsyncTask() |
|
38 { |
|
39 mExternalizedData.Close(); |
|
40 mInternalizedData.ResetAndDestroy(); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 /** |
|
45 * Handle asynchronous data storage requests |
|
46 * @param taskStorage - data tasks storage |
|
47 * @param dataStorage - data storage |
|
48 * @param msg - request message |
|
49 */ |
|
50 void CAfStorageAsyncTask::ExecuteLD(MAfTaskStorage& taskStorage, |
|
51 CAfStorage& dataStorage, |
|
52 const RMessage2& msg) |
|
53 { |
|
54 CAfStorageAsyncTask* self = new (ELeave) CAfStorageAsyncTask(); |
|
55 CleanupStack::PushL(self); |
|
56 self->ExecuteL(dataStorage, msg); |
|
57 taskStorage.PushL(self); |
|
58 CleanupStack::Pop(self); |
|
59 if (EFalse == msg.IsNull()) { |
|
60 msg.Complete(KErrNone); |
|
61 } |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 /** |
|
66 * Interface implementation |
|
67 * @see CActivityTask::Data() |
|
68 */ |
|
69 const TDesC8& CAfStorageAsyncTask::CAfStorageAsyncTask::Data() const |
|
70 { |
|
71 return mExternalizedData; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 /** |
|
76 * Interface implementation |
|
77 * @see CActivityTask::BroadcastReceivedL(const RMessage2 &) |
|
78 */ |
|
79 void CAfStorageAsyncTask::BroadcastReceivedL(const RMessage2& ) |
|
80 { |
|
81 // No implementation required |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 /** |
|
86 * Handle asynchronous data storage requests |
|
87 * @param dataStorage - data storage |
|
88 * @param msg - request message |
|
89 */ |
|
90 void CAfStorageAsyncTask::ExecuteL(CAfStorage& dataStorage, |
|
91 const RMessage2& msg) |
|
92 { |
|
93 switch (msg.Function()) { |
|
94 case Activities: |
|
95 AllActivitiesL(dataStorage, msg); |
|
96 break; |
|
97 case ApplicationActivities: |
|
98 ApplicationActivitiesL(dataStorage, msg); |
|
99 break; |
|
100 case ApplicationActivity: |
|
101 ApplicationActivityL(dataStorage, msg); |
|
102 break; |
|
103 default: |
|
104 //this code shouldn't be called. fatal error: means wrong session implementation |
|
105 User::Panic(KUnsupportedStorageAsyncTask, KErrGeneral); |
|
106 }; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 /** |
|
111 * Handle getting all activities request |
|
112 * @param dataStorage - data storage |
|
113 * @param msg - requested message |
|
114 */ |
|
115 void CAfStorageAsyncTask::AllActivitiesL(CAfStorage& dataStorage, |
|
116 const RMessage2& msg) |
|
117 { |
|
118 dataStorage.ActivitiesL(mInternalizedData); |
|
119 ExternalizeL(); |
|
120 WriteResponseL(msg); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 /** |
|
125 * Handle getting application activities request |
|
126 * @param dataStorage - data storage |
|
127 * @param msg - requested message |
|
128 */ |
|
129 void CAfStorageAsyncTask::ApplicationActivitiesL(CAfStorage& dataStorage, |
|
130 const RMessage2& msg) |
|
131 { |
|
132 CAfEntry *entry = CAfEntry::NewLC(msg); |
|
133 dataStorage.ActivitiesL(mInternalizedData, entry->ApplicationId()); |
|
134 CleanupStack::PopAndDestroy(entry); |
|
135 ExternalizeL(); |
|
136 WriteResponseL(msg); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 /** |
|
141 * Handle getting application activity request |
|
142 * @param dataStorage - data storage |
|
143 * @param msg - requested message |
|
144 */ |
|
145 void CAfStorageAsyncTask::ApplicationActivityL(CAfStorage& dataStorage, |
|
146 const RMessage2& msg) |
|
147 { |
|
148 CAfEntry *src(CAfEntry::NewLC(msg)); |
|
149 dataStorage.ActivityL(mInternalizedData, *src); |
|
150 CleanupStack::PopAndDestroy(src); |
|
151 ExternalizeL(); |
|
152 WriteResponseL(msg); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 void CAfStorageAsyncTask::ExternalizeL() |
|
157 { |
|
158 mExternalizedData << mInternalizedData; |
|
159 mInternalizedData.ResetAndDestroy(); |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 /** |
|
164 * Write response data into request message |
|
165 * @param msg - destination message |
|
166 */ |
|
167 void CAfStorageAsyncTask::WriteResponseL(const RMessage2& msg) |
|
168 { |
|
169 if (EFalse == msg.IsNull()) { |
|
170 msg.WriteL(1, |
|
171 TPckgBuf<TInt>(mExternalizedData.Length()));//write data size |
|
172 msg.WriteL(2, |
|
173 TPckgBuf<CBase*>(this));//task identyfier |
|
174 } |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 /** |
|
179 * Returns ETrue if task is related with session argument |
|
180 */ |
|
181 |
|
182 TBool CAfStorageAsyncTask::IsSessionTask(const CSession2* /*session*/) |
|
183 { |
|
184 return EFalse; |
|
185 } |