60
|
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 |
{
|
366
|
78 |
// FILE* f = fopen("c:\\tcf\\TCFServer_Main.txt", "at");
|
|
79 |
// LogTime(f);
|
|
80 |
// fprintf(f,"ExeLocation=%s\n", gServerLocation);
|
|
81 |
// fclose(f);
|
60
|
82 |
}
|
|
83 |
#endif
|
|
84 |
gManager = new CServerManager(gServerLocation);
|
|
85 |
gManager->CommandThread();
|
|
86 |
delete gManager;
|
366
|
87 |
|
60
|
88 |
return 0;
|
|
89 |
}
|
|
90 |
#ifdef _DEBUG
|
|
91 |
static void LogTime(FILE* f)
|
|
92 |
{
|
|
93 |
SYSTEMTIME sTime;
|
|
94 |
GetLocalTime(&sTime);
|
|
95 |
if (f)
|
|
96 |
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);
|
|
97 |
}
|
|
98 |
#endif
|
|
99 |
#ifdef _WIN32
|
|
100 |
void GetServerLocation(char* cl)
|
|
101 |
{
|
|
102 |
char dir[_MAX_DIR];
|
|
103 |
char drive[_MAX_DRIVE];
|
|
104 |
_splitpath(cl, drive, dir, NULL, NULL);
|
|
105 |
sprintf(gServerLocation, "%s%s", drive, dir);
|
|
106 |
}
|
|
107 |
#else
|
|
108 |
#error not Windows
|
|
109 |
#endif
|