|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Sensor server message wrapper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SENSRVMESSAGE_H |
|
20 #define SENSRVMESSAGE_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include "sensrvtypes.h" |
|
24 |
|
25 class CSensrvSession; |
|
26 |
|
27 /** |
|
28 * Wraps the client message for sensor server internal handling. |
|
29 * |
|
30 * @since S60 5.0 |
|
31 */ |
|
32 class CSensrvMessage : public CBase |
|
33 { |
|
34 public: |
|
35 |
|
36 /** |
|
37 * Two-phased constructor for external message |
|
38 * |
|
39 * @since S60 5.0 |
|
40 * @return New CSensrvMessage instance |
|
41 */ |
|
42 static CSensrvMessage* NewL(); |
|
43 |
|
44 /** |
|
45 * Destructor. |
|
46 * @since S60 5.0 |
|
47 */ |
|
48 virtual ~CSensrvMessage(); |
|
49 |
|
50 /** |
|
51 * Initializes the message. Must be done before message is |
|
52 * used first time and before use after each complete. |
|
53 * |
|
54 * @since S60 5.0 |
|
55 * @param aMessage Client message to wrap |
|
56 */ |
|
57 void Initialize(const RMessage2& aMessage); |
|
58 |
|
59 /** |
|
60 * Completes the message |
|
61 * |
|
62 * @since S60 5.0 |
|
63 * @param aReason Completion reason identifier. Usually error code. |
|
64 */ |
|
65 void Complete(TInt aReason); |
|
66 |
|
67 /** |
|
68 * Gets the function requested by client. |
|
69 * |
|
70 * @since S60 5.0 |
|
71 * @return Function id. |
|
72 */ |
|
73 inline TInt Function() const { return iMessage.Function(); }; |
|
74 |
|
75 /** |
|
76 * Gets session related to this message. |
|
77 * |
|
78 * @since S60 5.0 |
|
79 * @return Pointer to related session. |
|
80 */ |
|
81 CSensrvSession* Session(); |
|
82 |
|
83 /** |
|
84 * Writes return data to wrapped message. |
|
85 * |
|
86 * @since S60 5.0 |
|
87 * @param aParam Parameter index to write |
|
88 * @param aDes Source descriptor for written data. |
|
89 * @param aOffset The offset from the start of the client's descriptor. |
|
90 * If not explicitly specified, the offset defaults to zero. |
|
91 * @return KErrArgument aParam is invalid, or if aOffset is negative. |
|
92 * KErrBadDescriptor Parameter is not a descriptor. |
|
93 * KErrOverflow Target descriptor is too small. |
|
94 */ |
|
95 TInt Write(TInt aParam, const TDesC8& aDes, TInt aOffset=0); |
|
96 |
|
97 /** |
|
98 * Gets message parameter descriptor maximum lenght. |
|
99 * |
|
100 * @since S60 5.0 |
|
101 * @param aParam Index of message parameter |
|
102 * @return If >= 0, indicates maximum lenght of descriptor parameter. |
|
103 * Otherwise indicates error code: KErrArgument if aParam is invalid, |
|
104 * or KErrBadDescriptor if message parameter specified |
|
105 * aParam is not of the descriptor type. |
|
106 */ |
|
107 TInt GetDesMaxLength(TInt aParam) const; |
|
108 |
|
109 /** |
|
110 * Gets message parameter descriptor lenght. |
|
111 * |
|
112 * @since S60 5.0 |
|
113 * @param aParam Index of message parameter |
|
114 * @return If >= 0, indicates maximum lenght of descriptor parameter. |
|
115 * Otherwise indicates error code: KErrArgument if aParam is invalid, |
|
116 * or KErrBadDescriptor if message parameter specified |
|
117 * aParam is not of the descriptor type. |
|
118 */ |
|
119 TInt GetDesLength(TInt aParam) const; |
|
120 |
|
121 /** |
|
122 * Gets client process SID |
|
123 * |
|
124 * @since S60 5.0 |
|
125 * @return Secure Id of the client process. |
|
126 */ |
|
127 TSecureId SecureId() const; |
|
128 |
|
129 /** |
|
130 * Reads data from wrapped message. |
|
131 * |
|
132 * @since S60 5.0 |
|
133 * @param aParam The index value identifying the argument. |
|
134 * This is a value in the range 0 to (KMaxMessageArguments-1) inclusive. |
|
135 * @param aDes The target descriptor into which the client data is to be written. |
|
136 * @return KErrArgument If aParam has a value outside the valid range. |
|
137 * KErrBadDescriptor If the message argument is not an 8-bit descriptor. |
|
138 */ |
|
139 TInt Read( const TInt aParam, TDes8 &aDes ) const; |
|
140 |
|
141 /** |
|
142 * Reads integer data from wrapped message. |
|
143 * |
|
144 * @since S60 5.0 |
|
145 * @param aParam The index value identifying the argument. |
|
146 * This is a value in the range 0 to (KMaxMessageArguments-1) inclusive. |
|
147 * @param aInt The target integer where the value is read. |
|
148 */ |
|
149 void ReadInt( const TInt aParam, TInt &aInt ) const; |
|
150 |
|
151 /** |
|
152 * Extracts channel id from message. |
|
153 * |
|
154 * @since S60 5.0 |
|
155 * @param aChannelId The found channel id is returned here. |
|
156 * @return KErrNotSupported If message data doesn't include channel id. |
|
157 */ |
|
158 TInt GetChannelId(TSensrvChannelId& aChannelId) const; |
|
159 |
|
160 /** |
|
161 * Gets the security info of the client message |
|
162 * |
|
163 * @since S60 5.0 |
|
164 * @param aSecurityInfo This object will contain client security info |
|
165 */ |
|
166 void GetSecurityInfo(TSecurityInfo& aSecurityInfo) const; |
|
167 |
|
168 /** |
|
169 * Returns message handle. Used to determine if message is still valid. |
|
170 * |
|
171 * @since S60 5.0 |
|
172 * @return Message handle. Handle will be zero if message is not currently valid. |
|
173 */ |
|
174 inline TInt Handle() const { return iMessage.Handle(); }; |
|
175 |
|
176 /** |
|
177 * Returns the message as read only. |
|
178 * |
|
179 * @since S60 5.0 |
|
180 * @return The message. |
|
181 */ |
|
182 inline const RMessage2& GetMessage() const { return iMessage; }; |
|
183 |
|
184 private: |
|
185 |
|
186 /** |
|
187 * C++ constructor for external message. |
|
188 */ |
|
189 CSensrvMessage(); |
|
190 |
|
191 private: // Data |
|
192 |
|
193 /** |
|
194 * Wrapped message |
|
195 */ |
|
196 RMessage2 iMessage; |
|
197 }; |
|
198 |
|
199 |
|
200 #endif // SENSRVMESSAGE_H |