|
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 "afsession.h" |
|
18 #include "aftask.h" |
|
19 #include "activitycmd.h" |
|
20 |
|
21 #include "afstorageasynctask.h" |
|
22 #include "afstoragesynctask.h" |
|
23 #include "afobservertask.h" |
|
24 #include "afbroadcasttask.h" |
|
25 #include "afdataprovidertask.h" |
|
26 #include "afthumbnailtask.h" |
|
27 |
|
28 _LIT(KTaskAlreadyExists, "Activity task exists"); |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 /** |
|
32 * Constructor for performing 1st stage construction |
|
33 * @param fileSession - initialized file system session |
|
34 * @param taskStorage - global observers storage |
|
35 * @param storage - data storage |
|
36 */ |
|
37 |
|
38 CAfSession::CAfSession(RFs& fileSession, |
|
39 MAfTaskStorage& taskStorage, |
|
40 CAfStorage& storage) |
|
41 : |
|
42 mFileSession(fileSession), |
|
43 mTasksStorage(taskStorage), |
|
44 mStorage(storage) |
|
45 { |
|
46 // No implementation required |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 /** |
|
51 * Destructor. |
|
52 */ |
|
53 CAfSession::~CAfSession() |
|
54 { |
|
55 RemoveNotValidTasks(this); |
|
56 mTasksStorage.RemoveNotValidTasks(this); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 /** |
|
61 * Two-phased constructor. |
|
62 * @param fileSession - initialized file system session |
|
63 * @param taskStorage - global observers storage |
|
64 * @param storage - data storage |
|
65 */ |
|
66 CAfSession* CAfSession::NewL(RFs& fileSession, |
|
67 MAfTaskStorage& taskStorage, |
|
68 CAfStorage& storage) |
|
69 { |
|
70 CAfSession* self = new (ELeave) CAfSession(fileSession, |
|
71 taskStorage, |
|
72 storage); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(self); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 /** |
|
81 * EPOC default constructor for performing 2nd stage construction |
|
82 */ |
|
83 void CAfSession::ConstructL() |
|
84 { |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 /** |
|
89 * Implements interface |
|
90 * @see void CSession2::ServiceL(const RMessage2&) |
|
91 */ |
|
92 void CAfSession::ServiceL(const RMessage2& message) |
|
93 { |
|
94 switch (message.Function()) { |
|
95 case AddActivity: |
|
96 case UpdateActivity: |
|
97 case RemoveActivity: |
|
98 case RemoveApplicationActivities: |
|
99 AfStorageSyncTask::ExecuteL(mTasksStorage, mStorage, message); |
|
100 break; |
|
101 |
|
102 case ApplicationActivity: |
|
103 case Activities: |
|
104 case ApplicationActivities: |
|
105 CAfStorageAsyncTask::ExecuteLD(*this, mStorage, message); |
|
106 break; |
|
107 |
|
108 case WaitActivity: |
|
109 case NotifyChange: |
|
110 CAfObserverTask::ExecuteLD(mTasksStorage, *this, message); |
|
111 break; |
|
112 |
|
113 case GetThumbnail: |
|
114 CAfThumbnailTask::ExecuteLD(*this, message); |
|
115 break; |
|
116 |
|
117 case LaunchActivity: |
|
118 case CancelWait: |
|
119 case CancelNotify: |
|
120 AfBroadcastTask::ExecuteL(mTasksStorage, message); |
|
121 break; |
|
122 |
|
123 case GetData: |
|
124 AfDataProviderTask::ExecuteL(*this,message); |
|
125 break; |
|
126 |
|
127 default: |
|
128 message.Complete(CServer2::EBadMessageNumber); |
|
129 break; |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 /** |
|
135 * Interface implementation |
|
136 * @see MAfTaskStorage::PushL(CAfTask *) |
|
137 */ |
|
138 void CAfSession::PushL(CAfTask * task) |
|
139 { |
|
140 (KErrNotFound == mRunningTasks.Find(task)) ? |
|
141 mRunningTasks.AppendL(task) : |
|
142 User::Panic(KTaskAlreadyExists, KErrAlreadyExists); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 /** |
|
147 * Interface implementation |
|
148 * @see MAfTaskStorage::Pop(CAfTask *) |
|
149 */ |
|
150 void CAfSession::Pop(CAfTask *task) |
|
151 { |
|
152 const TInt offset(mRunningTasks.Find(task)); |
|
153 if (KErrNotFound != offset) { |
|
154 mRunningTasks.Remove(offset); |
|
155 } |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 /** |
|
160 * Interface implementation |
|
161 * @see MAfTaskStorage::StorageData() |
|
162 */ |
|
163 const RPointerArray<CAfTask>& CAfSession::StorageData() const |
|
164 { |
|
165 return mRunningTasks; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 /** |
|
170 * Removes not valid task |
|
171 */ |
|
172 void CAfSession::RemoveNotValidTasks(const CSession2* session) |
|
173 { |
|
174 if (session == this) { |
|
175 mRunningTasks.ResetAndDestroy(); |
|
176 } |
|
177 } |