connectivity/com.nokia.tcf/native/TCFNative/TCFServer/ConnectionImpl.h
author wpaul
Thu, 09 Sep 2010 16:48:02 -0500
changeset 1979 59f66d6a7b33
parent 1473 6c45b7c9cdac
permissions -rw-r--r--
don't show the welcome screen - bug #9556.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     1
/*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     3
* All rights reserved.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     4
* This component and the accompanying materials are made available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     6
* which accompanies this distribution, and is available
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     8
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
     9
* Initial Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    11
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    12
* Contributors:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    13
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    14
* Description: 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    15
*
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    16
*/
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    17
// ConnectionImpl.h: interface for the CConnectionImpl class.
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    18
//
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    19
//////////////////////////////////////////////////////////////////////
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    20
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    21
#if !defined(AFX_CONNECTIONIMPL_H__1D0D5B50_3DDD_49B8_834B_5996D9CC0124__INCLUDED_)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    22
#define AFX_CONNECTIONIMPL_H__1D0D5B50_3DDD_49B8_834B_5996D9CC0124__INCLUDED_
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    23
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    24
#if _MSC_VER > 1000
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    25
#pragma once
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    26
#endif // _MSC_VER > 1000
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    27
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    28
#include "Connection.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    29
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    30
class CConnectionImpl : public CConnection  
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    31
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    32
public:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    33
	CConnectionImpl();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    34
	CConnectionImpl(ConnectData conData, DWORD connectionId);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    35
	virtual ~CConnectionImpl();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    36
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    37
	BOOL IsEqual(CConnection* connection);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    38
	BOOL IsEqual(pConnectData pConData);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    39
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    40
	BOOL AddClient(CClient* client);	// add a client to this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    41
	BOOL RemoveClient(CClient* client);	// remove a client from this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    42
	BOOL AddClientToRegistry(CClient* client, long numberIds, BYTE* ids); 
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    43
	BOOL RemoveClientFromRegistry(CClient* client); // remove a client from this registry
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    44
	BOOL StartClient(CClient* client){ return TRUE; }	// start processing for a specified client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    45
	BOOL StopClient(CClient* client){ return TRUE; }	// stop processing for a specified client
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    46
	long DoConnect();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    47
	long DoDisconnect();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    48
	long DoSendMessage(long encodeOption, BYTE protocolVersion, BOOL useMsgId, BYTE msgId, DWORD msgLength, BYTE* msg);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    49
	long DoRetryProcessing();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    50
	long EnterRetryPeriod(long err, bool passOsErr, DWORD osErr);
1473
6c45b7c9cdac Close ports when there is a fatal error allowing OS to free all handles to it. Do not report OSErrors on sending messages as these are confusing.
Chad Peckham <chad.peckham@nokia.com>
parents: 60
diff changeset
    51
	long HandleFatalPortError(long err, bool passOsErr, DWORD osErr);
60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    52
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    53
	BOOL PauseProcessing();				// pause processing thread (not exit)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    54
	BOOL RestartProcessing();			// restart processing after a pause
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    55
	BOOL StartProcessing();				// start processing thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    56
	BOOL ExitProcessing();				// exit processing thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    57
	BOOL IsProcessingPaused() { return (m_MessageProcessorState == MP_PAUSE); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    58
	BOOL IsProcessingStarted() { return (m_MessageProcessorState == MP_START); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    59
	BOOL IsProcessingContinuing() { return (m_MessageProcessorState == MP_PROCESSING); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    60
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    61
	long GetConnectionId() { return m_ConnectionID; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    62
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    63
	// m_Status operations
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    64
	BOOL IsConnected() { return ((m_Status == eConnected) || (m_Status == eRetryInProgress)); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    65
	BOOL IsDisconnected() { return (m_Status == eDisconnected); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    66
	BOOL IsRetryInProgress() { return (m_Status== eRetryInProgress); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    67
	BOOL IsRetryTimedOut() { return (m_Status == eRetryTimedOut); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    68
	void SetConnected() { m_Status = eConnected; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    69
	void SetDisconnected() { m_Status = eDisconnected; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    70
	void SetRetryInProgress() { m_Status = eRetryInProgress; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    71
	void SetRetryTimedOut() { m_Status = eRetryTimedOut; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    72
	void NotifyClientsCommError(long tcfError, bool passOsError=false, DWORD osError=0);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    73
	BOOL CreateCommProtocols(const char* commLibraryPath, const char* protocolLibraryPath);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    74
	BOOL HasVersion();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    75
	void GetVersion(char* outVersion);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    76
	
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    77
	long GetNumberClients() { return m_ClientList->size(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    78
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    79
	void UnLockAllDestinations();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    80
	void FlushAllClientMessageFiles();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    81
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    82
	ConnectData* m_ConnectSettings;	// connection settings
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    83
	ClientList* m_ClientList;		// this connection only
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    84
	eConnectionStatus m_Status;		// this connection status
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    85
	CRegistry* m_Registry;			// registry for this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    86
	long m_ConnectionID;			// id for this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    87
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    88
	CBaseCom* m_BaseComm;			// communication port handler
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    89
	HINSTANCE m_BaseCommHandle;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    90
	CBaseProtocol* m_BaseProtocol;	// protocol for port
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    91
	HINSTANCE m_BaseProtocolHandle;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    92
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    93
	unsigned long m_OsError;		// error from OS if applicable
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    94
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    95
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    96
	char m_DebugLogMsg[2000];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    97
	TCDebugLog* m_DebugLog;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    98
	char m_DebugLogMsg2[2000];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    99
	TCDebugLog* m_DebugLog2;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   100
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   101
	// MessageProcessor thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   102
	static DWORD WINAPI MessageProcessor(LPVOID lpParam);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   103
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   104
	int m_MessageProcessorState;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   105
	bool m_ExitMessageProcessor;		// flag to tell MessageProcessor thread to exit
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   106
	bool m_PauseMessageProcessing; // flag to tell MessageProcessor thread to stop all message processing (temporarily)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   107
	bool m_StartMessageProcessing;	// flag to tell MessageProcessor thread to start message processing
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   108
	HANDLE m_hMessageProcessorExittedEvent; // event to tell main thread that MessageProcessor thread has exitted
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   109
	HANDLE m_hMessageProcessorStoppedEvent; // event to tell main thread that MessageProcessor thread has stopped processing
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   110
	HANDLE m_hMessageProcessorStartedEvent; // event to tell main thread that MessageProcessor thread has started processing
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   111
	
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   112
	HANDLE m_hMessageProcessorThread;	// handle to MessageProcessor thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   113
	DWORD m_dwMessageProcessorThreadId;	// ID for          "			"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   114
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   115
	// com errors and retry stuff
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   116
	time_t m_NextRetryTime;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   117
	time_t m_RetryTimeoutTime;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   118
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   119
	// client flush times
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   120
	DWORD m_NextFlushFileTime;
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
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   124
#endif // !defined(AFX_CONNECTIONIMPL_H__1D0D5B50_3DDD_49B8_834B_5996D9CC0124__INCLUDED_)