author | fturovic <frank.turovich@nokia.com> |
Wed, 16 Jun 2010 11:39:35 -0500 | |
changeset 1475 | fb0e02cb252b |
parent 1473 | 6c45b7c9cdac |
child 1481 | c7f22cc57d44 |
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 |
// ConnectionImpl.cpp: implementation of the CConnectionImpl class. |
|
18 |
// |
|
19 |
////////////////////////////////////////////////////////////////////// |
|
20 |
||
21 |
#include "stdafx.h" |
|
22 |
#include "ConnectionImpl.h" |
|
23 |
#include "RegistryImpl.h" |
|
24 |
#include "ServerManager.h" |
|
25 |
||
26 |
#ifdef _DEBUG |
|
27 |
extern BOOL gDoLogging; |
|
28 |
#endif |
|
29 |
||
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
30 |
#define LOG_CONNECTION |
60 | 31 |
#if defined(LOG_CONNECTION) && defined(_DEBUG) |
32 |
#define TCDEBUGOPEN() if (gDoLogging) { this->m_DebugLog->WaitForAccess(); } |
|
33 |
#define TCDEBUGLOGS(s) if (gDoLogging) { sprintf(this->m_DebugLogMsg,"%s", s); this->m_DebugLog->log(this->m_DebugLogMsg); } |
|
34 |
#define TCDEBUGLOGA1(s, a1) if (gDoLogging) { sprintf(this->m_DebugLogMsg, s, a1); this->m_DebugLog->log(this->m_DebugLogMsg); } |
|
35 |
#define TCDEBUGLOGA2(s, a1, a2) if (gDoLogging) { sprintf(this->m_DebugLogMsg, s, a1, a2); this->m_DebugLog->log(this->m_DebugLogMsg); } |
|
36 |
#define TCDEBUGLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(this->m_DebugLogMsg, s, a1, a2, a3); this->m_DebugLog->log(this->m_DebugLogMsg); } |
|
37 |
#define TCDEBUGLOGA4(s, a1, a2, a3, a4) if (gDoLogging) { sprintf(this->m_DebugLogMsg, s, a1, a2, a3, a4); this->m_DebugLog->log(this->m_DebugLogMsg); } |
|
38 |
#define TCDEBUGCLOSE() if (gDoLogging) { this->m_DebugLog->ReleaseAccess(); } |
|
39 |
#else |
|
40 |
#define TCDEBUGOPEN() |
|
41 |
#define TCDEBUGLOGS(s) |
|
42 |
#define TCDEBUGLOGA1(s, a1) |
|
43 |
#define TCDEBUGLOGA2(s, a1, a2) |
|
44 |
#define TCDEBUGLOGA3(s, a1, a2, a3) |
|
45 |
#define TCDEBUGLOGA4(s, a1, a2, a3, a4) |
|
46 |
#define TCDEBUGCLOSE() |
|
47 |
#endif |
|
48 |
||
366 | 49 |
//#define LOG_MPROCESSOR |
50 |
||
60 | 51 |
////////////////////////////////////////////////////////////////////// |
52 |
// Construction/Destruction |
|
53 |
////////////////////////////////////////////////////////////////////// |
|
54 |
||
55 |
CConnectionImpl::CConnectionImpl() |
|
56 |
{ |
|
57 |
m_ConnectSettings = NULL; |
|
58 |
m_ClientList = NULL; |
|
59 |
m_Status = eDisconnected; |
|
60 |
m_Registry = NULL; |
|
61 |
m_ConnectionID = 0; |
|
62 |
m_OsError = 0; |
|
63 |
m_BaseComm = NULL; |
|
64 |
m_BaseProtocol = NULL; |
|
65 |
m_BaseCommHandle = NULL; |
|
66 |
m_BaseProtocolHandle = NULL; |
|
67 |
||
68 |
// message processing thread flags and handles |
|
69 |
m_MessageProcessorState = MP_NONE; |
|
70 |
m_ExitMessageProcessor = false; |
|
71 |
m_PauseMessageProcessing = false; |
|
72 |
m_StartMessageProcessing = false; |
|
73 |
m_hMessageProcessorExittedEvent = NULL; |
|
74 |
m_hMessageProcessorStoppedEvent = NULL; |
|
75 |
m_hMessageProcessorStartedEvent = NULL; |
|
76 |
m_hMessageProcessorThread = NULL; |
|
77 |
m_dwMessageProcessorThreadId = 0; |
|
78 |
||
79 |
m_NextRetryTime = m_RetryTimeoutTime = 0; |
|
80 |
||
81 |
m_NextFlushFileTime = 0; |
|
82 |
} |
|
83 |
||
84 |
CConnectionImpl::CConnectionImpl(ConnectData conData, DWORD connectionId) |
|
85 |
{ |
|
86 |
#ifdef _DEBUG |
|
87 |
if (gDoLogging) |
|
88 |
{ |
|
366 | 89 |
#if defined(LOG_CONNECTION) |
60 | 90 |
m_DebugLog = new TCDebugLog("TCF_ConnectionLog", connectionId); |
366 | 91 |
#else |
92 |
m_DebugLog = NULL; |
|
93 |
#endif |
|
94 |
#if defined(LOG_MPROCESSOR) |
|
60 | 95 |
m_DebugLog2 = new TCDebugLog("TCF_ProcessorLog", connectionId); |
366 | 96 |
#else |
97 |
m_DebugLog2 = NULL; |
|
98 |
#endif |
|
60 | 99 |
} |
100 |
else |
|
101 |
{ |
|
102 |
m_DebugLog = NULL; |
|
103 |
m_DebugLog2 = NULL; |
|
104 |
} |
|
105 |
#else |
|
106 |
m_DebugLog = NULL; |
|
107 |
m_DebugLog2 = NULL; |
|
108 |
#endif |
|
109 |
||
110 |
TCDEBUGOPEN(); |
|
111 |
TCDEBUGLOGA1("CConnectionImpl::CConnectionImpl id = %d\n", connectionId); |
|
112 |
||
113 |
m_ConnectSettings = new ConnectData(); |
|
114 |
||
115 |
memcpy(m_ConnectSettings, &conData, sizeof(ConnectData)); |
|
116 |
||
117 |
m_ClientList = new ClientList(); |
|
118 |
m_ClientList->clear(); |
|
119 |
m_Status = eDisconnected; |
|
120 |
m_Registry = new CRegistryImpl(connectionId); |
|
121 |
m_ConnectionID = connectionId; |
|
122 |
m_BaseComm = NULL; |
|
123 |
m_BaseProtocol = NULL; |
|
124 |
m_BaseCommHandle = NULL; |
|
125 |
m_BaseProtocolHandle = NULL; |
|
126 |
||
127 |
// message processing thread flags and handles |
|
128 |
m_MessageProcessorState = MP_NONE; |
|
129 |
m_ExitMessageProcessor = false; |
|
130 |
m_PauseMessageProcessing = false; |
|
131 |
m_StartMessageProcessing = false; |
|
132 |
||
133 |
// create named events |
|
134 |
char eventName[100]; |
|
135 |
||
136 |
sprintf(eventName, "%s%d", MESSAGEPROCESSOR_EXITEVENT_BASENAME, connectionId); |
|
137 |
m_hMessageProcessorExittedEvent = ::CreateEvent(NULL, FALSE, FALSE, eventName); |
|
138 |
||
139 |
sprintf(eventName, "%s%d", MESSAGEPROCESSOR_STOPEVENT_BASENAME, connectionId); |
|
140 |
m_hMessageProcessorStoppedEvent = ::CreateEvent(NULL, FALSE, FALSE, eventName); |
|
141 |
||
142 |
sprintf(eventName, "%s%d", MESSAGEPROCESSOR_STARTEVENT_BASENAME, connectionId); |
|
143 |
m_hMessageProcessorStartedEvent = ::CreateEvent(NULL, FALSE, FALSE, eventName); |
|
144 |
||
145 |
m_hMessageProcessorThread = NULL; |
|
146 |
m_dwMessageProcessorThreadId = 0; |
|
147 |
||
148 |
m_NextRetryTime = m_RetryTimeoutTime = 0; |
|
149 |
||
150 |
m_NextFlushFileTime = 0; |
|
151 |
m_OsError = 0; |
|
152 |
||
153 |
TCDEBUGCLOSE(); |
|
154 |
} |
|
155 |
CConnectionImpl::~CConnectionImpl() |
|
156 |
{ |
|
157 |
TCDEBUGOPEN(); |
|
158 |
TCDEBUGLOGS("CConnectionImpl::~CConnectionImpl\n"); |
|
159 |
||
160 |
// terminate the message processor thread if running |
|
161 |
||
162 |
if (m_hMessageProcessorThread != NULL) |
|
163 |
{ |
|
164 |
BOOL t = ::TerminateThread(m_hMessageProcessorThread, 0); |
|
165 |
::CloseHandle(m_hMessageProcessorThread); |
|
166 |
} |
|
167 |
||
168 |
if (m_hMessageProcessorExittedEvent != NULL) |
|
169 |
{ |
|
170 |
::CloseHandle(m_hMessageProcessorExittedEvent); |
|
171 |
} |
|
172 |
||
173 |
if (m_hMessageProcessorStoppedEvent != NULL) |
|
174 |
{ |
|
175 |
::CloseHandle(m_hMessageProcessorStoppedEvent); |
|
176 |
} |
|
177 |
||
1215
657de0649d83
fix event leak bug 11107
Chad Peckham <chad.peckham@nokia.com>
parents:
366
diff
changeset
|
178 |
if (m_hMessageProcessorStartedEvent != NULL) |
657de0649d83
fix event leak bug 11107
Chad Peckham <chad.peckham@nokia.com>
parents:
366
diff
changeset
|
179 |
{ |
657de0649d83
fix event leak bug 11107
Chad Peckham <chad.peckham@nokia.com>
parents:
366
diff
changeset
|
180 |
::CloseHandle(m_hMessageProcessorStartedEvent); |
657de0649d83
fix event leak bug 11107
Chad Peckham <chad.peckham@nokia.com>
parents:
366
diff
changeset
|
181 |
} |
657de0649d83
fix event leak bug 11107
Chad Peckham <chad.peckham@nokia.com>
parents:
366
diff
changeset
|
182 |
|
60 | 183 |
if (m_ConnectSettings) |
184 |
delete m_ConnectSettings; |
|
185 |
||
186 |
||
187 |
if (m_ClientList) |
|
188 |
{ |
|
189 |
m_ClientList->clear(); |
|
190 |
delete m_ClientList; |
|
191 |
} |
|
192 |
||
193 |
if (m_Registry) |
|
194 |
{ |
|
195 |
delete m_Registry; |
|
196 |
} |
|
197 |
||
198 |
if (m_BaseComm) |
|
199 |
{ |
|
200 |
delete m_BaseComm; |
|
201 |
} |
|
202 |
||
203 |
if (m_BaseCommHandle) |
|
204 |
{ |
|
205 |
::FreeLibrary(m_BaseCommHandle); |
|
206 |
} |
|
207 |
if (m_BaseProtocol) |
|
208 |
{ |
|
209 |
delete m_BaseProtocol; |
|
210 |
} |
|
211 |
||
212 |
if (m_BaseProtocolHandle) |
|
213 |
{ |
|
214 |
::FreeLibrary(m_BaseProtocolHandle); |
|
215 |
} |
|
216 |
||
217 |
TCDEBUGCLOSE(); |
|
218 |
if (m_DebugLog) |
|
219 |
delete m_DebugLog; |
|
220 |
if (m_DebugLog2) |
|
221 |
delete m_DebugLog2; |
|
222 |
||
223 |
} |
|
224 |
||
225 |
BOOL CConnectionImpl::IsEqual(CConnection* connection) |
|
226 |
{ |
|
227 |
TCDEBUGOPEN(); |
|
228 |
TCDEBUGLOGS("CConnectionImpl::IsEqual\n"); |
|
229 |
||
230 |
BOOL equal = FALSE; |
|
231 |
||
232 |
if (strcmp(m_ConnectSettings->connectType, connection->m_ConnectSettings->connectType) == 0) |
|
233 |
{ |
|
234 |
if (m_BaseComm) |
|
235 |
{ |
|
236 |
if (m_BaseComm->IsConnectionEqual(connection->m_ConnectSettings)) |
|
237 |
{ |
|
238 |
equal = TRUE; |
|
239 |
} |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
equal = TRUE; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
TCDEBUGCLOSE(); |
|
248 |
return equal; |
|
249 |
} |
|
250 |
||
251 |
BOOL CConnectionImpl::IsEqual(pConnectData pConData) |
|
252 |
{ |
|
253 |
TCDEBUGOPEN(); |
|
254 |
TCDEBUGLOGS("CConnectionImpl::IsEqual\n"); |
|
255 |
||
256 |
BOOL equal = FALSE; |
|
257 |
||
258 |
if (strcmp(m_ConnectSettings->connectType, pConData->connectType) == 0) |
|
259 |
{ |
|
260 |
if (m_BaseComm) |
|
261 |
{ |
|
262 |
if (m_BaseComm->IsConnectionEqual(pConData)) |
|
263 |
{ |
|
264 |
equal = TRUE; |
|
265 |
} |
|
266 |
} |
|
267 |
else |
|
268 |
{ |
|
269 |
equal = TRUE; |
|
270 |
} |
|
271 |
} |
|
272 |
TCDEBUGCLOSE(); |
|
273 |
return equal; |
|
274 |
} |
|
275 |
||
276 |
long CConnectionImpl::DoConnect() |
|
277 |
{ |
|
278 |
TCDEBUGOPEN(); |
|
279 |
TCDEBUGLOGS("CConnectionImpl::DoConnect\n"); |
|
280 |
||
281 |
long ret = TCAPI_ERR_NONE; |
|
282 |
||
283 |
if (m_BaseComm && m_BaseProtocol) |
|
284 |
{ |
|
285 |
ret = m_BaseComm->OpenPort(); |
|
286 |
if (ret != TCAPI_ERR_NONE) |
|
287 |
{ |
|
288 |
m_OsError = m_BaseComm->m_lastCommError; |
|
289 |
TCDEBUGLOGA1(" m_BaseComm->OpenPort = %d\n", ret); |
|
290 |
} |
|
291 |
} |
|
292 |
else |
|
293 |
{ |
|
294 |
ret = TCAPI_ERR_UNKNOWN_MEDIA_TYPE; |
|
295 |
} |
|
296 |
||
297 |
if (ret == TCAPI_ERR_NONE) |
|
298 |
{ |
|
299 |
m_Status = eConnected; |
|
300 |
||
301 |
TCDEBUGCLOSE(); |
|
302 |
||
303 |
StartProcessing(); |
|
304 |
} |
|
305 |
else |
|
306 |
{ |
|
307 |
// if (m_BaseComm != NULL) |
|
308 |
// { |
|
309 |
// delete m_BaseComm; |
|
310 |
// m_BaseComm = NULL; |
|
311 |
// } |
|
312 |
TCDEBUGCLOSE(); |
|
313 |
} |
|
314 |
return ret; |
|
315 |
} |
|
316 |
||
317 |
long CConnectionImpl::DoDisconnect() |
|
318 |
{ |
|
319 |
TCDEBUGOPEN(); |
|
320 |
TCDEBUGLOGS("CConnectionImpl::DoDisconnect\n"); |
|
321 |
||
322 |
long ret = TCAPI_ERR_NONE; |
|
323 |
if (IsConnected()) |
|
324 |
{ |
|
325 |
ret = m_BaseComm->ClosePort(); |
|
326 |
// delete m_BaseComm; |
|
327 |
// m_BaseComm = NULL; |
|
328 |
} |
|
329 |
m_Status = eDisconnected; |
|
330 |
||
331 |
TCDEBUGCLOSE(); |
|
332 |
return ret; |
|
333 |
} |
|
334 |
||
335 |
BOOL CConnectionImpl::AddClient(CClient* client) |
|
336 |
{ |
|
337 |
TCDEBUGOPEN(); |
|
338 |
TCDEBUGLOGS("CConnectionImpl::AddClient\n"); |
|
339 |
||
340 |
BOOL ok = TRUE; |
|
341 |
||
342 |
m_ClientList->push_back(client); |
|
343 |
||
344 |
TCDEBUGCLOSE(); |
|
345 |
return ok; |
|
346 |
} |
|
347 |
||
348 |
long CConnectionImpl::DoSendMessage(long encodeOption, BYTE protocolVersion, BOOL useMsgId, BYTE msgId, DWORD msgLength, BYTE* pMsg) |
|
349 |
{ |
|
350 |
TCDEBUGOPEN(); |
|
351 |
TCDEBUGLOGS("CConnectionImpl::DoSendMessage\n"); |
|
352 |
||
353 |
long err = TCAPI_ERR_NONE; |
|
354 |
if (IsRetryInProgress()) |
|
355 |
{ |
|
356 |
err = TCAPI_ERR_COMM_RETRY_IN_PROGRESS; |
|
357 |
} |
|
358 |
else if (IsRetryTimedOut()) |
|
359 |
{ |
|
360 |
err = TCAPI_ERR_COMM_TIMEOUT; |
|
361 |
} |
|
362 |
else if (m_Status == eConnected) |
|
363 |
{ |
|
364 |
BYTE* encodedMessage = new BYTE[msgLength + 40]; // add enough for header (msgLength may be 0) |
|
365 |
// if msgLength == 0, then encodeOption SHOULD be ENCODE_FORMAT since com expects to send something! |
|
366 |
if (encodeOption == ENCODE_FORMAT) |
|
367 |
{ |
|
368 |
#ifdef _DEBUG |
|
369 |
char msg[200]; msg[0] = '\0'; |
|
370 |
int len = (msgLength > 30) ? 30 : msgLength; |
|
371 |
for (int i = 0; i < len; i ++) |
|
372 |
{ |
|
373 |
sprintf(msg, "%s%02.2x ", msg, pMsg[i]); |
|
374 |
} |
|
375 |
sprintf(msg, "%s\n", msg); |
|
376 |
TCDEBUGLOGS(msg); |
|
377 |
#endif |
|
378 |
// msgLength maybe 0 and pMsg maybe NULL (we're not sending a raw message, just a protocol header) |
|
379 |
msgLength = m_BaseProtocol->EncodeMessage(pMsg, msgLength, protocolVersion, msgId, encodedMessage, msgLength+40); |
|
380 |
#ifdef _DEBUG |
|
381 |
msg[0] = '\0'; |
|
382 |
len = (msgLength > 30) ? 30 : msgLength; |
|
383 |
for (i = 0; i < len; i ++) |
|
384 |
{ |
|
385 |
sprintf(msg, "%s%02.2x ", msg, encodedMessage[i]); |
|
386 |
} |
|
387 |
sprintf(msg, "%s\n", msg); |
|
388 |
TCDEBUGLOGS(msg); |
|
389 |
#endif |
|
390 |
err = m_BaseComm->SendDataToPort(msgLength, encodedMessage); |
|
391 |
} |
|
392 |
else |
|
393 |
{ |
|
394 |
#ifdef _DEBUG |
|
395 |
char msg[200]; msg[0] = '\0'; |
|
396 |
int len = (msgLength > 30) ? 30 : msgLength; |
|
397 |
for (int i = 0; i < len; i ++) |
|
398 |
{ |
|
399 |
sprintf(msg, "%s%02.2x ", msg, pMsg[i]); |
|
400 |
} |
|
401 |
sprintf(msg, "%s\n", msg); |
|
402 |
TCDEBUGLOGS(msg); |
|
403 |
#endif |
|
404 |
// msgLength != 0 and pMsg != NULL |
|
405 |
err = m_BaseComm->SendDataToPort(msgLength, pMsg); |
|
406 |
} |
|
407 |
delete[] encodedMessage; |
|
408 |
||
409 |
TCDEBUGLOGS("CConnectionImpl::DoSendMessage done\n"); |
|
410 |
if (err == TCAPI_ERR_COMM_ERROR) |
|
411 |
{ |
|
366 | 412 |
// EnterRetryPeriod(err, true, m_BaseComm->m_lastCommError); |
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
413 |
HandleFatalPortError(err, true, m_BaseComm->m_lastCommError); |
60 | 414 |
m_OsError = m_BaseComm->m_lastCommError; |
415 |
} |
|
416 |
} |
|
417 |
else |
|
418 |
{ |
|
419 |
err = TCAPI_ERR_MEDIA_NOT_OPEN; |
|
420 |
} |
|
421 |
||
422 |
TCDEBUGLOGA1("CConnectionImpl::DoSendMessage err = %d\n", err); |
|
423 |
TCDEBUGCLOSE(); |
|
424 |
return err; |
|
425 |
} |
|
426 |
||
427 |
long CConnectionImpl::DoRetryProcessing() |
|
428 |
{ |
|
429 |
long err = TCAPI_ERR_NONE; |
|
430 |
||
431 |
// if not connected |
|
432 |
// return no error |
|
433 |
if (m_BaseComm == NULL /*|| m_BaseComm->IsConnected() == false*/) |
|
434 |
return TCAPI_ERR_MEDIA_NOT_OPEN; |
|
435 |
||
436 |
// if retry not in progress && retry not timed out |
|
437 |
// return no error |
|
438 |
if (!IsRetryInProgress() && !IsRetryTimedOut()) |
|
439 |
return TCAPI_ERR_NONE; |
|
440 |
||
441 |
// TCDEBUGOPEN(); |
|
442 |
// TCDEBUGLOGS("CConnectionImpl::DoRetryProcessing\n"); |
|
443 |
// TCDEBUGCLOSE(); |
|
444 |
// if retry timeout flag already set |
|
445 |
// return timeout error |
|
446 |
if (IsRetryTimedOut()) |
|
447 |
return TCAPI_ERR_COMM_TIMEOUT; |
|
448 |
||
449 |
// get current time |
|
450 |
time_t ctime; |
|
451 |
time(&ctime); |
|
452 |
// if retry timeout period has expired |
|
453 |
if (ctime >= m_RetryTimeoutTime) |
|
454 |
{ |
|
455 |
TCDEBUGOPEN(); |
|
456 |
TCDEBUGLOGS("CConnectionImpl::DoRetryProcessing retry timeout\n"); |
|
457 |
TCDEBUGCLOSE(); |
|
458 |
// send timeout error to all clients |
|
459 |
NotifyClientsCommError(TCAPI_ERR_COMM_TIMEOUT); |
|
460 |
// close comm port |
|
461 |
m_BaseComm->ClosePort(); |
|
462 |
// set retry timeout flag |
|
463 |
SetRetryTimedOut(); |
|
464 |
// return retry timeout error |
|
465 |
err = TCAPI_ERR_COMM_TIMEOUT; |
|
466 |
} |
|
467 |
// else if retry time has passed |
|
468 |
else if (ctime >= m_NextRetryTime) |
|
469 |
{ |
|
470 |
TCDEBUGOPEN(); |
|
471 |
TCDEBUGLOGS("CConnectionImpl::DoRetryProcessing retry time\n"); |
|
472 |
TCDEBUGCLOSE(); |
|
473 |
// close comm port |
|
474 |
// reopen comm port |
|
475 |
m_BaseComm->ClosePort(); |
|
476 |
int openErr = m_BaseComm->OpenPort(); |
|
477 |
// if comm error |
|
478 |
if (openErr != TCAPI_ERR_NONE) |
|
479 |
{ |
|
480 |
// set next retry time |
|
481 |
// return comm error |
|
482 |
m_NextRetryTime = ctime + m_ConnectSettings->retryInterval; |
|
483 |
err = TCAPI_ERR_COMM_RETRY_IN_PROGRESS; |
|
484 |
m_OsError = m_BaseComm->m_lastCommError; |
|
485 |
} |
|
486 |
else |
|
487 |
{ |
|
488 |
TCDEBUGOPEN(); |
|
489 |
TCDEBUGLOGS("CConnectionImpl::DoRetryProcessing reconnected\n"); |
|
490 |
TCDEBUGCLOSE(); |
|
491 |
// send reconnect warning to all clients |
|
492 |
NotifyClientsCommError(TCAPI_INFO_COMM_RECONNECTED); |
|
493 |
// set connected |
|
494 |
SetConnected(); |
|
495 |
err = TCAPI_ERR_NONE; |
|
496 |
} |
|
497 |
} |
|
498 |
else // still in retry |
|
499 |
{ |
|
500 |
err = TCAPI_ERR_COMM_RETRY_IN_PROGRESS; |
|
501 |
} |
|
502 |
||
503 |
||
504 |
// TCDEBUGOPEN(); |
|
505 |
// TCDEBUGLOGA1("CConnectionImpl::DoRetryProcessing err = %d\n", err); |
|
506 |
// TCDEBUGCLOSE(); |
|
507 |
return err; |
|
508 |
} |
|
509 |
long CConnectionImpl::EnterRetryPeriod(long commErr, bool passOsErr, DWORD osErr) |
|
510 |
{ |
|
511 |
TCDEBUGOPEN(); |
|
366 | 512 |
TCDEBUGLOGA3("CConnectionImpl::EnterRetryPeriod commErr=%d passOsErr=%d osErr=%d\n", commErr, passOsErr, osErr); |
60 | 513 |
TCDEBUGCLOSE(); |
514 |
||
515 |
long err = TCAPI_ERR_NONE; |
|
516 |
||
517 |
// set next retry time |
|
518 |
time_t ctime; |
|
519 |
time(&ctime); |
|
520 |
m_NextRetryTime = ctime + m_ConnectSettings->retryInterval; |
|
521 |
// set retry timeout time |
|
522 |
m_RetryTimeoutTime = ctime + m_ConnectSettings->retryTimeout; |
|
523 |
// send comm error to all clients |
|
524 |
NotifyClientsCommError(commErr, passOsErr, osErr); |
|
525 |
// set retry in progress flag |
|
526 |
SetRetryInProgress(); |
|
527 |
||
528 |
return err; |
|
529 |
} |
|
530 |
||
531 |
BOOL CConnectionImpl::RemoveClient(CClient* client) |
|
532 |
{ |
|
533 |
TCDEBUGOPEN(); |
|
534 |
TCDEBUGLOGS("CConnectionImpl::RemoveClient\n"); |
|
535 |
||
536 |
BOOL found = FALSE; |
|
537 |
||
538 |
if (m_ClientList->size() != 0) |
|
539 |
{ |
|
540 |
ClientList::iterator iter; |
|
541 |
for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++) |
|
542 |
{ |
|
543 |
if ((*iter)->GetClientId() == client->GetClientId()) |
|
544 |
{ |
|
545 |
m_ClientList->erase(iter); |
|
546 |
found = TRUE; |
|
547 |
break; |
|
548 |
} |
|
549 |
} |
|
550 |
} |
|
551 |
||
552 |
TCDEBUGCLOSE(); |
|
553 |
return found; |
|
554 |
} |
|
555 |
||
556 |
BOOL CConnectionImpl::ExitProcessing() |
|
557 |
{ |
|
558 |
TCDEBUGOPEN(); |
|
559 |
TCDEBUGLOGS("CConnectionImpl::ExitProcessing\n"); |
|
560 |
||
561 |
// exit the messageprocessing thread |
|
562 |
if (m_hMessageProcessorThread != NULL) |
|
563 |
{ |
|
564 |
m_MessageProcessorState = MP_EXIT; |
|
565 |
||
566 |
m_StartMessageProcessing = false; |
|
567 |
m_PauseMessageProcessing = true; |
|
568 |
m_ExitMessageProcessor = true; |
|
569 |
DWORD waitStatus = ::WaitForSingleObject(m_hMessageProcessorExittedEvent, MESSAGEPROCESSOR_EVENTWAIT_TIMEOUT); |
|
570 |
TCDEBUGLOGA1("CConnectionImpl::ExitProcessing waitStatus=%x\n", waitStatus); |
|
571 |
::CloseHandle(m_hMessageProcessorThread); |
|
572 |
m_hMessageProcessorThread = NULL; |
|
573 |
} |
|
574 |
||
575 |
TCDEBUGCLOSE(); |
|
576 |
return TRUE; |
|
577 |
} |
|
578 |
||
579 |
BOOL CConnectionImpl::StartProcessing() |
|
580 |
{ |
|
581 |
TCDEBUGOPEN(); |
|
582 |
TCDEBUGLOGS("CConnectionImpl::StartProcessing\n"); |
|
583 |
||
584 |
// starts processing thread |
|
585 |
if (m_hMessageProcessorThread == NULL) |
|
586 |
{ |
|
587 |
m_MessageProcessorState = MP_PAUSE; |
|
588 |
||
589 |
m_ExitMessageProcessor = false; |
|
590 |
m_StartMessageProcessing = false; |
|
591 |
m_PauseMessageProcessing = false; |
|
592 |
// TODO: create thread |
|
593 |
m_hMessageProcessorThread = ::CreateThread( |
|
594 |
NULL, |
|
595 |
0, |
|
596 |
(LPTHREAD_START_ROUTINE) MessageProcessor, |
|
597 |
this, |
|
598 |
0, |
|
599 |
&m_dwMessageProcessorThreadId); |
|
600 |
} |
|
601 |
||
602 |
TCDEBUGCLOSE(); |
|
603 |
return PauseProcessing();//RestartProcessing(); |
|
604 |
} |
|
605 |
||
606 |
BOOL CConnectionImpl::PauseProcessing() |
|
607 |
{ |
|
608 |
TCDEBUGOPEN(); |
|
609 |
TCDEBUGLOGS("CConnectionImpl::PauseProcessing\n"); |
|
610 |
||
611 |
// tells the processing thread to pause |
|
612 |
if (m_hMessageProcessorThread != NULL) |
|
613 |
{ |
|
614 |
m_MessageProcessorState = MP_PAUSE; |
|
615 |
||
616 |
m_ExitMessageProcessor = false; |
|
617 |
m_StartMessageProcessing = false; |
|
618 |
m_PauseMessageProcessing = true; |
|
619 |
DWORD waitStatus = ::WaitForSingleObject(m_hMessageProcessorStoppedEvent, MESSAGEPROCESSOR_EVENTWAIT_TIMEOUT); |
|
620 |
TCDEBUGLOGA1("CConnectionImpl::PauseProcessing waitStatus=%x\n", waitStatus); |
|
621 |
} |
|
622 |
||
623 |
TCDEBUGCLOSE(); |
|
624 |
return TRUE; |
|
625 |
} |
|
626 |
||
627 |
BOOL CConnectionImpl::RestartProcessing() |
|
628 |
{ |
|
629 |
TCDEBUGOPEN(); |
|
630 |
TCDEBUGLOGS("CConnectionImpl::RestartProcessing\n"); |
|
631 |
||
632 |
// tell the processing thread to restart |
|
633 |
if (m_hMessageProcessorThread != NULL) |
|
634 |
{ |
|
635 |
m_MessageProcessorState = MP_START; |
|
636 |
||
637 |
m_ExitMessageProcessor = false; |
|
638 |
m_StartMessageProcessing = true; |
|
639 |
m_PauseMessageProcessing = false; |
|
640 |
DWORD waitStatus = ::WaitForSingleObject(m_hMessageProcessorStartedEvent, MESSAGEPROCESSOR_EVENTWAIT_TIMEOUT); |
|
641 |
TCDEBUGLOGA1("CConnectionImpl::RestartProcessing waitStatus=%x\n", waitStatus); |
|
642 |
} |
|
643 |
||
644 |
TCDEBUGCLOSE(); |
|
645 |
return TRUE; |
|
646 |
} |
|
647 |
||
648 |
BOOL CConnectionImpl::RemoveClientFromRegistry(CClient* client) |
|
649 |
{ |
|
650 |
TCDEBUGOPEN(); |
|
651 |
TCDEBUGLOGS("CConnectionImpl::RemoveClientFromRegistry\n"); |
|
652 |
TCDEBUGCLOSE(); |
|
653 |
||
654 |
return m_Registry->RemoveClient(client); |
|
655 |
} |
|
656 |
||
657 |
BOOL CConnectionImpl::AddClientToRegistry(CClient* client, long numberIds, BYTE* ids) |
|
658 |
{ |
|
659 |
TCDEBUGOPEN(); |
|
660 |
TCDEBUGLOGS("CConnectionImpl::AddClientToRegistry\n"); |
|
661 |
TCDEBUGCLOSE(); |
|
662 |
||
663 |
return m_Registry->AddClient(client, numberIds, ids); |
|
664 |
} |
|
665 |
||
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
666 |
long CConnectionImpl::HandleFatalPortError(long err, bool passOsErr, DWORD osErr) |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
667 |
{ |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
668 |
TCDEBUGOPEN(); |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
669 |
TCDEBUGLOGA3("CConnectionImpl::HandleFatalPortError err=%d passOsErr=%d osErr=%d\n", err, passOsErr, osErr); |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
670 |
TCDEBUGCLOSE(); |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
671 |
|
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
672 |
m_BaseComm->ClosePort(); |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
673 |
m_Status = eDisconnected; |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
674 |
|
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
675 |
NotifyClientsCommError(err); |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
676 |
|
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
677 |
return TCAPI_ERR_NONE; |
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
678 |
} |
60 | 679 |
void CConnectionImpl::NotifyClientsCommError(long tcfError, bool passOsError, DWORD osError) |
680 |
{ |
|
681 |
// TCDEBUGOPEN(); |
|
682 |
// TCDEBUGLOGS("CConnectionImpl::NotifyClientsCommError\n"); |
|
683 |
// TCDEBUGCLOSE(); |
|
684 |
||
685 |
if (m_ClientList->size() != 0) |
|
686 |
{ |
|
687 |
ClientList::iterator iter; |
|
688 |
for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++) |
|
689 |
{ |
|
690 |
CErrorMonitor* errorMonitor = (*iter)->m_ErrorMonitor; |
|
691 |
errorMonitor->PutError(tcfError, passOsError, osError); |
|
692 |
} |
|
693 |
} |
|
694 |
} |
|
695 |
BOOL CConnectionImpl::HasVersion() |
|
696 |
{ |
|
697 |
BOOL found = FALSE; |
|
698 |
||
699 |
if (m_BaseComm && m_BaseComm->HasVersion()) |
|
700 |
found = TRUE; |
|
701 |
||
702 |
return found; |
|
703 |
} |
|
704 |
void CConnectionImpl::GetVersion(char* version) |
|
705 |
{ |
|
706 |
if (HasVersion()) { |
|
707 |
m_BaseComm->GetVersion(version); |
|
708 |
} |
|
709 |
} |
|
710 |
||
711 |
void CConnectionImpl::UnLockAllDestinations() |
|
712 |
{ |
|
713 |
if (m_ClientList->size() != 0) |
|
714 |
{ |
|
715 |
ClientList::iterator iter; |
|
716 |
for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++) |
|
717 |
{ |
|
718 |
CInputStream* inputStream = (*iter)->m_InputStream; |
|
719 |
CMessageFile* file = (*iter)->m_MessageFile; |
|
720 |
if (inputStream != NULL) |
|
721 |
{ |
|
722 |
inputStream->UnLockStream(); |
|
723 |
} |
|
724 |
else if (file != NULL) |
|
725 |
{ |
|
726 |
file->UnLockMessageFile(); |
|
727 |
} |
|
728 |
} |
|
729 |
} |
|
730 |
} |
|
731 |
||
732 |
#if defined(LOG_MPROCESSOR) && defined(_DEBUG) |
|
733 |
#define MPLOGOPEN() if (gDoLogging) { pThis->m_DebugLog2->WaitForAccess(); } |
|
734 |
#define MPLOGS(s) if (gDoLogging) { sprintf(pThis->m_DebugLogMsg2,"%s", s); pThis->m_DebugLog2->log(pThis->m_DebugLogMsg2); } |
|
735 |
#define MPLOGA1(s, a1) if (gDoLogging) { sprintf(pThis->m_DebugLogMsg2, s, a1); pThis->m_DebugLog2->log(pThis->m_DebugLogMsg2); } |
|
736 |
#define MPLOGA2(s, a1, a2) if (gDoLogging) { sprintf(pThis->m_DebugLogMsg2, s, a1, a2); pThis->m_DebugLog2->log(pThis->m_DebugLogMsg2); } |
|
737 |
#define MPLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(pThis->m_DebugLogMsg2, s, a1, a2, a3); pThis->m_DebugLog2->log(pThis->m_DebugLogMsg2); } |
|
738 |
#define MPLOGCLOSE() if (gDoLogging) { pThis->m_DebugLog2->ReleaseAccess(); } |
|
739 |
#else |
|
740 |
#define MPLOGOPEN() |
|
741 |
#define MPLOGS(s) |
|
742 |
#define MPLOGA1(s, a1) |
|
743 |
#define MPLOGA2(s, a1, a2) |
|
744 |
#define MPLOGA3(s, a1, a2, a3) |
|
745 |
#define MPLOGCLOSE() |
|
746 |
#endif |
|
747 |
||
748 |
DWORD WINAPI CConnectionImpl::MessageProcessor(LPVOID lpParam) |
|
749 |
{ |
|
750 |
CConnectionImpl* pThis = (CConnectionImpl*)lpParam; |
|
751 |
||
752 |
MPLOGOPEN(); |
|
753 |
MPLOGS("MessageProcessor start thread\n"); |
|
754 |
||
755 |
bool processing = false; |
|
756 |
long err = TCAPI_ERR_NONE; |
|
757 |
DWORD pollSize = 0; |
|
758 |
||
759 |
while (pThis->m_MessageProcessorState != MP_EXIT) |
|
760 |
{ |
|
761 |
if (pThis->m_MessageProcessorState == MP_PAUSE) |
|
762 |
{ |
|
763 |
MPLOGS("MessageProcessor pause\n"); |
|
764 |
||
765 |
processing = false; |
|
766 |
pThis->m_PauseMessageProcessing = false; |
|
767 |
pThis->m_MessageProcessorState = MP_NONE; |
|
768 |
BOOL ok = ::SetEvent(pThis->m_hMessageProcessorStoppedEvent); |
|
769 |
} |
|
770 |
||
771 |
if (pThis->IsRetryInProgress()) |
|
772 |
err = pThis->DoRetryProcessing(); |
|
773 |
else if (pThis->IsRetryTimedOut()) |
|
774 |
err = TCAPI_ERR_COMM_TIMEOUT; |
|
775 |
||
776 |
if (processing && err == TCAPI_ERR_NONE) |
|
777 |
{ |
|
778 |
if (pThis->m_BaseComm && pThis->m_BaseComm->IsConnected()) |
|
779 |
{ |
|
780 |
err = pThis->m_BaseComm->PollPort(pollSize); |
|
781 |
MPLOGA2("MessageProcessor PollPort = %d pollsize = %d\n", err, pollSize); |
|
782 |
if (err != TCAPI_ERR_NONE) |
|
783 |
{ |
|
784 |
MPLOGA2("MessageProcessor err = %d osError = %d\n", err, pThis->m_BaseComm->m_lastCommError); |
|
366 | 785 |
// pThis->EnterRetryPeriod(err, true, pThis->m_BaseComm->m_lastCommError); |
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
786 |
pThis->HandleFatalPortError(err, true, pThis->m_BaseComm->m_lastCommError); |
60 | 787 |
} |
788 |
else |
|
789 |
{ |
|
790 |
if (pollSize == 0) |
|
791 |
{ |
|
792 |
Sleep(1); |
|
793 |
} |
|
794 |
else |
|
795 |
{ |
|
796 |
long numberProcessed = 0; |
|
797 |
// MPLOGA1("MessageProcessor ProcessBuffer pRegistry = %x\n", pThis->m_Registry); |
|
798 |
err = pThis->m_BaseComm->ProcessBuffer(pThis, pThis->m_Registry, numberProcessed); |
|
799 |
||
800 |
MPLOGA2("MessageProcessor ProcessBuffer err = %d number = %d\n", err, numberProcessed); |
|
801 |
||
802 |
if (err == TCAPI_ERR_COMM_ERROR) |
|
803 |
{ |
|
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
804 |
MPLOGA2("MessageProcessor err = %d osError = %d\n", err, pThis->m_BaseComm->m_lastCommError); |
60 | 805 |
// for this error we have os error, but we probably caught this in PollPort already |
366 | 806 |
// pThis->EnterRetryPeriod(err, true, pThis->m_BaseComm->m_lastCommError); |
1473
6c45b7c9cdac
Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents:
1215
diff
changeset
|
807 |
pThis->HandleFatalPortError(err, true, pThis->m_BaseComm->m_lastCommError); |
60 | 808 |
} |
809 |
else if (err != TCAPI_ERR_NONE) |
|
810 |
{ |
|
811 |
// all clients already notified in ProcessBuffer |
|
812 |
err = TCAPI_ERR_NONE; |
|
813 |
} |
|
814 |
pThis->UnLockAllDestinations(); // unlock all input streams, if they became locked during AddMessage() |
|
815 |
// Sleep(1); |
|
816 |
} |
|
817 |
} |
|
818 |
// MPLOGS("MessageProcessor FlushAllClientMessageFiles\n"); |
|
819 |
pThis->FlushAllClientMessageFiles(); |
|
820 |
} |
|
821 |
else |
|
822 |
{ |
|
823 |
// basecom not connected |
|
824 |
Sleep(1); |
|
825 |
} |
|
826 |
} |
|
827 |
else |
|
828 |
{ |
|
829 |
// processing is not being done |
|
830 |
Sleep(1); |
|
831 |
} |
|
832 |
if (pThis->m_MessageProcessorState == MP_START) |
|
833 |
{ |
|
834 |
MPLOGS("MessageProcessor start\n"); |
|
835 |
||
836 |
processing = true; |
|
837 |
pThis->m_StartMessageProcessing = false; |
|
838 |
pThis->m_MessageProcessorState = MP_PROCESSING; |
|
839 |
BOOL ok = ::SetEvent(pThis->m_hMessageProcessorStartedEvent); |
|
840 |
} |
|
841 |
} |
|
842 |
// signal we're stopping |
|
843 |
pThis->m_ExitMessageProcessor = false; |
|
844 |
pThis->m_MessageProcessorState = MP_NONE; |
|
845 |
::SetEvent(pThis->m_hMessageProcessorExittedEvent); |
|
846 |
||
847 |
MPLOGS("MessageProcessor exit thread\n"); |
|
848 |
MPLOGCLOSE(); |
|
849 |
||
850 |
return 0; |
|
851 |
} |
|
852 |
||
853 |
void CConnectionImpl::FlushAllClientMessageFiles() |
|
854 |
{ |
|
855 |
DWORD cTick = GetTickCount(); |
|
856 |
||
857 |
// MPLOGA2("CConnectionImpl::FlushAllClientMessageFiles cTick=%d m_NextFlushFileTime=%d\n", cTick, m_NextFlushFileTime); |
|
858 |
||
859 |
if (cTick > m_NextFlushFileTime) |
|
860 |
{ |
|
861 |
// MPLOGS("CConnectionImpl::FlushAllClientMessageFiles flush timeout\n"); |
|
862 |
if (m_ClientList->size() != 0) |
|
863 |
{ |
|
864 |
ClientList::iterator iter; |
|
865 |
for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++) |
|
866 |
{ |
|
867 |
CMessageFile* file = (*iter)->m_MessageFile; |
|
868 |
if (file != NULL) |
|
869 |
{ |
|
870 |
// MPLOGS("CConnectionImpl::FlushAllClientMessageFiles flush client\n"); |
|
871 |
file->FlushFile(); |
|
872 |
} |
|
873 |
} |
|
874 |
} |
|
875 |
m_NextFlushFileTime = GetTickCount() + FLUSH_TIME; |
|
876 |
} |
|
877 |
} |
|
878 |
||
879 |
BOOL CConnectionImpl::CreateCommProtocols(const char* commPath, const char* protPath) |
|
880 |
{ |
|
881 |
BOOL loaded = FALSE; |
|
882 |
||
883 |
TCDEBUGOPEN(); |
|
884 |
TCDEBUGLOGS("CConnectionImpl::CreateCommProtocols\n"); |
|
885 |
||
886 |
TCDEBUGLOGA2(" commPath=%s protPath=%s\n", commPath, protPath); |
|
887 |
||
888 |
m_BaseCommHandle = ::LoadLibrary(commPath); |
|
889 |
m_BaseProtocolHandle = ::LoadLibrary(protPath); |
|
890 |
if (m_BaseCommHandle == NULL || m_BaseProtocolHandle == NULL) |
|
891 |
{ |
|
892 |
TCDEBUGLOGA2(" error loading library, m_BaseCommHandle=%x m_BaseProtocolHandle=%x\n", m_BaseCommHandle, m_BaseProtocolHandle); |
|
893 |
if (m_BaseCommHandle) ::FreeLibrary(m_BaseCommHandle); m_BaseCommHandle = NULL; |
|
894 |
if (m_BaseProtocolHandle) ::FreeLibrary(m_BaseProtocolHandle); m_BaseProtocolHandle = NULL; |
|
895 |
||
896 |
} |
|
897 |
else |
|
898 |
{ |
|
899 |
COMMCREATE lpCommFn = (COMMCREATE)::GetProcAddress(m_BaseCommHandle, COMMCREATE_FNNAME); |
|
900 |
PROTOCOLCREATE lpProtFn = (PROTOCOLCREATE)::GetProcAddress(m_BaseProtocolHandle, PROTOCOLCREATE_FNNAME); |
|
901 |
if (lpCommFn == NULL || lpProtFn == NULL) |
|
902 |
{ |
|
903 |
TCDEBUGLOGA2(" error finding function, lpCommFn=%x lpProtFn=%x\n", lpCommFn, lpProtFn); |
|
904 |
if (m_BaseCommHandle) ::FreeLibrary(m_BaseCommHandle); m_BaseCommHandle = NULL; |
|
905 |
if (m_BaseProtocolHandle) ::FreeLibrary(m_BaseProtocolHandle); m_BaseProtocolHandle = NULL; |
|
906 |
} |
|
907 |
else |
|
908 |
{ |
|
909 |
m_BaseProtocol = lpProtFn(); |
|
910 |
if (m_BaseProtocol == NULL) |
|
911 |
{ |
|
912 |
TCDEBUGLOGA1(" error creating protocol, m_BaseProtocol=%x\n", m_BaseProtocol); |
|
913 |
if (m_BaseCommHandle) ::FreeLibrary(m_BaseCommHandle); m_BaseCommHandle = NULL; |
|
914 |
if (m_BaseProtocolHandle) ::FreeLibrary(m_BaseProtocolHandle); m_BaseProtocolHandle = NULL; |
|
915 |
} |
|
916 |
else |
|
917 |
{ |
|
918 |
m_BaseComm = lpCommFn(m_ConnectSettings, m_ConnectionID, m_BaseProtocol); |
|
919 |
if (m_BaseComm == NULL) |
|
920 |
{ |
|
921 |
TCDEBUGLOGA1(" error creating comm, m_BaseComm=%x\n", m_BaseComm); |
|
922 |
if (m_BaseProtocol) delete m_BaseProtocol; m_BaseProtocol = NULL; |
|
923 |
||
924 |
if (m_BaseCommHandle) ::FreeLibrary(m_BaseCommHandle); m_BaseCommHandle = NULL; |
|
925 |
if (m_BaseProtocolHandle) ::FreeLibrary(m_BaseProtocolHandle); m_BaseProtocolHandle = NULL; |
|
926 |
} |
|
927 |
else |
|
928 |
{ |
|
929 |
loaded = TRUE; |
|
930 |
TCDEBUGLOGA4(" created class, m_BaseComm=%x m_BaseProtocol=%x m_BaseCommHandle=%x m_BaseProtocolHandle=%x\n", m_BaseComm, m_BaseProtocol, m_BaseCommHandle, m_BaseProtocolHandle); |
|
931 |
} |
|
932 |
} |
|
933 |
} |
|
934 |
} |
|
935 |
||
936 |
TCDEBUGCLOSE(); |
|
937 |
return loaded; |
|
938 |
} |