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