connectivity/com.nokia.tcf/native/TCFNative/TCFServer/Client.cpp
changeset 60 9d2210c8eed2
equal deleted inserted replaced
59:c892c53c664e 60:9d2210c8eed2
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 // Client.cpp: implementation of the CClient class.
       
    18 //
       
    19 //////////////////////////////////////////////////////////////////////
       
    20 
       
    21 #include "stdafx.h"
       
    22 #include "Client.h"
       
    23 #include "ServerManager.h"
       
    24 
       
    25 extern CServerManager* gManager;
       
    26 #ifdef _DEBUG
       
    27 extern BOOL gDoLogging;
       
    28 #endif
       
    29 
       
    30 //#define LOG_CLIENT
       
    31 #if defined(LOG_CLIENT) && defined(_DEBUG)
       
    32 extern char TCDebugMsg[];
       
    33 #define TCDEBUGOPEN() if (gDoLogging) { gManager->m_DebugLog->WaitForAccess(); }
       
    34 #define TCDEBUGLOGS(s) if (gDoLogging) { sprintf(TCDebugMsg,"%s", s); gManager->m_DebugLog->log(TCDebugMsg); }
       
    35 #define TCDEBUGLOGA1(s, a1) if (gDoLogging) { sprintf(TCDebugMsg, s, a1); gManager->m_DebugLog->log(TCDebugMsg); }
       
    36 #define TCDEBUGLOGA2(s, a1, a2) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2); gManager->m_DebugLog->log(TCDebugMsg); }
       
    37 #define TCDEBUGLOGA3(s, a1, a2, a3) if (gDoLogging) { sprintf(TCDebugMsg, s, a1, a2, a3); gManager->m_DebugLog->log(TCDebugMsg); }
       
    38 #define TCDEBUGCLOSE() if (gDoLogging) { gManager->m_DebugLog->ReleaseAccess(); }
       
    39 #else
       
    40 #define TCDEBUGOPEN()
       
    41 #define TCDEBUGLOGS(s)
       
    42 #define TCDEBUGLOGA1(s, a1)
       
    43 #define TCDEBUGLOGA2(s, a1, a2)
       
    44 #define TCDEBUGLOGA3(s, a1, a2, a3)
       
    45 #define TCDEBUGCLOSE()
       
    46 #endif
       
    47 
       
    48 //////////////////////////////////////////////////////////////////////
       
    49 // Construction/Destruction
       
    50 //////////////////////////////////////////////////////////////////////
       
    51 
       
    52 CClient::CClient()
       
    53 {
       
    54 	TCDEBUGOPEN();
       
    55 	TCDEBUGLOGS("CClient::CClient\n");
       
    56 	
       
    57 	m_InputStream = NULL;
       
    58 	m_MessageFile = NULL;
       
    59 	m_ErrorMonitor = NULL;
       
    60 	m_Connection = NULL;
       
    61 	m_Status = eStopped;
       
    62 	m_ClientId = -1;
       
    63 	m_Options.ostVersion = 1;
       
    64 	m_Options.unWrapFormat = DEFAULT_UNWRAP_OPTION;
       
    65 	m_MessageDestination = eDestinationInputStream;	// default - changed later
       
    66 
       
    67 	TCDEBUGCLOSE();
       
    68 }
       
    69 
       
    70 CClient::CClient(CConnection* connection, ClientOptions& options, DWORD clientId)
       
    71 {
       
    72 	TCDEBUGOPEN();
       
    73 	TCDEBUGLOGS("CClient::CClient\n");
       
    74 	
       
    75 	m_Connection = connection;
       
    76 	m_Options.ostVersion = options.ostVersion;
       
    77 	m_Options.unWrapFormat = options.unWrapFormat;
       
    78 	m_ClientId = clientId;
       
    79 	m_Status = eStopped;
       
    80 
       
    81 	m_ErrorMonitor = new CErrorMonitor(m_ClientId);
       
    82 	m_ErrorMonitor->CreateData();
       
    83 	m_InputStream = NULL; // created on open instead
       
    84 	m_MessageFile = NULL;
       
    85 	m_MessageDestination = eDestinationInputStream;	// default - changed later
       
    86 
       
    87 
       
    88 	TCDEBUGCLOSE();
       
    89 }
       
    90 CClient::~CClient()
       
    91 {
       
    92 	TCDEBUGOPEN();
       
    93 	TCDEBUGLOGS("CClient::~CClient\n");
       
    94 	
       
    95 	if (m_ErrorMonitor)
       
    96 		delete m_ErrorMonitor;
       
    97 
       
    98 	if (m_InputStream)
       
    99 		delete m_InputStream;
       
   100 
       
   101 	if (m_MessageFile)
       
   102 		delete m_MessageFile;
       
   103 
       
   104 	TCDEBUGCLOSE();
       
   105 }
       
   106 BOOL CClient::OpenStream(DestinationOptions* streamOptions)
       
   107 {
       
   108 	TCDEBUGOPEN();
       
   109 	TCDEBUGLOGS("CClient::OpenStream\n");
       
   110 	
       
   111 	BOOL done = TRUE;
       
   112 
       
   113 	if (m_InputStream == NULL)
       
   114 	{
       
   115 		m_InputStream = new CInputStream(streamOptions->destinationFile, streamOptions->streamSize, streamOptions->overFlowToFile, m_ClientId);
       
   116 		m_InputStream->CreateStream();
       
   117 	}
       
   118 
       
   119 	TCDEBUGCLOSE();
       
   120 	return done;
       
   121 }
       
   122 
       
   123 BOOL CClient::CloseStream()
       
   124 {
       
   125 	TCDEBUGOPEN();
       
   126 	TCDEBUGLOGS("CClient::CloseStream\n");
       
   127 	
       
   128 	BOOL done = TRUE;
       
   129 
       
   130 	if (m_InputStream)
       
   131 	{
       
   132 		delete m_InputStream;
       
   133 		m_InputStream = NULL;
       
   134 	}
       
   135 
       
   136 	TCDEBUGCLOSE();
       
   137 	return done;
       
   138 }
       
   139 BOOL CClient::OpenMessageFile(DestinationOptions *messageFileOptions)
       
   140 {
       
   141 	BOOL done = TRUE;
       
   142 	if (m_MessageFile == NULL)
       
   143 	{
       
   144 		m_MessageFile = new CMessageFile(messageFileOptions->destinationFile, m_ClientId);
       
   145 		m_MessageFile->Open();
       
   146 	}
       
   147 
       
   148 	return done;
       
   149 }
       
   150 BOOL CClient::CloseMessageFile()
       
   151 {
       
   152 	BOOL done = TRUE;
       
   153 
       
   154 	if (m_MessageFile)
       
   155 	{
       
   156 		delete m_MessageFile;
       
   157 		m_MessageFile = NULL;
       
   158 	}
       
   159 
       
   160 	return done;
       
   161 }
       
   162 BOOL CClient::ClearMessageFile()
       
   163 {
       
   164 	BOOL done = TRUE;
       
   165 
       
   166 	if (m_MessageFile)
       
   167 	{
       
   168 		m_MessageFile->ClearFile();
       
   169 	}
       
   170 
       
   171 	return done;
       
   172 }
       
   173