|
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 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 * AuthServerUtil a utility class used by Authentication Server |
|
16 * implemented as static functions |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @internalComponent |
|
24 @released |
|
25 */ |
|
26 |
|
27 #ifndef __AUTHSERVERUTIL_H__ |
|
28 #define __AUTHSERVERUTIL_H__ |
|
29 |
|
30 #include <f32file.h> |
|
31 #include <s32mem.h> |
|
32 #include "arrayutils.h" |
|
33 |
|
34 namespace AuthServer |
|
35 { |
|
36 |
|
37 class AuthServerUtil |
|
38 { |
|
39 public: |
|
40 // IPC helper methods |
|
41 template<class T> |
|
42 static HBufC8* FlattenDataArrayLC(const RArray<T>& aArray); |
|
43 template<class T> |
|
44 static void SendDataArrayL(const RMessage2& aMessage, const RArray<T>& aArray, TInt aIpcIndx); |
|
45 |
|
46 template<class T> |
|
47 static HBufC8* FlattenDataPointerArrayLC(const RPointerArray<T>& aPointerArray); |
|
48 template<class T> |
|
49 static void SendDataPointerArrayL(const RMessage2& aMessage, const RPointerArray<T>& aPointerArray, TInt aIpcIndx); |
|
50 }; |
|
51 |
|
52 // Templated function definitions must appear in the header file |
|
53 |
|
54 template<class T> |
|
55 HBufC8* AuthServerUtil::FlattenDataArrayLC(const RArray<T>& aArray) |
|
56 { |
|
57 // dynamic buffer since we don't know in advance the size required |
|
58 CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize); |
|
59 CleanupStack::PushL(tempBuffer); |
|
60 |
|
61 RBufWriteStream stream(*tempBuffer); |
|
62 CleanupClosePushL(stream); |
|
63 |
|
64 // externalise the array of objects |
|
65 ExternalizeArrayL(aArray, stream); |
|
66 stream.CommitL(); |
|
67 |
|
68 // Now, create an HBufC8 from the stream buf's length, and copy |
|
69 // the stream buffer into this descriptor |
|
70 HBufC8* buffer = HBufC8::NewL(tempBuffer->Size()); |
|
71 TPtr8 ptr(buffer->Des()); |
|
72 tempBuffer->Read(0, ptr, tempBuffer->Size()); |
|
73 CleanupStack::PopAndDestroy(2, tempBuffer); // tempBuffer, stream |
|
74 |
|
75 CleanupStack::PushL(buffer); |
|
76 return buffer; |
|
77 } |
|
78 |
|
79 template<class T> |
|
80 void AuthServerUtil::SendDataArrayL(const RMessage2& aMessage, |
|
81 const RArray<T>& aArray, |
|
82 TInt aIpcIndx) |
|
83 { |
|
84 HBufC8* buffer = FlattenDataArrayLC(aArray); |
|
85 TPtr8 pbuffer(buffer->Des()); |
|
86 |
|
87 if (aMessage.GetDesMaxLengthL(aIpcIndx) < buffer->Size()) |
|
88 { |
|
89 TInt bufferSize = buffer->Size(); |
|
90 TPckgC<TInt> bufferSizePackage(bufferSize); |
|
91 aMessage.WriteL(aIpcIndx, bufferSizePackage); |
|
92 aMessage.Complete(KErrOverflow); |
|
93 } |
|
94 else |
|
95 { |
|
96 aMessage.WriteL(aIpcIndx, *buffer); |
|
97 aMessage.Complete(KErrNone); |
|
98 } |
|
99 |
|
100 CleanupStack::PopAndDestroy(buffer); |
|
101 } |
|
102 |
|
103 template<class T> |
|
104 HBufC8* AuthServerUtil::FlattenDataPointerArrayLC(const RPointerArray<T>& aPointerArray) |
|
105 { |
|
106 // dynamic buffer since we don't know in advance the size required |
|
107 CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize); |
|
108 CleanupStack::PushL(tempBuffer); |
|
109 |
|
110 RBufWriteStream stream(*tempBuffer); |
|
111 CleanupClosePushL(stream); |
|
112 |
|
113 // externalise the pointer array |
|
114 ExternalizePointerArrayL(aPointerArray, stream); |
|
115 stream.CommitL(); |
|
116 |
|
117 // Create an HBufC8 from the stream buf's length, and copy |
|
118 // the stream buffer into this descriptor |
|
119 HBufC8* buffer = HBufC8::NewL(tempBuffer->Size()); |
|
120 TPtr8 ptr(buffer->Des()); |
|
121 tempBuffer->Read(0, ptr, tempBuffer->Size()); |
|
122 CleanupStack::PopAndDestroy(2, tempBuffer); // tempBuffer, stream, |
|
123 |
|
124 CleanupStack::PushL(buffer); |
|
125 return buffer; |
|
126 } |
|
127 |
|
128 template<class T> |
|
129 void AuthServerUtil::SendDataPointerArrayL(const RMessage2& aMessage, |
|
130 const RPointerArray<T>& aPointerArray, |
|
131 TInt aIpcIndx) |
|
132 { |
|
133 HBufC8* buffer = FlattenDataPointerArrayLC(aPointerArray); |
|
134 TPtr8 pbuffer(buffer->Des()); |
|
135 |
|
136 if (aMessage.GetDesMaxLengthL(aIpcIndx) < buffer->Size()) |
|
137 { |
|
138 TInt bufferSize = buffer->Size(); |
|
139 TPckgC<TInt> bufferSizePackage(bufferSize); |
|
140 aMessage.WriteL(aIpcIndx, bufferSizePackage); |
|
141 aMessage.Complete(KErrOverflow); |
|
142 } |
|
143 else |
|
144 { |
|
145 aMessage.WriteL(aIpcIndx, *buffer); |
|
146 aMessage.Complete(KErrNone); |
|
147 } |
|
148 |
|
149 CleanupStack::PopAndDestroy(buffer); |
|
150 } |
|
151 |
|
152 } // namespace |
|
153 #endif //__AUTHSERVERUTIL_H__ |