|
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 // TCFClient.cpp : Defines the entry point for the DLL application. |
|
18 // |
|
19 |
|
20 #include "stdafx.h" |
|
21 #include <stdio.h> |
|
22 #include <sys/stat.h> |
|
23 #include "ClientManager.h" |
|
24 #include "ServerClient.h" |
|
25 #include "InputStream.h" |
|
26 #include "ErrorMonitorData.h" |
|
27 #include "TCDebugLog.h" |
|
28 #include <vector> |
|
29 |
|
30 // process wide data |
|
31 CClientManager* gManager; |
|
32 #ifdef _DEBUG |
|
33 BOOL gDoLogging = FALSE; |
|
34 #endif |
|
35 |
|
36 #ifdef _DEBUG |
|
37 static void LogTime(FILE* f); |
|
38 #endif |
|
39 |
|
40 |
|
41 BOOL APIENTRY DllMain( HINSTANCE hinstDLL, |
|
42 DWORD fdwReason, |
|
43 LPVOID lpReserved |
|
44 ) |
|
45 { |
|
46 // Perform actions based on the reason for calling. |
|
47 switch( fdwReason ) |
|
48 { |
|
49 case DLL_PROCESS_ATTACH: |
|
50 { |
|
51 // Initialize once for each new process. |
|
52 // Return FALSE to fail DLL load. |
|
53 DWORD currentProcessId = ::GetCurrentProcessId(); |
|
54 |
|
55 // Create client manager for this process |
|
56 #ifdef _DEBUG |
|
57 struct _stat buf; |
|
58 char* dirname = "c:\\tcf"; |
|
59 int result = _stat(dirname, &buf); |
|
60 if (result == 0) // exists |
|
61 { |
|
62 gDoLogging = TRUE; |
|
63 } |
|
64 else |
|
65 { |
|
66 gDoLogging = FALSE; |
|
67 } |
|
68 |
|
69 #endif |
|
70 gManager = new CClientManager(hinstDLL); |
|
71 #ifdef _DEBUG |
|
72 if (gDoLogging) |
|
73 { |
|
74 FILE* f = fopen("c:\\tcf\\TCF_DllMainDLL_PROCESS_ATTACH.txt", "at"); |
|
75 LogTime(f); |
|
76 fprintf(f,"DLL_PROCESS_ATTACH:\n hinstDLL=%x\n processId=%d\n DllLocation=%s\n DebugLog->m_FileName=%s\n", |
|
77 hinstDLL, |
|
78 currentProcessId, |
|
79 gManager->m_DllLocation, |
|
80 gManager->m_DebugLog->m_FileName); |
|
81 fclose(f); |
|
82 } |
|
83 #endif |
|
84 } |
|
85 break; |
|
86 |
|
87 case DLL_THREAD_ATTACH: |
|
88 { |
|
89 // Do thread-specific initialization. |
|
90 DWORD currentThreadId = ::GetCurrentThreadId(); |
|
91 #ifdef _DEBUG |
|
92 if (gDoLogging) |
|
93 { |
|
94 FILE* f = fopen("c:\\tcf\\TCF_DllMainDLL_THREAD_ATTACH.txt", "at"); |
|
95 LogTime(f); |
|
96 fprintf(f,"DLL_THREAD_ATTACH: hinstDLL=%x currentThreadId=%d\n", hinstDLL, currentThreadId); |
|
97 fclose(f); |
|
98 } |
|
99 #endif |
|
100 } |
|
101 break; |
|
102 |
|
103 case DLL_THREAD_DETACH: |
|
104 { |
|
105 // Do thread-specific cleanup. |
|
106 DWORD currentThreadId = ::GetCurrentThreadId(); |
|
107 #ifdef _DEBUG |
|
108 if (gDoLogging) |
|
109 { |
|
110 FILE* f = fopen("c:\\tcf\\TCF_DllMainDLL_THREAD_DETACH.txt", "at"); |
|
111 LogTime(f); |
|
112 fprintf(f,"DLL_THREAD_DETTACH: hinstDLL=%x currentThreadId=%d\n", hinstDLL, currentThreadId); |
|
113 fclose(f); |
|
114 } |
|
115 #endif |
|
116 } |
|
117 break; |
|
118 |
|
119 case DLL_PROCESS_DETACH: |
|
120 { |
|
121 // Perform any necessary cleanup. |
|
122 DWORD currentProcessId = ::GetCurrentProcessId(); |
|
123 // delete the client manager for this process |
|
124 #ifdef _DEBUG |
|
125 if (gDoLogging) |
|
126 { |
|
127 FILE* f = fopen("c:\\tcf\\TCF_DllMainDLL_PROCESS_DETACH.txt", "at"); |
|
128 LogTime(f); |
|
129 fprintf(f,"DLL_PROCESS_DETACH processId=%d\n", currentProcessId); |
|
130 fclose(f); |
|
131 } |
|
132 #endif |
|
133 if (gManager) |
|
134 { |
|
135 delete gManager; |
|
136 } |
|
137 } |
|
138 break; |
|
139 } |
|
140 return TRUE; // Successful DLL_PROCESS_ATTACH. |
|
141 } |
|
142 #ifdef _DEBUG |
|
143 static void LogTime(FILE* f) |
|
144 { |
|
145 SYSTEMTIME sTime; |
|
146 GetLocalTime(&sTime); |
|
147 if (f) |
|
148 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); |
|
149 } |
|
150 #endif |
|
151 |