|
1 // wsp_request.cpp |
|
2 // |
|
3 // Copyright (c) 2002 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 |
|
14 #include "_windows.h" |
|
15 #include "wsp_request.h" |
|
16 #include "wsp_panic.h" |
|
17 #include "wsp_log.h" |
|
18 |
|
19 |
|
20 // |
|
21 // TWin32Message. |
|
22 // |
|
23 |
|
24 void TWin32Message::Set(TInt aOppCode) |
|
25 { |
|
26 iOppCode = aOppCode; |
|
27 iReadBuf = NULL; |
|
28 iWriteBuf = NULL; |
|
29 iCompletionStatus = NULL; |
|
30 iParentThread.SetHandle(0); |
|
31 } |
|
32 |
|
33 void TWin32Message::Set(TInt aOppCode, TRequestStatus& aCompletionStatus) |
|
34 { |
|
35 iOppCode = aOppCode; |
|
36 iReadBuf = NULL; |
|
37 iWriteBuf = NULL; |
|
38 iCompletionStatus = &aCompletionStatus; |
|
39 aCompletionStatus = KRequestPending; |
|
40 iParentThread.SetHandle(0); |
|
41 } |
|
42 |
|
43 void TWin32Message::Set(TInt aOppCode, const TDesC8& aReadBuf) |
|
44 { |
|
45 iOppCode = aOppCode; |
|
46 iReadBuf = &aReadBuf; |
|
47 iWriteBuf = NULL; |
|
48 iCompletionStatus = NULL; |
|
49 iParentThread.SetHandle(0); |
|
50 } |
|
51 |
|
52 void TWin32Message::Set(TInt aOppCode, const TDesC8& aReadBuf, TRequestStatus& aCompletionStatus) |
|
53 { |
|
54 iOppCode = aOppCode; |
|
55 iReadBuf = &aReadBuf; |
|
56 iWriteBuf = NULL; |
|
57 iCompletionStatus = &aCompletionStatus; |
|
58 aCompletionStatus = KRequestPending; |
|
59 iParentThread.SetHandle(0); |
|
60 } |
|
61 |
|
62 void TWin32Message::Set(TInt aOppCode, TDes8& aWriteBuf) |
|
63 { |
|
64 iOppCode = aOppCode; |
|
65 iReadBuf = NULL; |
|
66 iWriteBuf = &aWriteBuf; |
|
67 iCompletionStatus = NULL; |
|
68 iParentThread.SetHandle(0); |
|
69 } |
|
70 |
|
71 void TWin32Message::Set(TInt aOppCode, TDes8& aWriteBuf, TRequestStatus& aCompletionStatus) |
|
72 { |
|
73 iOppCode = aOppCode; |
|
74 iReadBuf = NULL; |
|
75 iWriteBuf = &aWriteBuf; |
|
76 iCompletionStatus = &aCompletionStatus; |
|
77 aCompletionStatus = KRequestPending; |
|
78 iParentThread.SetHandle(0); |
|
79 } |
|
80 |
|
81 void TWin32Message::Set(TInt aOppCode, const TDesC8& aReadBuf, TDes8& aWriteBuf) |
|
82 { |
|
83 iOppCode = aOppCode; |
|
84 iReadBuf = &aReadBuf; |
|
85 iWriteBuf = &aWriteBuf; |
|
86 iCompletionStatus = NULL; |
|
87 iParentThread.SetHandle(0); |
|
88 } |
|
89 |
|
90 void TWin32Message::Set(TInt aOppCode, const TDesC8& aReadBuf, TDes8& aWriteBuf, TRequestStatus& aCompletionStatus) |
|
91 { |
|
92 iOppCode = aOppCode; |
|
93 iReadBuf = &aReadBuf; |
|
94 iWriteBuf = &aWriteBuf; |
|
95 iCompletionStatus = &aCompletionStatus; |
|
96 aCompletionStatus = KRequestPending; |
|
97 iParentThread.SetHandle(0); |
|
98 } |
|
99 |
|
100 TInt TWin32Message::OppCode() const |
|
101 { |
|
102 return iOppCode; |
|
103 } |
|
104 |
|
105 const TDesC8& TWin32Message::ReadBuffer() const |
|
106 { |
|
107 __ASSERT_DEBUG(iReadBuf, Panic(EWinSockPrtInvalidMessageReadBuffer)); |
|
108 return *iReadBuf; |
|
109 } |
|
110 |
|
111 TDes8& TWin32Message::WriteBuffer() |
|
112 { |
|
113 __ASSERT_DEBUG(iWriteBuf, Panic(EWinSockPrtInvalidMessageWriteBuffer)); |
|
114 return *iWriteBuf; |
|
115 } |
|
116 |
|
117 void TWin32Message::Complete(TInt aReason) |
|
118 { |
|
119 __ASSERT_DEBUG(iCompletionStatus, Panic(EWinSockPrtInvalidCompletionStatus)); |
|
120 iParentThread.RequestComplete(iCompletionStatus, aReason); |
|
121 } |
|
122 |
|
123 void TWin32Message::SetParentThreadHandle(RThread aParentThread) |
|
124 { |
|
125 __ASSERT_DEBUG(iParentThread.Handle() == 0, Panic(EWinSockPrtInvalidMessageParentThreadHandle)); |
|
126 iParentThread = aParentThread; |
|
127 } |
|
128 |
|
129 |
|
130 // |
|
131 // TWin32Request. |
|
132 // |
|
133 |
|
134 TWin32Request::TWin32Request() |
|
135 : iEvent(0), iMessage(NULL), iSubSession(0) |
|
136 { |
|
137 } |
|
138 |
|
139 TInt TWin32Request::DuplicateParentThreadHandle(RThread aChildThread) |
|
140 { |
|
141 return iParentThread.Duplicate(aChildThread); |
|
142 } |
|
143 |
|
144 TInt TWin32Request::MakeRequest(TWin32Message& aMessage) |
|
145 { |
|
146 WSP_LOG(WspLog::Printf(_L("TWin32Request::MakeRequest: aMessage: 0x%x"), &aMessage)); |
|
147 __ASSERT_DEBUG(iMessage == NULL, Panic(EWinSockPrtMultipleRequests)); |
|
148 iMessage = &aMessage; |
|
149 iMessage->SetParentThreadHandle(iParentThread); |
|
150 iSubSession = 0; |
|
151 iRequestStatus = KRequestPending; |
|
152 return MakeRequestAndWait(); |
|
153 } |
|
154 |
|
155 TInt TWin32Request::MakeRequest(TWin32Message& aMessage, TInt aSubSession) |
|
156 { |
|
157 WSP_LOG(WspLog::Printf(_L("TWin32Request::MakeRequest: aMessage: 0x%x, aSubSession: 0x%x"), &aMessage, aSubSession)); |
|
158 __ASSERT_DEBUG(iMessage == NULL, Panic(EWinSockPrtMultipleRequests)); |
|
159 iMessage = &aMessage; |
|
160 iMessage->SetParentThreadHandle(iParentThread); |
|
161 iSubSession = aSubSession; |
|
162 iRequestStatus = KRequestPending; |
|
163 return MakeRequestAndWait(); |
|
164 } |
|
165 |
|
166 void TWin32Request::SetEventHandle(WIN32_HANDLE aEvent) |
|
167 { |
|
168 iEvent = aEvent; |
|
169 } |
|
170 |
|
171 void TWin32Request::Requested(TInt aReason) |
|
172 { |
|
173 WSP_LOG(WspLog::Printf(_L("TWin32Request::Requested: aReason: %d, iMessage: 0x%x, iSubSession: 0x%x"), aReason, iMessage, iSubSession)); |
|
174 TRequestStatus* requestStatusPtr = &iRequestStatus; |
|
175 iParentThread.RequestComplete(requestStatusPtr, aReason); |
|
176 } |
|
177 |
|
178 TInt TWin32Request::SubSession() const |
|
179 { |
|
180 return iSubSession; |
|
181 } |
|
182 |
|
183 TWin32Message& TWin32Request::Message() |
|
184 { |
|
185 __ASSERT_DEBUG(iMessage, Panic(EWinSockPrtInvalidMessage)); |
|
186 return *iMessage; |
|
187 } |
|
188 |
|
189 TInt TWin32Request::MakeRequestAndWait() |
|
190 { |
|
191 if (!SetEvent(iEvent)) |
|
192 { |
|
193 return KErrBadHandle; |
|
194 } |
|
195 User::WaitForRequest(iRequestStatus); |
|
196 iMessage = NULL; |
|
197 return iRequestStatus.Int(); |
|
198 } |