connectivity/com.nokia.tcf/native/TCFNative/TCFServer/ServerManager.cpp
author fturovic <frank.turovich@nokia.com>
Mon, 29 Jun 2009 16:17:23 -0500
changeset 326 ab7c9b8bd24f
parent 60 9d2210c8eed2
child 366 b054461d2f85
permissions -rw-r--r--
bug 9343 fixed broken link
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
// ServerManager.cpp: implementation of the CServerManager 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 "ServerManager.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    23
#include "ConnectionImpl.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    24
#include "resource.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
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    27
#ifdef _DEBUG
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    28
extern BOOL gDoLogging;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    29
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    30
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    31
#define LOG_SERVERMANAGER
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    32
#if defined(LOG_SERVERMANAGER) && defined(_DEBUG)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    33
extern char TCDebugMsg[];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    34
#define TCDEBUGOPEN() if (gDoLogging) { m_DebugLog->WaitForAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    35
#define TCDEBUGLOGS(s) if (gDoLogging) { sprintf(TCDebugMsg,"%s", s); m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    36
#define TCDEBUGLOGA1(s, a1) if (gDoLogging) { sprintf(TCDebugMsg, s, a1); m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    37
#define TCDEBUGLOGA2(s, a1, a2) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2); m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    38
#define TCDEBUGLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2, a3); m_DebugLog->log(TCDebugMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    39
#define TCDEBUGCLOSE() if (gDoLogging) { m_DebugLog->ReleaseAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    40
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    41
#define TCDEBUGOPEN()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    42
#define TCDEBUGLOGS(s)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    43
#define TCDEBUGLOGA1(s, a1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    44
#define TCDEBUGLOGA2(s, a1, a2)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    45
#define TCDEBUGLOGA3(s, a1, a2, a3)
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
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    49
extern char* gServerLocation;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    50
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    51
// Construction/Destruction
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    52
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    53
CServerManager::CServerManager()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    54
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    55
	m_DebugLog = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    56
	m_Server = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    57
	m_ConnectionList = 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_NextClientId = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    60
	m_NextConnectionId = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    61
	m_Version[0] = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    62
	m_ExeLocation = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    63
	m_ProtocolList = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    64
	m_CommList = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    65
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    66
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    67
CServerManager::CServerManager(const char* exeLocation)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    68
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    69
#ifdef _DEBUG
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    70
	if (gDoLogging)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    71
		m_DebugLog = new TCDebugLog("TCF_ServerLog", ::GetCurrentProcessId());
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    72
	else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    73
		m_DebugLog = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    74
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    75
	m_DebugLog = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    76
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    77
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    78
	TCDEBUGLOGS("CServerManager::CServerManager\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    79
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    80
	m_Server = new CServerCommand();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    81
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    82
	m_ConnectionList = new ConnectionList();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    83
	m_ConnectionList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    84
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    85
	m_ClientList = new ClientList();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    86
	m_ClientList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    87
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    88
	m_NextClientId = ::GetCurrentProcessId() * 100;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    89
	m_NextConnectionId = (::GetCurrentProcessId() * 100) + 100;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    90
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    91
	int ret = ::LoadString(::GetModuleHandle(NULL), IDS_VERSION, m_Version, MAX_VERSION_STRING);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    92
	TCDEBUGLOGA1(" version=%s\n", m_Version);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    93
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    94
	TCDEBUGLOGA1(" exeLocation=%s\n", exeLocation);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    95
	m_ExeLocation = new char[MAX_EXEPATHNAME];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    96
	m_ExeLocation[0] = '\0';
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    97
	strcpy(m_ExeLocation, exeLocation);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    98
	TCDEBUGLOGA1(" m_ExeLocation=%s\n", m_ExeLocation);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    99
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   100
	m_ProtocolList = new ProtocolRegistry();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   101
	m_ProtocolList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   102
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   103
	m_CommList = new CommRegistry();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   104
	m_CommList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   105
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   106
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   107
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   108
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   109
CServerManager::~CServerManager()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   110
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   111
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   112
	TCDEBUGLOGS("CServerManager::~CServerManager\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   113
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   114
	if (m_Server)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   115
		delete m_Server;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   116
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   117
	if (m_ConnectionList)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   118
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   119
		m_ConnectionList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   120
		delete m_ConnectionList;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   121
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   122
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   123
	if (m_ClientList)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   124
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   125
		m_ClientList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   126
		delete m_ClientList;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   127
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   128
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   129
	if (m_ExeLocation)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   130
		delete[] m_ExeLocation;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   131
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   132
	if (m_ProtocolList)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   133
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   134
		m_ProtocolList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   135
		delete m_ProtocolList;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   136
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   137
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   138
	if (m_CommList)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   139
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   140
		m_CommList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   141
		delete m_CommList;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   142
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   143
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   144
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   145
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   146
	if (m_DebugLog)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   147
		delete m_DebugLog;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   148
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   149
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   150
void CServerManager::CommandThread()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   151
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   152
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   153
	TCDEBUGLOGS("CServerManager::CommandThread\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   154
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   155
	
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   156
	bool done = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   157
	eServerCommand command = eCmdNone;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   158
	ServerCommandData cmdrsp; pServerCommandData pCmdrsp = &cmdrsp;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   159
	pServerMessageData pMsg = new ServerMessageData();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   160
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   161
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   162
	RegisterAllProtocols();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   163
	RegisterAllComms();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   164
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   165
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   166
	while(!done)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   167
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   168
		while(!m_Server->GetCommand(pCmdrsp, pMsg))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   169
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   170
			Sleep(1);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   171
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   172
		command = pCmdrsp->command;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   173
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   174
		switch(command)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   175
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   176
		case eCmdConnect:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   177
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   178
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   179
				TCDEBUGLOGS(" eCmdConnect\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   180
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   181
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   182
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   183
				BOOL connCreated = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   184
				CConnectionImpl* conn = (CConnectionImpl*)FindConnection(&pCmdrsp->connectSettings);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   185
				if (conn == NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   186
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   187
					// create new one
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   188
					DWORD connId = m_NextConnectionId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   189
					conn = new CConnectionImpl(pCmdrsp->connectSettings, connId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   190
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   191
					TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   192
					const char* commPath = FindCommPath(pCmdrsp->connectSettings.connectType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   193
					TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   194
					TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   195
					const char* protPath = FindProtocolPath(pCmdrsp->connectSettings.decodeFormat);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   196
					TCDEBUGCLOSE();
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 (protPath == NULL || commPath == NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   199
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   200
						ret = TCAPI_ERR_UNKNOWN_MEDIA_TYPE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   201
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   202
					else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   203
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   204
						if (conn->CreateCommProtocols(commPath, protPath))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   205
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   206
							connCreated = TRUE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   207
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   208
						else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   209
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   210
							ret = TCAPI_ERR_UNKNOWN_MEDIA_TYPE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   211
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   212
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   213
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   214
				if (ret == TCAPI_ERR_NONE && (conn->IsDisconnected() || conn->IsRetryTimedOut()))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   215
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   216
					ret = conn->DoConnect();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   217
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   218
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   219
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   220
					DWORD id = m_NextClientId++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   221
					// create client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   222
					CClient* client = new CClient(conn, pCmdrsp->clientOptions, id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   223
					// add client to connection's list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   224
					conn->AddClient(client);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   225
					// add client to total list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   226
					m_ClientList->push_back(client);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   227
					// add connection to connection list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   228
					if (connCreated)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   229
						m_ConnectionList->push_back(conn);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   230
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   231
					m_NextConnectionId++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   232
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   233
					pCmdrsp->clientId = id;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   234
					m_Server->SendResponse(pCmdrsp);
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
					if (conn->m_OsError > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   239
						pCmdrsp->osError = conn->m_OsError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   240
					else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   241
						pCmdrsp->osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   242
					if (connCreated)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   243
						delete conn;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   244
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   245
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   246
					m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   247
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   248
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   249
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   250
		case eCmdDisconnect:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   251
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   252
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   253
				TCDEBUGLOGS(" eCmdDisconnect\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   254
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   255
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   256
				// find this client in our list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   257
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   258
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   259
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   260
					// get the connection for this client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   261
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   262
					// pause the processing so we can delete the client 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   263
					conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   264
					// stop processing this client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   265
					client->Stop();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   266
					// remove client from registry
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   267
					conn->RemoveClientFromRegistry(client);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   268
					// remove from connections client list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   269
					conn->RemoveClient(client);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   270
					// remove from total client list
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   271
					RemoveClient(client);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   272
					// delete client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   273
					delete client;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   274
					// no more clients on this connection, disconnect this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   275
					if (conn->GetNumberClients() == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   276
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   277
						conn->ExitProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   278
						conn->DoDisconnect();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   279
						RemoveConnection(conn);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   280
						delete conn;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   281
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   282
					else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   283
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   284
						conn->RestartProcessing();
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
				pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   288
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   289
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   290
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   291
		case eCmdSetMessageIds:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   292
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   293
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   294
				TCDEBUGLOGS(" eCmdSetMessageIds\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   295
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   296
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   297
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   298
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   299
				bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   300
				// find client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   301
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   302
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   303
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   304
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   305
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   306
					if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   307
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   308
						conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   309
						restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   310
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   311
					if (conn->IsDisconnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   312
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   313
						ret = TCAPI_ERR_MEDIA_NOT_OPEN;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   314
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   315
					else if (conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   316
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   317
						ret = TCAPI_ERR_COMM_RETRY_IN_PROGRESS;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   318
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   319
					else if (conn->IsRetryTimedOut())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   320
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   321
						ret = TCAPI_ERR_COMM_TIMEOUT;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   322
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   323
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   324
					if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   325
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   326
						// add client to connection's registry
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   327
						conn->AddClientToRegistry(client, pCmdrsp->number, pCmdrsp->messageIds);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   328
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   329
					if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   330
						conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   331
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   332
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   333
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   334
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   335
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   336
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   337
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   338
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   339
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   340
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   341
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   342
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   343
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   344
		case eCmdGetNumberConnections:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   345
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   346
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   347
				TCDEBUGLOGS(" eCmdGetNumberConnections\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   348
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   349
				long num = m_ConnectionList->size();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   350
				pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   351
				pCmdrsp->numConnections = num;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   352
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   353
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   354
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   355
		case eCmdGetConnectionType:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   356
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   357
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   358
				TCDEBUGLOGS(" eCmdGetConnectionType\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   359
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   360
				long index = pCmdrsp->index;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   361
				CConnectionImpl* pConn = (CConnectionImpl*)FindConnection(index);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   362
				if (pConn != NULL)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   363
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   364
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   365
					strncpy(pCmdrsp->connectSettings.connectType, pConn->m_ConnectSettings->connectType, MAX_CONNECTION_TYPE);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   366
//					pCmdrsp->connectSettings.connectType = pConn->m_ConnectSettings->connectType;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   367
					m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   368
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   369
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   370
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   371
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   372
					pCmdrsp->error = TCAPI_ERR_MISSING_CONNECTION_SPEC;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   373
					m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   374
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   375
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   376
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   377
		case eCmdOpenStream:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   378
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   379
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   380
				TCDEBUGLOGS(" eCmdOpenStream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   381
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   382
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   383
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   384
				// find client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   385
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   386
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   387
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   388
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   389
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   390
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   391
					if (conn->IsDisconnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   392
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   393
						ret = TCAPI_ERR_MEDIA_NOT_OPEN;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   394
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   395
					else if (conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   396
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   397
						ret = TCAPI_ERR_COMM_RETRY_IN_PROGRESS;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   398
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   399
					else if (conn->IsRetryTimedOut())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   400
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   401
						ret = TCAPI_ERR_COMM_TIMEOUT;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   402
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   403
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   404
					if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   405
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   406
						bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   407
						if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   408
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   409
							restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   410
							conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   411
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   412
						client->OpenStream(&pCmdrsp->destinationOptions);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   413
						if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   414
							conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   415
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   416
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   417
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   418
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   419
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   420
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   421
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   422
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   423
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   424
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   425
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   426
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   427
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   428
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   429
		case eCmdCloseStream:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   430
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   431
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   432
				TCDEBUGLOGS(" eCmdCloseStream\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   433
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   434
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   435
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   436
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   437
				bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   438
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   439
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   440
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   441
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   442
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   443
					if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   444
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   445
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   446
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   447
							if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   448
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   449
								conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   450
								restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   451
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   452
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   453
						client->CloseStream();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   454
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   455
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   456
							if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   457
								conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   458
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   459
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   460
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   461
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   462
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   463
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   464
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   465
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   466
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   467
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   468
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   469
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   470
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   471
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   472
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   473
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   474
		case eCmdOpenMessageFile:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   475
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   476
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   477
				TCDEBUGLOGS(" eCmdOpenMessageFile\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   478
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   479
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   480
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   481
				// find client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   482
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   483
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   484
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   485
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   486
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   487
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   488
					if (conn->IsDisconnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   489
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   490
						ret = TCAPI_ERR_MEDIA_NOT_OPEN;
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 if (conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   493
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   494
						ret = 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
					else if (conn->IsRetryTimedOut())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   497
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   498
						ret = TCAPI_ERR_COMM_TIMEOUT;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   499
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   500
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   501
					if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   502
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   503
						bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   504
						if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   505
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   506
							restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   507
							conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   508
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   509
						client->OpenMessageFile(&pCmdrsp->destinationOptions);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   510
						if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   511
							conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   512
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   513
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   514
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   515
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   516
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   517
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   518
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   519
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   520
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   521
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   522
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   523
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   524
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   525
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   526
		case eCmdCloseMessageFile:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   527
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   528
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   529
				TCDEBUGLOGS(" eCmdCloseMessageFile\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   530
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   531
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   532
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   533
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   534
				bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   535
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   536
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   537
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   538
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   539
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   540
					if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   541
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   542
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   543
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   544
							if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   545
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   546
								conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   547
								restart = true;
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
						client->CloseMessageFile();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   551
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   552
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   553
							if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   554
								conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   555
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   556
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   557
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   558
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   559
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   560
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   561
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   562
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   563
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   564
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   565
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   566
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   567
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   568
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   569
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   570
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   571
		case eCmdClearMessageFile:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   572
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   573
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   574
				TCDEBUGLOGS(" eCmdClearMessageFile\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   575
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   576
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   577
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   578
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   579
				bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   580
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   581
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   582
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   583
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   584
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   585
					if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   586
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   587
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   588
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   589
							if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   590
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   591
								conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   592
								restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   593
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   594
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   595
						client->ClearMessageFile();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   596
						if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   597
							conn->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
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   601
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   602
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   603
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   604
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   605
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   606
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   607
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   608
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   609
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   610
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   611
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   612
		case eCmdStart:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   613
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   614
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   615
				TCDEBUGLOGS(" eCmdStart\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   616
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   617
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   618
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   619
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   620
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   621
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   622
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   623
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   624
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   625
					conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   626
					if (conn->IsDisconnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   627
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   628
						ret = TCAPI_ERR_MEDIA_NOT_OPEN;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   629
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   630
					else if (conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   631
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   632
						ret = TCAPI_ERR_COMM_RETRY_IN_PROGRESS;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   633
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   634
					else if (conn->IsRetryTimedOut())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   635
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   636
						ret = TCAPI_ERR_COMM_TIMEOUT;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   637
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   638
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   639
					if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   640
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   641
						client->Start();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   642
						conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   643
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   644
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   645
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   646
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   647
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   648
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   649
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   650
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   651
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   652
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   653
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   654
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   655
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   656
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   657
		case eCmdStop:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   658
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   659
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   660
				TCDEBUGLOGS(" eCmdStop\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   661
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   662
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   663
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   664
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   665
				bool restart = false;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   666
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   667
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   668
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   669
					// get connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   670
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   671
					if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   672
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   673
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   674
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   675
							if (conn->IsProcessingContinuing())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   676
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   677
								restart = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   678
								conn->PauseProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   679
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   680
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   681
						client->Stop();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   682
						if (!conn->IsRetryTimedOut() && !conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   683
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   684
							if (restart)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   685
								conn->RestartProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   686
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   687
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   688
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   689
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   690
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   691
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   692
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   693
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   694
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   695
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   696
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   697
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   698
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   699
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   700
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   701
				TCDEBUGLOGS(" eCmdStop done\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   702
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   703
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   704
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   705
		case eCmdSendMessage:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   706
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   707
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   708
				TCDEBUGLOGS(" eCmdSendMessage\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   709
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   710
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   711
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   712
				DWORD osErr = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   713
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   714
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   715
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   716
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   717
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   718
					if (conn->IsDisconnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   719
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   720
						ret = TCAPI_ERR_MEDIA_NOT_OPEN;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   721
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   722
					else if (conn->IsRetryInProgress())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   723
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   724
						ret = TCAPI_ERR_COMM_RETRY_IN_PROGRESS;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   725
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   726
					else if (conn->IsRetryTimedOut())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   727
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   728
						ret = TCAPI_ERR_COMM_TIMEOUT;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   729
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   730
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   731
					if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   732
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   733
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   734
				TCDEBUGLOGS(" eCmdSendMessage DoSendMessage\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   735
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   736
						ret = conn->DoSendMessage(pCmdrsp->encodeOption, pCmdrsp->protocolVersion, pCmdrsp->useMyId, pCmdrsp->myId, pMsg->length, pMsg->message);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   737
//						ret = conn->DoSendMessage(pMsg->length, pMsg->message);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   738
						if (ret != TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   739
							osErr = conn->m_OsError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   740
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   741
				TCDEBUGLOGS(" eCmdSendMessage DoSendMessage done\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   742
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   743
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   744
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   745
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   746
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   747
//	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   748
//				TCDEBUGLOGS(" eCmdSendMessage OK\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   749
//	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   750
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   751
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   752
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   753
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   754
//	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   755
//				TCDEBUGLOGS(" eCmdSendMessage ERROR\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   756
//	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   757
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   758
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   759
					if (osErr > 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   760
						pCmdrsp->osError = osErr;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   761
					else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   762
						pCmdrsp->osError = 0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   763
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   764
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   765
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   766
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   767
		case eCmdExit:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   768
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   769
				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   770
				TCDEBUGLOGS(" eCmdExit\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   771
				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   772
				DoShutdown();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   773
				done = true;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   774
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   775
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   776
		case eCmdGetNumberVersions:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   777
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   778
				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   779
				TCDEBUGLOGS(" eCmdGetNumberVersions\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   780
				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   781
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   782
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   783
				long numberVersions = 1; // 1 for server
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   784
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   785
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   786
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   787
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   788
					CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   789
					if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   790
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   791
						if (conn->HasVersion())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   792
							numberVersions++;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   793
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   794
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   795
				if (ret == TCAPI_ERR_NONE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   796
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   797
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   798
					pCmdrsp->number = numberVersions;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   799
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   800
				else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   801
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   802
					pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   803
					pCmdrsp->error = ret;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   804
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   805
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   806
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   807
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   808
		case eCmdGetVersion:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   809
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   810
				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   811
				TCDEBUGLOGS(" eCmdGetVersion\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   812
				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   813
				// index = 1 ==> TCFServer version
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   814
				// index = 2 ==> Connection version if it exists
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   815
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   816
				long index = pCmdrsp->index;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   817
				pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   818
				pCmdrsp->version[0] = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   819
				if (index == 1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   820
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   821
					pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   822
					strncpy(pCmdrsp->version, m_Version, MAX_VERSION_STRING);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   823
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   824
				else if (index == 2)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   825
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   826
					DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   827
					CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   828
					if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   829
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   830
						CConnectionImpl* conn = (CConnectionImpl*)client->GetConnection();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   831
						if (conn->IsConnected())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   832
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   833
							pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   834
							if (conn->HasVersion())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   835
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   836
								conn->GetVersion(pCmdrsp->version);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   837
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   838
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   839
						else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   840
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   841
							pCmdrsp->response = eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   842
							pCmdrsp->error = TCAPI_ERR_MEDIA_NOT_OPEN;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   843
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   844
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   845
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   846
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   847
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   848
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   849
		case eCmdGetClientStatus:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   850
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   851
				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   852
				TCDEBUGLOGS(" eCmdGetClientStatus\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   853
				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   854
				long ret = TCAPI_ERR_NONE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   855
				DWORD id = pCmdrsp->clientId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   856
				CClient* client = FindClient(id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   857
				pCmdrsp->response = eRspOK;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   858
				pCmdrsp->clientStatus = eUnknownClient;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   859
				if (client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   860
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   861
					if (client->IsStarted())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   862
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   863
						pCmdrsp->clientStatus = eStarted;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   864
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   865
					else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   866
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   867
						pCmdrsp->clientStatus = eStopped;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   868
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   869
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   870
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   871
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   872
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   873
		default:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   874
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   875
				TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   876
				TCDEBUGLOGA1(" unknown command = %d\n", command);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   877
				TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   878
				pCmdrsp->response = eRspOK;//eRspError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   879
				pCmdrsp->error = TCAPI_ERR_FEATURE_NOT_IMPLEMENTED;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   880
				m_Server->SendResponse(pCmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   881
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   882
			break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   883
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   884
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   885
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   886
	pCmdrsp->response = eRspExitted;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   887
	m_Server->SendResponse(&cmdrsp);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   888
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   889
	if (pMsg)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   890
		delete pMsg;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   891
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   892
	TCDEBUGOPEN();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   893
	TCDEBUGLOGS("CServerManager::CommandThread exitting\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   894
	TCDEBUGCLOSE();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   895
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   896
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   897
CConnection* CServerManager::FindConnection(pConnectData pConData)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   898
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   899
	TCDEBUGLOGS("CServerManager::FindConnection1\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   900
	CConnection* connection = 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_ConnectionList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   903
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   904
		ConnectionList::iterator pConn;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   905
		for (pConn = m_ConnectionList->begin(); pConn != m_ConnectionList->end(); pConn++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   906
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   907
			if ((*pConn)->IsEqual(pConData))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   908
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   909
				connection = *pConn;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   910
				break;
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
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   915
	TCDEBUGLOGA1("CServerManager::FindConnection1 connection=%x\n", connection);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   916
	return connection;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   917
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   918
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   919
CConnection* CServerManager::FindConnection(long index)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   920
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   921
	TCDEBUGLOGS("CServerManager::FindConnection2\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   922
	CConnection* connection = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   923
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   924
	if (m_ConnectionList->size() >= index)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   925
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   926
		connection = m_ConnectionList->at(index);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   927
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   928
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   929
	TCDEBUGLOGA1("CServerManager::FindConnection2 connection=%x\n", connection);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   930
	return connection;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   931
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   932
CClient* CServerManager::FindClient(DWORD id)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   933
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   934
	CClient* found = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   935
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   936
	if (m_ClientList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   937
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   938
		ClientList::iterator iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   939
		for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   940
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   941
			if ((*iter)->GetClientId() == id)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   942
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   943
				found = *iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   944
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   945
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   946
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   947
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   948
	return found;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   949
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   950
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   951
BOOL CServerManager::RemoveClient(CClient* client)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   952
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   953
	BOOL found = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   954
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   955
	if (m_ClientList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   956
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   957
		ClientList::iterator iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   958
		for (iter = m_ClientList->begin(); iter != m_ClientList->end(); iter++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   959
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   960
			if ((*iter)->GetClientId() == client->GetClientId())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   961
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   962
				m_ClientList->erase(iter);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   963
				found = TRUE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   964
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   965
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   966
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   967
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   968
	return found;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   969
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   970
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   971
BOOL CServerManager::RemoveConnection(CConnection* conn)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   972
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   973
	BOOL found = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   974
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   975
	if (m_ConnectionList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   976
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   977
		ConnectionList::iterator iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   978
		for (iter = m_ConnectionList->begin(); iter != m_ConnectionList->end(); iter++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   979
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   980
			if ((*iter)->GetConnectionId() == conn->GetConnectionId())
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   981
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   982
				m_ConnectionList->erase(iter);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   983
				found = TRUE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   984
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   985
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   986
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   987
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   988
	return found;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   989
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   990
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   991
void CServerManager::DoShutdown()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   992
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   993
	// for each connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   994
	// stop processing on that connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   995
	// disconnect that connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   996
	if (m_ConnectionList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   997
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   998
		ConnectionList::iterator pConn;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   999
		for (pConn = m_ConnectionList->begin(); pConn != m_ConnectionList->end(); pConn++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1000
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1001
			(*pConn)->ExitProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1002
			(*pConn)->DoDisconnect();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1003
			delete (*pConn);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1004
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1005
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1006
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1007
void CServerManager::RegisterAllComms()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1008
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1009
	TCDEBUGLOGS("CServerManager::RegisterAllComms\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1010
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1011
	m_CommList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1012
	if (m_ExeLocation && (m_ExeLocation[0] != '\0'))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1013
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1014
		char* searchPath = new char[MAX_EXEPATHNAME];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1015
		char* loadPath = new char[MAX_EXEPATHNAME];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1016
		strncpy(searchPath, m_ExeLocation, MAX_EXEPATHNAME);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1017
		sprintf(searchPath, "%s%c*", searchPath, PATH_DELIMITER);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1018
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1019
		TCDEBUGLOGA1("CServerManager::RegisterAllComms searchPath=%s\n", searchPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1020
		
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1021
		WIN32_FIND_DATA fileData;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1022
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1023
		HANDLE sh = ::FindFirstFile(searchPath, &fileData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1024
		if (sh != INVALID_HANDLE_VALUE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1025
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1026
			BOOL done = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1027
			while (!done)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1028
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1029
				TCDEBUGLOGA1("CServerManager::RegisterAllComms file=%s\n", fileData.cFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1030
				if (strncmp(fileData.cFileName, COMMDLL_BASENAME, strlen(COMMDLL_BASENAME)) == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1031
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1032
					sprintf(loadPath, "%s%c%s", m_ExeLocation, PATH_DELIMITER, fileData.cFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1033
					TCDEBUGLOGA1("CServerManager::RegisterAllComms loadPath=%s\n", loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1034
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1035
					HINSTANCE hLib = ::LoadLibrary(loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1036
					TCDEBUGLOGA1("CServerManager::RegisterAllComms hLib=%x\n", hLib);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1037
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1038
					if (hLib)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1039
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1040
						TCDEBUGLOGS("CServerManager::RegisterAllComms - library loaded\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1041
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1042
						COMMREGISTER lpFn = (COMMREGISTER)::GetProcAddress(hLib, COMMREGISTER_FNNAME);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1043
						TCDEBUGLOGA1("CServerManager::RegisterAllComms lpFn=%x\n", lpFn);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1044
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1045
						if (lpFn)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1046
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1047
							TCDEBUGLOGS("CServerManager::RegisterAllComms - function found\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1048
							const char* pType = lpFn();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1049
							if (pType)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1050
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1051
								TCDEBUGLOGA1("CServerManager::RegisterAllComms pType=%s\n", pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1052
								CCommRegistryItem* pComm = new CCommRegistryItem();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1053
								strcpy(pComm->m_CommLibrary, loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1054
								strcpy(pComm->m_CommType, pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1055
								m_CommList->push_back(pComm);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1056
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1057
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1058
						::FreeLibrary(hLib);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1059
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1060
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1061
				BOOL fNext = ::FindNextFile(sh, &fileData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1062
				if (fNext == FALSE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1063
					done = TRUE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1064
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1065
			::FindClose(sh);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1066
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1067
		delete[] searchPath;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1068
		delete[] loadPath;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1069
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1070
	TCDEBUGLOGS("CServerManager::RegisterAllComms\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1071
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1072
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1073
void CServerManager::RegisterAllProtocols()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1074
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1075
	TCDEBUGLOGS("CServerManager::RegisterAllProtocols\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1076
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1077
	m_ProtocolList->clear();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1078
	if (m_ExeLocation && (m_ExeLocation[0] != '\0'))
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1079
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1080
		char* searchPath = new char[MAX_EXEPATHNAME];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1081
		char* loadPath = new char[MAX_EXEPATHNAME];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1082
		strncpy(searchPath, m_ExeLocation, MAX_EXEPATHNAME);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1083
		sprintf(searchPath, "%s%c*", searchPath, PATH_DELIMITER);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1084
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1085
		TCDEBUGLOGA1("CServerManager::RegisterAllProtocols searchPath=%s\n", searchPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1086
		
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1087
		WIN32_FIND_DATA fileData;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1088
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1089
		HANDLE sh = ::FindFirstFile(searchPath, &fileData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1090
		BOOL done = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1091
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1092
		if (sh != INVALID_HANDLE_VALUE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1093
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1094
			BOOL done = FALSE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1095
			while (!done)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1096
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1097
				TCDEBUGLOGA1("CServerManager::RegisterAllProtocols file=%s\n", fileData.cFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1098
				if (strncmp(fileData.cFileName, PROTOCOLDLL_BASENAME, strlen(PROTOCOLDLL_BASENAME)) == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1099
				{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1100
					sprintf(loadPath, "%s%c%s", m_ExeLocation, PATH_DELIMITER, fileData.cFileName);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1101
					TCDEBUGLOGA1("CServerManager::RegisterAllProtocols loadPath=%s\n", loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1102
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1103
					HINSTANCE hLib = ::LoadLibrary(loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1104
					TCDEBUGLOGA1("CServerManager::RegisterAllProtocols hLib=%x\n", hLib);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1105
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1106
					if (hLib)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1107
					{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1108
						TCDEBUGLOGS("CServerManager::RegisterAllProtocols - library loaded\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1109
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1110
						PROTOCOLREGISTER lpFn = (PROTOCOLREGISTER)::GetProcAddress(hLib, PROTOCOLREGISTER_FNNAME);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1111
						TCDEBUGLOGA1("CServerManager::RegisterAllProtocols lpFn=%x\n", lpFn);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1112
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1113
						if (lpFn)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1114
						{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1115
							TCDEBUGLOGS("CServerManager::RegisterAllProtocols - function found\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1116
							const char* pType = lpFn();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1117
							if (pType)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1118
							{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1119
								TCDEBUGLOGA1("CServerManager::RegisterAllProtocols pType=%s\n", pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1120
								CProtocolRegistryItem* pProt = new CProtocolRegistryItem();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1121
								strcpy(pProt->m_ProtocolLibrary, loadPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1122
								strcpy(pProt->m_ProtocolType, pType);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1123
								m_ProtocolList->push_back(pProt);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1124
							}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1125
						}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1126
						::FreeLibrary(hLib);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1127
					}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1128
				}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1129
				BOOL fNext = ::FindNextFile(sh, &fileData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1130
				if (fNext == FALSE)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1131
					done = TRUE;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1132
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1133
			::FindClose(sh);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1134
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1135
		delete[] searchPath;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1136
		delete[] loadPath;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1137
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1138
	TCDEBUGLOGS("CServerManager::RegisterAllProtocols\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1139
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1140
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1141
void CServerManager::UnRegisterAllComms()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1142
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1143
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1144
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1145
void CServerManager::UnRegisterAllProtocols()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1146
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1147
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1148
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1149
const char* CServerManager::FindProtocolPath(char* protocolType)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1150
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1151
	char* path = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1152
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1153
	TCDEBUGLOGS("CServerManager::FindProtocolPath\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1154
	if (m_ProtocolList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1155
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1156
		ProtocolRegistry::iterator iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1157
		for (iter = m_ProtocolList->begin(); iter != m_ProtocolList->end(); iter++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1158
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1159
			if (strcmp((*iter)->m_ProtocolType, protocolType) == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1160
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1161
				path = (*iter)->m_ProtocolLibrary;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1162
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1163
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1164
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1165
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1166
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1167
	TCDEBUGLOGA1("CServerManager::FindProtocolPath path=%s\n", path);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1168
	return path;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1169
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1170
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1171
const char* CServerManager::FindCommPath(char* commType)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1172
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1173
	char* path = NULL;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1174
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1175
	TCDEBUGLOGS("CServerManager::FindCommPath\n");
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1176
	if (m_CommList->size() != 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1177
	{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1178
		CommRegistry::iterator iter;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1179
		for (iter = m_CommList->begin(); iter != m_CommList->end(); iter++)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1180
		{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1181
			if (strcmp((*iter)->m_CommType, commType) == 0)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1182
			{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1183
				path = (*iter)->m_CommLibrary;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1184
				break;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1185
			}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1186
		}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1187
	}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1188
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1189
	TCDEBUGLOGA1("CServerManager::FindCommPath path=%s\n", path);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1190
	return path;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1191
}
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
  1192