|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of DTClient |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "DTClient.h" |
|
21 #include "DevTokenUtils.h" |
|
22 #include "DevTokenClientSession.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CDTClient::CDTClient() |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CDTClient::CDTClient(TInt aUID, |
|
32 MCTToken& aToken, |
|
33 RDevTokenClientSession& aClient) |
|
34 : CActive(EPriorityNormal), |
|
35 iToken(aToken), |
|
36 iInterfaceUID(aUID), |
|
37 iClientSession(aClient), |
|
38 iRequestPtr(NULL, 0, 0) |
|
39 { |
|
40 } |
|
41 |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CDTClient::~CDTClient() |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CDTClient::~CDTClient() |
|
48 { |
|
49 Cancel(); |
|
50 delete iRequestDataBuf; |
|
51 } |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CDTClient::TAsyncRequest::~TAsyncRequest() |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CDTClient::TAsyncRequest::~TAsyncRequest() |
|
59 { |
|
60 __ASSERT_DEBUG(EIdle==iRequest, DevTokenPanic(ERequestOutstanding)); |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CDTClient::TAsyncRequest::operator() |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CDTClient::TAsyncRequest::operator()(TDevTokenMessages aRequest, |
|
69 TRequestStatus* aStatus) |
|
70 { |
|
71 __ASSERT_DEBUG(EIdle==iRequest, DevTokenPanic(ERequestOutstanding)); |
|
72 iRequest = aRequest; |
|
73 iClientStatus = aStatus; |
|
74 *aStatus = KRequestPending; |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CDTClient::TAsyncRequest::Complete() |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CDTClient::TAsyncRequest::Complete(TInt aCompletionResult) |
|
83 { |
|
84 __ASSERT_DEBUG(EIdle!=iRequest, DevTokenPanic(ENoRequestOutstanding)); |
|
85 User::RequestComplete(iClientStatus, aCompletionResult); |
|
86 iRequest = EIdle; |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CDTClient::TAsyncRequest::Cancel() |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CDTClient::TAsyncRequest::Cancel() |
|
95 { |
|
96 User::RequestComplete(iClientStatus, KErrCancel); |
|
97 iRequest = EIdle; |
|
98 } |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CDTClient::TAsyncRequest::FreeRequestBuffer() |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CDTClient::FreeRequestBuffer() const |
|
106 { |
|
107 delete iRequestDataBuf; |
|
108 iRequestDataBuf = NULL; |
|
109 iRequestPtr.Set(NULL, 0, 0); |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CDTClient::AllocRequestBuffer(TInt aReqdSize) const |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CDTClient::AllocRequestBuffer(TInt aReqdSize) const |
|
118 { |
|
119 ASSERT(aReqdSize > 0); |
|
120 TInt result = KErrNoMemory; |
|
121 |
|
122 FreeRequestBuffer(); |
|
123 iRequestDataBuf = HBufC8::NewMax(aReqdSize); |
|
124 if ( iRequestDataBuf ) |
|
125 { |
|
126 iRequestPtr.Set(iRequestDataBuf->Des()); |
|
127 iRequestPtr.FillZ(); |
|
128 result = KErrNone; |
|
129 } |
|
130 return result; |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CDTClient::SendSyncRequestAndHandleOverflowL() |
|
136 // Execute a synchronous request that returns a buffer of indetermintate length. |
|
137 // If the initial buffer is too short, the server leaves with KErrOverflow and |
|
138 // passes us the required length - the reuest is then re-sent. |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CDTClient::SendSyncRequestAndHandleOverflowL(TDevTokenMessages aMessage, |
|
142 TInt aInitialBufSize, |
|
143 const TIpcArgs& aArgs) const |
|
144 { |
|
145 User::LeaveIfError(AllocRequestBuffer(aInitialBufSize)); |
|
146 |
|
147 TInt err = iClientSession.SendRequest(aMessage, aArgs); |
|
148 if ( err == KErrOverflow ) |
|
149 { |
|
150 TInt sizeReqd = 0; |
|
151 TPckg<TInt> theSize(sizeReqd); |
|
152 theSize.Copy(iRequestPtr); |
|
153 User::LeaveIfError(AllocRequestBuffer(sizeReqd)); |
|
154 err = iClientSession.SendRequest(aMessage, aArgs); |
|
155 } |
|
156 User::LeaveIfError(err); |
|
157 } |
|
158 |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CDTClient::DoCancel() |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CDTClient::DoCancel() |
|
165 { |
|
166 iCurrentRequest.Cancel(); |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CDTClient::RunError() |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CDTClient::RunError(TInt aError) |
|
175 { |
|
176 iCurrentRequest.Complete(aError); |
|
177 return KErrNone; // Handled |
|
178 } |
|
179 |
|
180 //EOF |
|
181 |