|
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 "afstorageclientimp.h" |
|
18 |
|
19 #include <fbs.h> |
|
20 #include <s32mem.h> |
|
21 |
|
22 #include "afstorageglobals.h" |
|
23 #include "afglobals.h" |
|
24 #include "afentry.h" |
|
25 #include "afasyncrequest_p.h" |
|
26 #include "afthumbnailrequest_p.h" |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 /** |
|
30 * Furst phase constructor |
|
31 */ |
|
32 RAfStorageClientImplementation::RAfStorageClientImplementation(MAfAsyncRequestObserver &observer) |
|
33 : |
|
34 mObserver(observer) |
|
35 {} |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 /** |
|
39 * Destructor |
|
40 */ |
|
41 RAfStorageClientImplementation::~RAfStorageClientImplementation() |
|
42 { |
|
43 Close(); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 void RAfStorageClientImplementation::Close() |
|
48 { |
|
49 mAsyncTasks.ResetAndDestroy(); |
|
50 RSessionBase::Close(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 /** |
|
55 * Function establish connection to activity server |
|
56 */ |
|
57 void RAfStorageClientImplementation::connectL() |
|
58 { |
|
59 const int asyncMessageSlots(12); |
|
60 const int maxRetry(4); |
|
61 TInt retry = maxRetry; |
|
62 TInt errNo(KErrNone); |
|
63 do { |
|
64 errNo = CreateSession(KActivityServerName, |
|
65 TVersion(0, 0, 0), |
|
66 asyncMessageSlots); |
|
67 if (KErrNotFound != errNo && KErrServerTerminated != errNo) { |
|
68 retry =0; |
|
69 } else { |
|
70 TRAP(errNo, startServerL()); |
|
71 if (KErrNone != errNo && KErrAlreadyExists != errNo) { |
|
72 retry =0; |
|
73 errNo = CreateSession(KActivityServerName, |
|
74 TVersion(0, 0, 0), |
|
75 asyncMessageSlots); |
|
76 } |
|
77 } |
|
78 } while (--retry > 0); |
|
79 User::LeaveIfError(errNo); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 void RAfStorageClientImplementation::startServerL() |
|
84 { |
|
85 RProcess server; |
|
86 const TUidType uid(KNullUid, KNullUid, KActivityServerUid); |
|
87 User::LeaveIfError(server.Create(KActivityServerName, KNullDesC, uid)); |
|
88 TRequestStatus stat; |
|
89 server.Rendezvous(stat); |
|
90 if (stat != KRequestPending) { |
|
91 server.Kill(0); |
|
92 } else { |
|
93 server.Resume(); |
|
94 } |
|
95 User::WaitForRequest(stat); |
|
96 int errNo = (EExitPanic == server.ExitType()) ? |
|
97 KErrGeneral : stat.Int(); |
|
98 if (KErrCancel == errNo) { |
|
99 errNo = KErrNone; |
|
100 } |
|
101 server.Close(); |
|
102 User::LeaveIfError(errNo); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 void RAfStorageClientImplementation::executeL(int function) |
|
107 { |
|
108 switch (function) { |
|
109 case WaitActivity: |
|
110 case NotifyChange: |
|
111 CAfAsyncRequestPrivate::NewLD(mObserver, *this, static_cast<ActivityCmd>(function)); |
|
112 break; |
|
113 default: |
|
114 User::LeaveIfError(SendReceive(function, TIpcArgs())); |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 void RAfStorageClientImplementation::executeL(int function, |
|
120 const CAfEntry &entry, |
|
121 int userData) |
|
122 { |
|
123 TPckgBuf<TInt> data(userData); |
|
124 RBuf8 serializedEntry; |
|
125 CleanupClosePushL(serializedEntry); |
|
126 serializedEntry.CreateL(entry.Size()); |
|
127 RDesWriteStream stream(serializedEntry); |
|
128 CleanupClosePushL(stream); |
|
129 stream << entry; |
|
130 CleanupStack::PopAndDestroy(&stream); |
|
131 User::LeaveIfError(SendReceive(function, TIpcArgs(&serializedEntry, &data))); |
|
132 CleanupStack::PopAndDestroy(&serializedEntry); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 void RAfStorageClientImplementation::executeL(int function, RPointerArray<CAfEntry> &resultsList, const CAfEntry& templateEntry) |
|
137 { |
|
138 resultsList.ResetAndDestroy(); |
|
139 RBuf8 buffer; |
|
140 CleanupClosePushL(buffer); |
|
141 CAfEntry::ReallocL(buffer, templateEntry.Size()); |
|
142 RDesWriteStream writer(buffer); |
|
143 CleanupClosePushL(writer); |
|
144 writer << templateEntry; |
|
145 CleanupStack::PopAndDestroy(&writer); |
|
146 TPckgBuf<int> length(0), taskId(0); |
|
147 User::LeaveIfError(SendReceive(function, |
|
148 TIpcArgs(&buffer, &length, &taskId))); |
|
149 CAfEntry::ReallocL(buffer, length()); |
|
150 User::LeaveIfError(SendReceive(GetData, TIpcArgs(&taskId, &buffer))); |
|
151 resultsList << buffer; |
|
152 CleanupStack::PopAndDestroy(&buffer); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 void RAfStorageClientImplementation::getThumbnailL(TSize size, |
|
157 const TDesC& source, |
|
158 TAny *userData ) |
|
159 { |
|
160 CAfThumbnailRequestPrivate::NewLD(mObserver, *this, size, source, userData); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 void RAfStorageClientImplementation::PushL(CBase* asyncTask) |
|
165 { |
|
166 const TInt offset(mAsyncTasks.Find(asyncTask)); |
|
167 (KErrNotFound == offset) ? mAsyncTasks.AppendL(asyncTask) : User::Leave(KErrAlreadyExists); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 void RAfStorageClientImplementation::Pop(CBase* asyncTask) |
|
172 { |
|
173 const TInt offset(mAsyncTasks.Find(asyncTask)); |
|
174 if (KErrNotFound != offset) { |
|
175 mAsyncTasks.Remove(offset); |
|
176 } |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 void RAfStorageClientImplementation::sendAsync(int function, |
|
181 const TIpcArgs& args, |
|
182 TRequestStatus& status) |
|
183 { |
|
184 SendReceive(function, args, status); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 void RAfStorageClientImplementation::getDataL(int id, TDes8& buffer) |
|
189 { |
|
190 TPckgBuf<int> requestId(id); |
|
191 SendReceive(GetData, TIpcArgs(&requestId, &buffer)); |
|
192 } |