connectivity/com.nokia.tcf/native/TCFNative/TCFServer/TCFServer.cpp
changeset 60 9d2210c8eed2
child 366 b054461d2f85
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 // TCFServer.cpp : Defines the entry point for the console application.
       
    18 //
       
    19 
       
    20 #include "stdafx.h"
       
    21 #include "ServerClient.h"
       
    22 #include "ServerManager.h"
       
    23 #include <vector>
       
    24 #include <sys/stat.h>
       
    25 
       
    26 CServerManager* gManager;
       
    27 char gServerLocation[2048]={0};
       
    28 
       
    29 #ifdef _DEBUG
       
    30 BOOL gDoLogging=FALSE;
       
    31 char TCDebugMsg[1000];
       
    32 #define TCDEBUGOPEN() gManager->m_DebugLog->WaitForAccess();
       
    33 #define TCDEBUGLOGS(s) sprintf(TCDebugMsg,"%s", s); gManager->m_DebugLog->log(TCDebugMsg);
       
    34 #define TCDEBUGLOGA1(s, a1) sprintf(TCDebugMsg, s, a1); gManager->m_DebugLog->log(TCDebugMsg);
       
    35 #define TCDEBUGLOGA2(s, a1, a2) sprintf(TCDebugMsg, s, a1, a2); gManager->m_DebugLog->log(TCDebugMsg);
       
    36 #define TCDEBUGLOGA3(s, a1, a2, a3) sprintf(TCDebugMsg, s, a1, a2, a3); gManager->m_DebugLog->log(TCDebugMsg);
       
    37 #define TCDEBUGCLOSE() gManager->m_DebugLog->ReleaseAccess();
       
    38 #else
       
    39 #define TCDEBUGOPEN()
       
    40 #define TCDEBUGLOGS(s)
       
    41 #define TCDEBUGLOGA1(s, a1)
       
    42 #define TCDEBUGLOGA2(s, a1, a2)
       
    43 #define TCDEBUGLOGA3(s, a1, a2, a3)
       
    44 #define TCDEBUGCLOSE()
       
    45 #endif
       
    46 static void GetServerLocation(char* cl);
       
    47 #ifdef _DEBUG
       
    48 static void LogTime(FILE* f);
       
    49 #endif
       
    50 int main(int argc, char* argv[])
       
    51 {
       
    52 #ifdef _DEBUG
       
    53 	struct _stat buf;
       
    54 	char* dirname = "c:\\tcf";
       
    55 	int result = _stat(dirname, &buf);
       
    56 	if (result == 0)
       
    57 	{
       
    58 		gDoLogging = TRUE;
       
    59 	}
       
    60 	else
       
    61 	{
       
    62 		gDoLogging = FALSE;
       
    63 	}
       
    64 #endif
       
    65 
       
    66 
       
    67 	if (argc == 2) // for running from the debugger
       
    68 	{
       
    69 		GetServerLocation(argv[1]);
       
    70 	}
       
    71 	else
       
    72 	{
       
    73 		GetServerLocation(argv[0]);
       
    74 	}
       
    75 #ifdef _DEBUG
       
    76 	if (gDoLogging)
       
    77 	{
       
    78 		FILE* f = fopen("c:\\tcf\\TCFServer_Main.txt", "at");
       
    79 		LogTime(f);
       
    80 		fprintf(f,"ExeLocation=%s\n", gServerLocation);
       
    81 		fclose(f);
       
    82 	}
       
    83 #endif
       
    84 	gManager = new CServerManager(gServerLocation);
       
    85 	gManager->CommandThread();
       
    86 	delete gManager;
       
    87 	return 0;
       
    88 }
       
    89 #ifdef _DEBUG
       
    90 static void LogTime(FILE* f)
       
    91 {
       
    92 	SYSTEMTIME sTime;
       
    93 	GetLocalTime(&sTime);
       
    94 	if (f)
       
    95 		fprintf(f, "%02.2d%02.2d-%02.2d:%02.2d:%02.2d.%03.3d: ", sTime.wDay, sTime.wMonth, sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds);
       
    96 }
       
    97 #endif
       
    98 #ifdef _WIN32
       
    99 void GetServerLocation(char* cl)
       
   100 {
       
   101 	char dir[_MAX_DIR];
       
   102 	char drive[_MAX_DRIVE];
       
   103 	_splitpath(cl, drive, dir, NULL, NULL);
       
   104 	sprintf(gServerLocation, "%s%s", drive, dir);
       
   105 }
       
   106 #else
       
   107 #error not Windows
       
   108 #endif