connectivity/com.nokia.tcf/native/TCFNative/TCFServer/BaseCom.h
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
#ifndef __BASECOM_H__
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    18
#define __BASECOM_H__
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    19
#include "Registry.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    20
#include "ServerClient.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    21
#include "TCConstants.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    22
#include "TCErrorConstants.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    23
#include "BaseProtocol.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    24
#include "TCDebugLog.h"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    25
#include <time.h>
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_COMM
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    32
#if defined(LOG_COMM) && defined(_DEBUG)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    33
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    34
#define COMMLOGOPEN() if (gDoLogging) { if (m_CommDebugLog) m_CommDebugLog->WaitForAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    35
#define COMMLOGS(s) if (gDoLogging) { sprintf(m_CommDebugLogMsg,"%s", s); if (m_CommDebugLog) m_CommDebugLog->log(m_CommDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    36
#define COMMLOGA1(s, a1) if (gDoLogging) { sprintf(m_CommDebugLogMsg, s, a1); if (m_CommDebugLog) m_CommDebugLog->log(m_CommDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    37
#define COMMLOGA2(s, a1, a2) if (gDoLogging) { sprintf(m_CommDebugLogMsg, s, a1, a2); if (m_CommDebugLog) m_CommDebugLog->log(m_CommDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    38
#define COMMLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(m_CommDebugLogMsg, s, a1, a2, a3); if (m_CommDebugLog) m_CommDebugLog->log(m_CommDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    39
#define COMMLOGA4(s, a1, a2, a3, a4) if (gDoLogging) { sprintf(m_CommDebugLogMsg, s, a1, a2, a3, a4); if (m_CommDebugLog) m_CommDebugLog->log(m_CommDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    40
#define COMMLOGCLOSE() if (gDoLogging) { if (m_CommDebugLog) m_CommDebugLog->ReleaseAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    41
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    42
#define COMMLOGOPEN()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    43
#define COMMLOGS(s)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    44
#define COMMLOGA1(s, a1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    45
#define COMMLOGA2(s, a1, a2)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    46
#define COMMLOGA3(s, a1, a2, a3)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    47
#define COMMLOGA4(s, a1, a2, a3, a4)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    48
#define COMMLOGCLOSE()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    49
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    50
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    51
#define LOG_PROCCOMM
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    52
#if defined(LOG_PROCCOMM) && defined(_DEBUG)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    53
#define PROCLOGOPEN() if (gDoLogging) { m_ProcDebugLog->WaitForAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    54
#define PROCLOGS(s) if (gDoLogging) { sprintf(m_ProcDebugLogMsg,"%s", s); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    55
#define PROCLOGA1(s, a1) if (gDoLogging) { sprintf(m_ProcDebugLogMsg, s, a1); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    56
#define PROCLOGA2(s, a1, a2) if (gDoLogging) { sprintf(m_ProcDebugLogMsg, s, a1, a2); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    57
#define PROCLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(m_ProcDebugLogMsg, s, a1, a2, a3); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    58
#define PROCLOGA4(s, a1, a2, a3, a4) if (gDoLogging) { sprintf(m_ProcDebugLogMsg, s, a1, a2, a3, a4); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    59
#define PROCLOGA5(s, a1, a2, a3, a4, a5) if (gDoLogging) { sprintf(m_ProcDebugLogMsg, s, a1, a2, a3, a4, a5); m_ProcDebugLog->log(m_ProcDebugLogMsg); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    60
#define PROCLOGCLOSE() if (gDoLogging) { m_ProcDebugLog->ReleaseAccess(); }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    61
#else
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    62
#define PROCLOGOPEN()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    63
#define PROCLOGS(s)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    64
#define PROCLOGA1(s, a1)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    65
#define PROCLOGA2(s, a1, a2)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    66
#define PROCLOGA3(s, a1, a2, a3)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    67
#define PROCLOGA4(s, a1, a2, a3, a4)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    68
#define PROCLOGA5(s, a1, a2, a3, a4, a5)
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    69
#define PROCLOGCLOSE()
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    70
#endif
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    71
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    72
class CConnection;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    73
class CBaseProtocol;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    74
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    75
class CBaseCom
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    76
{
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    77
public:
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    78
	CBaseCom();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    79
	CBaseCom(ConnectData* connectSettings, DWORD connectionId, CBaseProtocol* protocol);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    80
	virtual ~CBaseCom();
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    81
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    82
//	void SetConnectSettings(ConnectData* connectSettings);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    83
//	void SetProtocol(CBaseProtocol* protocol) { m_Protocol = protocol; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    84
//	void SetConnectionId(DWORD id);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    85
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    86
	virtual long OpenPort()=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    87
	virtual long ClosePort()=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    88
	virtual long SendDataToPort(DWORD inSize, const void* inData)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    89
	virtual long PollPort(DWORD& outSize)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    90
	virtual long ReadPort(DWORD inSize, void* outData, DWORD& outSize)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    91
	virtual long ProcessBuffer(CConnection* pConn, CRegistry* pRegistry, long& numberProcessed)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    92
	virtual void DeleteMsg(DWORD inMsgLength)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    93
	virtual bool IsConnected() { return m_isConnected; }
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    94
	virtual bool GetVersion(char* outVersion)=0; // get version of whatever we're connected to
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    95
	virtual bool HasVersion()=0; // does this connection have a version?
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    96
	virtual long PreProcessMessage(int inMsgType, DWORD inMsgLength, BYTE* inMessage)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    97
	virtual long PreProcessMessage(BYTE msgId, DWORD inMsgLength, BYTE* inMessage)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    98
	virtual bool IsConnectionEqual(ConnectData* pConn)=0;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
    99
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   100
	BYTE* m_pBuffer;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   101
	DWORD m_numberBytes;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   102
	bool m_isConnected;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   103
	DWORD m_connId;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   104
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   105
	ConnectData* m_ConnectSettings; // from connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   106
	CBaseProtocol* m_Protocol;		// used for this connection
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   107
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   108
	// for Open/Close/Send thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   109
	char m_CommDebugLogMsg[2000];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   110
	TCDebugLog* m_CommDebugLog;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   111
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   112
	// for Poll/Read/Process/PreProcess thread
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   113
	char m_ProcDebugLogMsg[2000];
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   114
	TCDebugLog* m_ProcDebugLog;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   115
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   116
	DWORD m_lastCommError;
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   117
};
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   118
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   119
typedef const char* (*COMMREGISTER)(void);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   120
typedef CBaseCom* (*COMMCREATE)(ConnectData* connectSettings, DWORD connectionId, CBaseProtocol* protocol);
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   121
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   122
#define COMMREGISTER_FNNAME	"RegisterComm"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   123
#define COMMCREATE_FNNAME	"CreateComm"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   124
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   125
#define COMMDLL_BASENAME	"TCFComm"
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   126
9d2210c8eed2 Commit changes for 2.1.0
chpeckha
parents:
diff changeset
   127
#endif __BASECOM_H__