1 /* |
|
2 * Copyright (c) 2008-2010 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 the License "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 * Utils functions used by scr session and subsession clients. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef SCRCLIENT_INL |
|
27 #define SCRCLIENT_INL |
|
28 |
|
29 #include <usif/scr/scr.h> |
|
30 #include <scs/cleanuputils.h> |
|
31 #include <scs/streamingarray.h> |
|
32 #include <s32mem.h> |
|
33 |
|
34 namespace Usif |
|
35 { |
|
36 template <class C> |
|
37 inline HBufC8* GetObjectDataLC(const C& aConnection, TInt aFunction, TInt aDataSize) |
|
38 { |
|
39 HBufC8 *buf = HBufC8::NewLC(aDataSize); |
|
40 TPtr8 ptrBuf(buf->Des()); |
|
41 TIpcArgs argBuf(&ptrBuf); |
|
42 User::LeaveIfError(aConnection.SendSyncMessage(aFunction, argBuf)); |
|
43 return buf; |
|
44 } |
|
45 |
|
46 template <class T, class C> |
|
47 inline T* GetObjectL(const C& aConnection, TInt aSizeFunction, TInt aDataFunction, TInt aArgNum, TIpcArgs& aArgs) |
|
48 { |
|
49 TInt size(0); |
|
50 TPckg<TInt> sizePak(size); |
|
51 aArgs.Set(aArgNum, &sizePak); |
|
52 User::LeaveIfError(aConnection.SendSyncMessage(aSizeFunction, aArgs)); |
|
53 if(!size) |
|
54 {// There is no related object return NULL |
|
55 return NULL; |
|
56 } |
|
57 HBufC8 *buf = GetObjectDataLC(aConnection, aDataFunction, size); |
|
58 |
|
59 RDesReadStream stream(*buf); |
|
60 CleanupClosePushL(stream); |
|
61 T *retObject = TTraits<T>::ReadFromStreamL(stream); |
|
62 CleanupStack::PopAndDestroy(2, buf); |
|
63 return retObject; |
|
64 } |
|
65 |
|
66 template <class T, class C> |
|
67 inline TBool GetObjectL(const C& aConnection, T& aObject, TInt aSizeFunction, TInt aDataFunction, TInt aArgNum, TIpcArgs& aArgs) |
|
68 { |
|
69 TInt size(0); |
|
70 TPckg<TInt> sizePak(size); |
|
71 aArgs.Set(aArgNum, &sizePak); |
|
72 User::LeaveIfError(aConnection.SendSyncMessage(aSizeFunction, aArgs)); |
|
73 if(!size) |
|
74 {// There is no related object, return EFalse |
|
75 return EFalse; |
|
76 } |
|
77 HBufC8 *buf = GetObjectDataLC(aConnection, aDataFunction, size); |
|
78 |
|
79 RDesReadStream stream(*buf); |
|
80 CleanupClosePushL(stream); |
|
81 aObject.InternalizeL(stream); |
|
82 CleanupStack::PopAndDestroy(2, buf); |
|
83 return ETrue; |
|
84 } |
|
85 |
|
86 template <class C, class T> |
|
87 inline void GetObjectArrayL(const C& aConnection, TInt aSizeFunction, TInt aDataFunction, TInt aArgNum, TIpcArgs& aArgs, RPointerArray<T>& aArray) |
|
88 { |
|
89 TInt size(0); |
|
90 TPckg<TInt> sizePak(size); |
|
91 aArgs.Set(aArgNum, &sizePak); |
|
92 User::LeaveIfError(aConnection.SendSyncMessage(aSizeFunction, aArgs)); |
|
93 if(!size) |
|
94 {// There is no related data, return. |
|
95 return; |
|
96 } |
|
97 HBufC8 *buf = GetObjectDataLC(aConnection, aDataFunction, size); |
|
98 |
|
99 RDesReadStream stream(*buf); |
|
100 CleanupClosePushL(stream); |
|
101 InternalizePointersArrayL(aArray, stream); |
|
102 CleanupStack::PopAndDestroy(2, buf); |
|
103 } |
|
104 |
|
105 template <class C, class T> |
|
106 inline void GetObjectArrayL(const C& aConnection, TInt aSizeFunction, TInt aDataFunction, TInt aArgNum, TIpcArgs& aArgs, RArray<T>& aArray) |
|
107 { |
|
108 TInt size(0); |
|
109 TPckg<TInt> sizePak(size); |
|
110 aArgs.Set(aArgNum, &sizePak); |
|
111 User::LeaveIfError(aConnection.SendSyncMessage(aSizeFunction, aArgs)); |
|
112 if(!size) |
|
113 {// There is no related data, return. |
|
114 return; |
|
115 } |
|
116 HBufC8 *buf = GetObjectDataLC(aConnection, aDataFunction, size); |
|
117 |
|
118 RDesReadStream stream(*buf); |
|
119 CleanupClosePushL(stream); |
|
120 InternalizeFixedLengthArrayL(aArray, stream); |
|
121 CleanupStack::PopAndDestroy(2, buf); |
|
122 } |
|
123 |
|
124 template <class C> |
|
125 inline void ExternalizeObjectL(const C* aObject, RBuf8& aBuf) |
|
126 { |
|
127 const C *localCopyOfObject(0); |
|
128 |
|
129 if(!aObject) |
|
130 {// if object is not supplied, then create an empty one. |
|
131 localCopyOfObject = C::NewLC(); |
|
132 } |
|
133 else |
|
134 { |
|
135 localCopyOfObject = aObject; |
|
136 } |
|
137 |
|
138 // Get the required buffer size for the externalized C object |
|
139 TInt bufSize = GetObjectBufferSizeL(*localCopyOfObject); |
|
140 |
|
141 // Clean the buffer and re-create it with the required buffer size |
|
142 aBuf.Close(); |
|
143 aBuf.CreateL(bufSize); |
|
144 |
|
145 // Externalize the filter object into the buffer |
|
146 RDesWriteStream wstream(aBuf); |
|
147 wstream.PushL(); |
|
148 wstream << *localCopyOfObject; |
|
149 wstream.CommitL(); |
|
150 wstream.Pop(); |
|
151 wstream.Release(); |
|
152 |
|
153 if(!aObject) |
|
154 {// destroy the filter if created locally |
|
155 CleanupStack::PopAndDestroy((C*)localCopyOfObject); |
|
156 } |
|
157 }// End of ExternalizeObjectL |
|
158 |
|
159 template <class C> |
|
160 inline void ExternalizeRefObjectL(const C& aObject, RBuf8& aBuf) |
|
161 { |
|
162 // Get the required buffer size for the externalized C object |
|
163 TInt bufSize = GetObjectBufferSizeL(aObject); |
|
164 |
|
165 // Clean the buffer and re-create it with the required buffer size |
|
166 aBuf.Close(); |
|
167 aBuf.CreateL(bufSize); |
|
168 |
|
169 // Externalize the filter object into the buffer |
|
170 RDesWriteStream wstream(aBuf); |
|
171 wstream.PushL(); |
|
172 wstream << aObject; |
|
173 wstream.CommitL(); |
|
174 wstream.Pop(); |
|
175 wstream.Release(); |
|
176 |
|
177 }// End of ExternalizeObjectL |
|
178 } |
|
179 |
|
180 #endif /* SCRCLIENT_INL */ |
|