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 "activitystoragesynctask.h" |
|
18 #include "activitycmd.h" |
|
19 |
|
20 _LIT(KUnsupportedStorageSyncTask, "Unsupported sync storage task"); |
|
21 |
|
22 // ----------------------------------------------------------------------------- |
|
23 // |
|
24 // ----------------------------------------------------------------------------- |
|
25 // |
|
26 void ActivityStorageSyncTask::ExecuteL(MActivityTaskStorage& observers, |
|
27 CActivityStorage& dataStorage, |
|
28 const RMessage2& msg) |
|
29 { |
|
30 switch (msg.Function()) { |
|
31 case AddActivity: |
|
32 AddActivityL(dataStorage, msg); |
|
33 break; |
|
34 case UpdateActivity: |
|
35 UpdateActivityL(dataStorage, msg); |
|
36 break; |
|
37 case RemoveActivity: |
|
38 DeleteActivityL(dataStorage, msg); |
|
39 break; |
|
40 case RemoveApplicationActivities: |
|
41 DeleteApplicationActivitiesL(dataStorage, msg); |
|
42 break; |
|
43 default: |
|
44 //this code shouldn't be called. fatal error: means wrong session implementation |
|
45 User::Panic(KUnsupportedStorageSyncTask, KErrGeneral); |
|
46 }; |
|
47 msg.Complete(KErrNone); |
|
48 NotifyChangeL(observers, msg); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void ActivityStorageSyncTask::AddActivityL(CActivityStorage& dataStorage, const RMessage2& msg) |
|
56 { |
|
57 TPckgBuf<TInt> appId; |
|
58 msg.ReadL(KRequestAppIdOffset, appId); |
|
59 |
|
60 RBuf8 actId; |
|
61 CleanupClosePushL(actId); |
|
62 actId.CreateL(msg.GetDesLengthL(KRequestActOffset)); |
|
63 msg.ReadL(KRequestActOffset, actId, 0); |
|
64 |
|
65 RBuf8 data; |
|
66 CleanupClosePushL(data); |
|
67 data.CreateL(msg.GetDesLengthL(KRequestData)); |
|
68 msg.ReadL(KRequestData, data, 0); |
|
69 |
|
70 dataStorage.AddActivityL(appId(), actId, data); |
|
71 |
|
72 CleanupStack::PopAndDestroy(&data); |
|
73 CleanupStack::PopAndDestroy(&actId); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void ActivityStorageSyncTask::UpdateActivityL(CActivityStorage& dataStorage, const RMessage2& msg) |
|
81 { |
|
82 TPckgBuf<TInt> appId; |
|
83 msg.ReadL(KRequestAppIdOffset, appId); |
|
84 |
|
85 RBuf8 actId; |
|
86 CleanupClosePushL(actId); |
|
87 actId.CreateL(msg.GetDesLengthL(KRequestActOffset)); |
|
88 msg.ReadL(KRequestActOffset, actId, 0); |
|
89 |
|
90 RBuf8 data; |
|
91 CleanupClosePushL(data); |
|
92 data.CreateL(msg.GetDesLengthL(KRequestData)); |
|
93 msg.ReadL(KRequestData, data, 0); |
|
94 |
|
95 dataStorage.UpdateActivityL(appId(), actId, data); |
|
96 |
|
97 CleanupStack::PopAndDestroy(&data); |
|
98 CleanupStack::PopAndDestroy(&actId); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void ActivityStorageSyncTask::DeleteActivityL(CActivityStorage& dataStorage, const RMessage2& msg) |
|
106 { |
|
107 TPckgBuf<TInt> appId; |
|
108 msg.ReadL(KRequestAppIdOffset, appId); |
|
109 |
|
110 RBuf8 actId; |
|
111 CleanupClosePushL(actId); |
|
112 actId.CreateL(msg.GetDesLengthL(KRequestActOffset)); |
|
113 msg.ReadL(KRequestActOffset, actId, 0); |
|
114 |
|
115 dataStorage.DeleteActivityL(appId(), actId); |
|
116 |
|
117 CleanupStack::PopAndDestroy(&actId); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void ActivityStorageSyncTask::DeleteApplicationActivitiesL(CActivityStorage& dataStorage, const RMessage2& msg) |
|
125 { |
|
126 TPckgBuf<TInt> appId; |
|
127 msg.ReadL(KRequestAppIdOffset, appId); |
|
128 dataStorage.DeleteActivitiesL(appId()); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void ActivityStorageSyncTask::NotifyChangeL(MActivityTaskStorage& observers, |
|
136 const RMessage2& msg) |
|
137 { |
|
138 const RPointerArray<CActivityTask> &table(observers.StorageData()); |
|
139 for (TInt iter(table.Count() - 1); 0 <= iter; --iter) { |
|
140 table[iter]->BroadcastReceivedL(msg); |
|
141 } |
|
142 } |
|