author | Chad Peckham <chad.peckham@nokia.com> |
Wed, 02 Sep 2009 16:30:45 -0500 | |
changeset 476 | 1e1ad434efb1 |
parent 60 | 9d2210c8eed2 |
permissions | -rw-r--r-- |
60 | 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 |
* |
|
16 |
*/ |
|
17 |
#ifndef __SERVERCLIENT_H__ |
|
18 |
#define __SERVERCLIENT_H__ |
|
19 |
||
20 |
#include "shareddata.h" |
|
21 |
#include "mutex.h" |
|
22 |
||
23 |
#define MAX_IPADDRESS_SIZE (20) |
|
24 |
#define MAX_PORT_SIZE (6) |
|
25 |
typedef struct tagTcpConnectData |
|
26 |
{ |
|
27 |
char ipAddress[MAX_IPADDRESS_SIZE]; |
|
28 |
char ipPort[MAX_PORT_SIZE]; |
|
29 |
} *pTcpConnectData, TcpConnectData; |
|
30 |
||
31 |
enum eFlowControl |
|
32 |
{ |
|
33 |
eFlowControlNone, |
|
34 |
eFlowControlHW, |
|
35 |
eFlowControlSW, |
|
36 |
}; |
|
37 |
enum eStopBits |
|
38 |
{ |
|
39 |
eStopBits1, |
|
40 |
eStopBits15, |
|
41 |
eStopBits2, |
|
42 |
}; |
|
43 |
enum eParity |
|
44 |
{ |
|
45 |
eParityNone, |
|
46 |
eParityOdd, |
|
47 |
eParityEven, |
|
48 |
}; |
|
49 |
||
50 |
#define MAX_COMPORT_SIZE (20) |
|
51 |
typedef struct tagRealSerialConnectData |
|
52 |
{ |
|
53 |
eFlowControl flowControl; |
|
54 |
eStopBits stopBits; |
|
55 |
eParity parity; |
|
56 |
DWORD baudRate; |
|
57 |
DWORD dataBits; |
|
58 |
char comPort[MAX_COMPORT_SIZE]; |
|
59 |
} *pRealSerialConnectData, RealSerialConnectData; |
|
60 |
||
61 |
typedef struct tagVirtualSerialConnectData |
|
62 |
{ |
|
63 |
char comPort[MAX_COMPORT_SIZE]; |
|
64 |
} *pVirtualSerialConnectData, VirtualSerialConnectData; |
|
65 |
||
66 |
#define MAX_USBDEVICE_SIZE (100) |
|
67 |
typedef struct tagUSBConnectData |
|
68 |
{ |
|
69 |
// TODO |
|
70 |
char device[MAX_USBDEVICE_SIZE]; |
|
71 |
} *pUSBConnectData, USBConnectData; |
|
72 |
||
73 |
#define MAX_NUMBER_OPTIONS (20) |
|
74 |
#define MAX_DECODE_FORMAT (16) |
|
75 |
#define MAX_CONNECTION_TYPE (16) |
|
76 |
||
77 |
// per connection settings |
|
78 |
typedef struct tagConnectData |
|
79 |
{ |
|
80 |
DWORD retryInterval; // retry interval option |
|
81 |
DWORD retryTimeout; // retry timeout option |
|
82 |
DWORD traceBoxChannel; // added TraceBox information |
|
83 |
char decodeFormat[MAX_DECODE_FORMAT]; // decode format (e.g. "ost") option |
|
84 |
char connectType[MAX_CONNECTION_TYPE]; // connection type (e.g. "tcp") |
|
85 |
TcpConnectData tcpSettings; // TCP/IP settings |
|
86 |
RealSerialConnectData realSerialSettings; // real serial |
|
87 |
VirtualSerialConnectData virtualSerialSettings; // virtual serial |
|
88 |
USBConnectData usbSettings; // real USB |
|
89 |
||
90 |
} *pConnectData, ConnectData; |
|
91 |
||
92 |
// per client options - done at connect time |
|
93 |
typedef struct tagClientOptions |
|
94 |
{ |
|
95 |
DWORD unWrapFormat; // message unwrapping option (PN or OST) |
|
96 |
DWORD ostVersion; // which OST version to use on sendmessage (unused in native) |
|
97 |
||
98 |
} *pClientOptions, ClientOptions; |
|
99 |
||
100 |
// per client options - done on opening stream |
|
101 |
enum eMessageDestination |
|
102 |
{ |
|
103 |
eDestinationInputStream = 0, // input stream |
|
104 |
eDestinationFile, // message file |
|
105 |
}; |
|
106 |
#define MAX_FILEPATH (2048L) |
|
107 |
typedef struct tagDestinationOptions |
|
108 |
{ |
|
109 |
eMessageDestination destination; // eMessageDestination |
|
110 |
DWORD streamSize; // input stream size |
|
111 |
BOOL overFlowToFile; // overflow stream to file option |
|
112 |
CHAR destinationFile[MAX_FILEPATH]; // stream overflow file or message file |
|
113 |
||
114 |
} *pDestinationOptions, DestinationOptions; |
|
115 |
||
116 |
enum eServerCommand |
|
117 |
{ |
|
118 |
eCmdNone = 0, // no command to process |
|
119 |
eCmdConnect, // connect (connectSettings clientOptions *clientId) |
|
120 |
eCmdDisconnect, // disconnect (clientId) |
|
121 |
eCmdGetClientStatus, // getclientstatus (clientId *clientStatus) |
|
122 |
eCmdGetConnectionStatus, // getconnstatus |
|
123 |
eCmdSetMessageIds, // setmessageIds (clientId number messageIds) |
|
124 |
eCmdGetNumberVersions, // getnumberversions (clientId *number) |
|
125 |
eCmdGetVersion, // getversion (clientId index *version) |
|
126 |
eCmdGetNumberConnections, // getnumberconnections (*number) |
|
127 |
eCmdGetConnectionType, // getconnectiontype (index *connectionSettings.connectType) |
|
128 |
eCmdGetConnection, // getconnection (index *connectionSettings) |
|
129 |
eCmdGetNumberClients, // getnumclients (*number) |
|
130 |
eCmdOpenStream, // openstream (clientId destinationoptions) |
|
131 |
eCmdCloseStream, // closestream (clientId) |
|
132 |
eCmdStart, // start (clientId) |
|
133 |
eCmdStop, // stop (clientId) |
|
134 |
eCmdSendMessage, // sendmessage (clientId number message) |
|
135 |
eCmdTestClientConnection, // testconnection (clientId) |
|
136 |
eCmdTestConnection, // testconnection (connectSettings) |
|
137 |
eCmdExit, // tell server to exit its main command thread |
|
138 |
eCmdOpenMessageFile, // openfile (clientId destinationoptions) |
|
139 |
eCmdCloseMessageFile, // closefile (clientId) |
|
140 |
eCmdClearMessageFile, // clearfile (clientId) |
|
141 |
||
142 |
}; |
|
143 |
||
144 |
enum eServerResponse |
|
145 |
{ |
|
146 |
eRspNone = 0, // no response generated |
|
147 |
eRspOK, // response with no errors |
|
148 |
eRspError, // error response: error |
|
149 |
eRspExitted, // server has exitted |
|
150 |
}; |
|
151 |
||
152 |
enum eClientStatus |
|
153 |
{ |
|
154 |
eStarted, // message processing started |
|
155 |
eStopped, // message processing stopped |
|
156 |
eUnknownClient, // client not found |
|
157 |
}; |
|
158 |
||
159 |
enum eConnectionStatus |
|
160 |
{ |
|
161 |
eConnected, // connection is OK |
|
162 |
eDisconnected, // disconnected |
|
163 |
eRetryInProgress, // inside retry interval (connected) |
|
164 |
eRetryTimedOut, // retry timedout (disconnected) |
|
165 |
}; |
|
166 |
||
167 |
// ----------- Command/Response Data ------------------- |
|
168 |
#define MAX_VERSION_STRING (80) |
|
169 |
#define MAX_MESSAGEIDS (256) |
|
170 |
typedef struct tagServerCommandData |
|
171 |
{ |
|
172 |
eServerCommand command; // command type |
|
173 |
eServerResponse response; // response type |
|
174 |
eClientStatus clientStatus; // client status |
|
175 |
eConnectionStatus connectionStatus; // connection status |
|
176 |
long error; // response error |
|
177 |
unsigned long osError; // error from the OS if applicable |
|
178 |
long clientId; // clientID for command/response |
|
179 |
long index; // eGetVersion command/eGetConnection command |
|
180 |
long number; // length or other number value (see commands) |
|
181 |
char version[MAX_VERSION_STRING]; // eGetVersion response |
|
182 |
ConnectData connectSettings; // eConnect command/eGetConnection response |
|
183 |
ClientOptions clientOptions; // per client options |
|
184 |
DestinationOptions destinationOptions; // input stream or message file options |
|
185 |
long numClients; // eGetNumberClients response |
|
186 |
long numConnections; // eGetNumberConnections response |
|
187 |
long encodeOption; // eSendMessage - what to do with protocol headers |
|
188 |
BYTE protocolVersion; // eSendMessage - OST version byte if OST protocol |
|
189 |
BOOL useMyId; // eSendMessage |
|
190 |
BYTE myId; // eSendMessage |
|
191 |
BYTE messageIds[MAX_MESSAGEIDS]; // eSetMessageIds command |
|
192 |
||
193 |
} *pServerCommandData, ServerCommandData; |
|
194 |
||
195 |
#define SERVERCOMMANDDATA_MAP_SIZE (sizeof(ServerCommandData)) |
|
196 |
#define SERVERCOMMANDDATA_MAP_NAME "TCFServerCommandData" |
|
197 |
||
198 |
#define SERVERCOMMANDDATA_MUTEX_NAME "TCFServerCommandDataMutex" |
|
199 |
//#define SERVERCOMMANDDATA_MUTEX_TIMEOUT (60000L) |
|
200 |
#define SERVERCOMMANDDATA_MUTEX_TIMEOUT (1000L) |
|
201 |
||
202 |
class CServerCommandData : public CSharedData |
|
203 |
{ |
|
204 |
public: |
|
205 |
BOOL Init() { if (IsCreator()) \ |
|
206 |
{\ |
|
207 |
pServerCommandData pData = (pServerCommandData)GetDataPtr();\ |
|
208 |
pData->command = eCmdNone;\ |
|
209 |
pData->response = eRspNone;\ |
|
210 |
pData->clientStatus = eStopped;\ |
|
211 |
pData->connectionStatus = eDisconnected;\ |
|
212 |
pData->clientId = -1;\ |
|
213 |
pData->index = 0;\ |
|
214 |
pData->number = 0;\ |
|
215 |
pData->version[0] = 0;\ |
|
216 |
pData->numClients = 0;\ |
|
217 |
pData->numConnections = 0;\ |
|
218 |
memset(&pData->messageIds, 0, MAX_MESSAGEIDS);\ |
|
219 |
}\ |
|
220 |
return TRUE; } |
|
221 |
}; |
|
222 |
// ----------- Command/Response Data ------------------- |
|
223 |
||
224 |
// ----------- Send Message Data ------------------- |
|
225 |
#define MAX_SENDMESSAGE (64*1024L+12) |
|
226 |
typedef struct tagServerMessageData |
|
227 |
{ |
|
228 |
long length; |
|
229 |
BYTE message[MAX_SENDMESSAGE]; // eSendMessage command |
|
230 |
} *pServerMessageData, ServerMessageData; |
|
231 |
||
232 |
#define SERVERMESSAGEDATA_MAP_SIZE (sizeof(ServerMessageData)) |
|
233 |
#define SERVERMESSAGEDATA_MAP_NAME "TCFServerMessageData" |
|
234 |
||
235 |
class CServerMessageData : public CSharedData |
|
236 |
{ |
|
237 |
public: |
|
238 |
BOOL Init() { if (IsCreator()) \ |
|
239 |
{\ |
|
240 |
pServerMessageData pData = (pServerMessageData)GetDataPtr();\ |
|
241 |
memset(&pData->message, 0, MAX_SENDMESSAGE);\ |
|
242 |
pData->length = 0;\ |
|
243 |
}\ |
|
244 |
return TRUE; } |
|
245 |
}; |
|
246 |
// ----------- Send Message Data ------------------- |
|
247 |
||
248 |
// ----------- Server Process Data ------------------- |
|
249 |
typedef struct tagServerProcessData |
|
250 |
{ |
|
251 |
long numRefs; // reference count (first creates server process/last destroys server process) |
|
252 |
PROCESS_INFORMATION serverProcess; // Server process information |
|
253 |
} *pServerProcessData, ServerProcessData; |
|
254 |
||
255 |
#define SERVERPROCESSDATA_MAP_SIZE (sizeof(ServerProcessData)) |
|
256 |
#define SERVERPROCESSDATA_MAP_NAME "TCFServerProcessData" |
|
257 |
||
258 |
class CServerProcessData : public CSharedData |
|
259 |
{ |
|
260 |
public: |
|
261 |
BOOL Init() { if (IsCreator()) \ |
|
262 |
{\ |
|
263 |
pServerProcessData pData = (pServerProcessData)GetDataPtr();\ |
|
264 |
pData->numRefs = 0;\ |
|
265 |
memset(&pData->serverProcess, 0, sizeof(pData->serverProcess));\ |
|
266 |
pData->serverProcess.hProcess = NULL;\ |
|
267 |
}\ |
|
268 |
return TRUE; } |
|
269 |
}; |
|
270 |
// ----------- Server Process Data ------------------- |
|
271 |
||
272 |
||
273 |
// Main server command/response class |
|
274 |
#define SERVERPIPE_MUTEX_NAME "TCFServerPipeMutex" |
|
275 |
#define SERVERPIPE_MUTEX_TIMEOUT (60000L) |
|
276 |
||
277 |
// Server command/response events |
|
278 |
#define SERVER_COMMAND_READY_EVENTNAME "TCFServerCommandReadyEvent" |
|
279 |
#define SERVER_RESPONSE_READY_EVENTNAME "TCFServerResponseReadyEvent" |
|
476
1e1ad434efb1
Decrease TCFServer response timeout to 10 seconds
Chad Peckham <chad.peckham@nokia.com>
parents:
60
diff
changeset
|
280 |
#define SERVER_CMDRSP_EVENT_TIMEOUT 10000L |
60 | 281 |
|
282 |
class CServerCommand |
|
283 |
{ |
|
284 |
public: |
|
285 |
CServerCommand(); |
|
286 |
~CServerCommand(); |
|
287 |
||
288 |
// Client methods |
|
289 |
BOOL SendCommand(pServerCommandData pCmd, DWORD msgLength=0, BYTE* message=NULL); |
|
290 |
BOOL GetResponse(pServerCommandData pRsp); |
|
291 |
||
292 |
// Server methods |
|
293 |
BOOL GetCommand(pServerCommandData pCmd, pServerMessageData pMsg); |
|
294 |
BOOL SendResponse(pServerCommandData pRsp); |
|
295 |
||
296 |
BOOL WaitforServerPipeAccess() { return m_ServerPipeMutex.Wait(); } |
|
297 |
BOOL ReleaseServerPipeAccess() { return m_ServerPipeMutex.Release(); } |
|
298 |
||
299 |
pServerProcessData GetProcessPtr() { return (pServerProcessData)m_ServerProcessData.GetDataPtr(); } |
|
300 |
||
301 |
private: |
|
302 |
pServerCommandData GetDataPtr() { return (pServerCommandData)m_ServerCommandData.GetDataPtr(); } |
|
303 |
pServerMessageData GetMsgPtr() { return (pServerMessageData)m_ServerMessageData.GetDataPtr(); } |
|
304 |
||
305 |
private: |
|
306 |
// Server Commands/Responses |
|
307 |
BOOL WaitForServerCommandAccess() { return m_ServerCommandMutex.Wait(); }; |
|
308 |
BOOL ReleaseServerCommandAccess() { return m_ServerCommandMutex.Release(); }; |
|
309 |
// BOOL WaitForServerCommandAccess() { return TRUE; }; |
|
310 |
// BOOL ReleaseServerCommandAccess() { return TRUE; }; |
|
311 |
CServerCommandData m_ServerCommandData; |
|
312 |
CServerMessageData m_ServerMessageData; |
|
313 |
CServerProcessData m_ServerProcessData; |
|
314 |
||
315 |
Mutex m_ServerCommandMutex; |
|
316 |
Mutex m_ServerPipeMutex; |
|
317 |
||
318 |
// client |
|
319 |
void SetCommandReady(); |
|
320 |
// server |
|
321 |
void SetResponseReady(); |
|
322 |
HANDLE m_hServerCommandReadyEvent; |
|
323 |
HANDLE m_hServerResponseReadyEvent; |
|
324 |
}; |
|
325 |
||
326 |
#endif// __SERVERCLIENT_H__ |