00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #if !defined(_FEDM_LOGGER_H_INCLUDED_)
00035 #define _FEDM_LOGGER_H_INCLUDED_
00036
00037 #ifdef _FELOGMNG_SUPPORT
00038 #include <strstream>
00039 #include "felogmng.h"
00040 #endif
00041
00042
00043 #if defined(_FELOGMNG_LINUX)
00044 #include <dlfcn.h>
00045 #endif
00046
00047
00048 #ifdef _FELOGMNG_SUPPORT
00049
00050
00051
00052
00053 #if defined(_FELOGMNG_WINDOWS) || defined(_FELOGMNG_WINDOWS_CE)
00054 #define FEDM_TRACE(logger, a, b) \
00055 { \
00056 if(logger != NULL && logger->m_lpfnAddLogMessage != NULL) \
00057 { \
00058 LARGE_INTEGER logTime; \
00059 ::QueryPerformanceCounter(&logTime); \
00060 std::ostrstream oss; \
00061 oss << b << std::ends; \
00062 ((LPFN_FELOGMNG_ADD_LOG_MESSAGE)logger->m_lpfnAddLogMessage)(logger->m_pLogger, (unsigned long long)logTime.QuadPart, a, oss.str()); \
00063 oss.freeze(false); \
00064 } \
00065 }
00066 #endif
00067
00068 #if defined(_FELOGMNG_LINUX)
00069 #define FEDM_TRACE(logger, a, b) \
00070 { \
00071 if(logger != NULL && logger->m_lpfnAddLogMessage != NULL) \
00072 { \
00073 std::ostrstream oss; \
00074 oss << b << std::ends; \
00075 ((LPFN_FELOGMNG_ADD_LOG_MESSAGE)logger->m_lpfnAddLogMessage)(logger->m_pLogger, (unsigned long long)clock(), a, oss.str()); \
00076 oss.freeze(false); \
00077 } \
00078 }
00079 #endif
00080
00081
00082
00083
00084
00085
00086 #if defined(_FELOGMNG_WINDOWS) || defined(_FELOGMNG_WINDOWS_CE)
00087 #define FEDM_TRACE_FNC(logger, a, b, c, d) \
00088 { \
00089 if(logger != NULL && logger->m_lpfnAddLogMessageFnc != NULL) \
00090 { \
00091 LARGE_INTEGER logTime; \
00092 ::QueryPerformanceCounter(&logTime); \
00093 std::ostrstream oss1, oss2; \
00094 oss1 << b << std::ends; \
00095 oss2 << d << std::ends; \
00096 ((LPFN_FELOGMNG_ADD_LOG_MESSAGE_FNC)logger->m_lpfnAddLogMessageFnc)(logger->m_pLogger, (unsigned long long)logTime.QuadPart, a, oss1.str(), c, oss2.str()); \
00097 oss1.freeze(false); \
00098 oss2.freeze(false); \
00099 } \
00100 }
00101 #endif
00102
00103 #if defined(_FELOGMNG_LINUX)
00104 #define FEDM_TRACE_FNC(logger, a, b, c, d) \
00105 { \
00106 if(logger != NULL && logger->m_lpfnAddLogMessageFnc != NULL) \
00107 { \
00108 std::ostrstream oss1, oss2; \
00109 oss1 << b << std::ends; \
00110 oss2 << d << std::ends; \
00111 ((LPFN_FELOGMNG_ADD_LOG_MESSAGE_FNC)logger->m_lpfnAddLogMessageFnc)(logger->m_pLogger, (unsigned long long)clock(), a, oss1.str(), c, oss2.str()); \
00112 oss1.freeze(false); \
00113 oss2.freeze(false); \
00114 } \
00115 }
00116 #endif
00117
00118 #define FEDM_SETPROP1(logger, a, b) \
00119 { \
00120 if(logger != NULL && logger->m_lpfnSetLoggerProp1 != NULL) \
00121 { \
00122 ((LPFN_FELOGMNG_SET_LOGGER_PROP1)logger->m_lpfnSetLoggerProp1)(logger->m_pLogger, a, b); \
00123 } \
00124 }
00125
00126 #define FEDM_SETPROP2(logger, a, b) \
00127 { \
00128 if(logger != NULL && logger->m_lpfnSetLoggerProp2 != NULL) \
00129 { \
00130 ((LPFN_FELOGMNG_SET_LOGGER_PROP2)logger->m_lpfnSetLoggerProp2)(logger->m_pLogger, a, b); \
00131 } \
00132 }
00133
00134 #else
00135
00136 #define FEDM_TRACE(logger, a, b) {}
00137 #define FEDM_TRACE_FNC(logger, a, b, c, d) {}
00138 #define FEDM_SETPROP1(logger, a, b) {}
00139 #define FEDM_SETPROP2(logger, a, b) {}
00140
00141 #endif
00142
00143
00144
00145
00146 class FEDM_Logger
00147 {
00148 public:
00149 FEDM_Logger(unsigned __int64 ui64SourceLayer, unsigned int uiInstallCounter, std::string sVersion)
00150 {
00151 m_pLogger = NULL;
00152 m_pLib = NULL;
00153 m_lpfnCreateLogger = NULL;
00154 m_lpfnDeleteLogger = NULL;
00155 m_lpfnSetLoggerProp1 = NULL;
00156 m_lpfnSetLoggerProp2 = NULL;
00157 m_lpfnAddLogMessage = NULL;
00158 m_lpfnAddLogMessageFnc = NULL;
00159
00160 #ifdef _FELOGMNG_SUPPORT
00161 #if defined(_FEDM_WINDOWS)
00162 m_pLib = LoadLib("felogmng.dll");
00163 #elif defined(_FEDM_LINUX) || defined(_MAC_OSX)
00164 #if defined(_MAC_OSX)
00165 m_pLib = LoadLib("libfelogmng.dylib");
00166 #else
00167 m_pLib = LoadLib("libfelogmng.so");
00168 #endif
00169 #endif
00170
00171 if(m_pLib != NULL)
00172 {
00173
00174 m_lpfnCreateLogger = GetFunctionPtr(m_pLib, "FELOGMNG_CreateLogger");
00175 m_lpfnDeleteLogger = GetFunctionPtr(m_pLib, "FELOGMNG_DeleteLogger");
00176 m_lpfnSetLoggerProp1 = GetFunctionPtr(m_pLib, "FELOGMNG_SetLoggerProp1");
00177 m_lpfnSetLoggerProp2 = GetFunctionPtr(m_pLib, "FELOGMNG_SetLoggerProp2");
00178 m_lpfnAddLogMessage = GetFunctionPtr(m_pLib, "FELOGMNG_AddLogMessage");
00179 m_lpfnAddLogMessageFnc = GetFunctionPtr(m_pLib, "FELOGMNG_AddLogMessageFnc");
00180
00181 if(m_lpfnCreateLogger != NULL)
00182 {
00183 int iBack = ((LPFN_FELOGMNG_CREATE_LOGGER)m_lpfnCreateLogger)(ui64SourceLayer, FELOGMNG_SRC_OBJ, uiInstallCounter, 0, 0, 0, "", &m_pLogger);
00184 if(iBack == 0)
00185 {
00186 if(m_pLogger != NULL && uiInstallCounter == 1)
00187 {
00188 FEDM_TRACE(this, FELOGMNG_DBG_INFO, sVersion);
00189 }
00190 }
00191 }
00192 }
00193 #endif
00194 }
00195
00196 ~FEDM_Logger()
00197 {
00198 #ifdef _FELOGMNG_SUPPORT
00199 if(m_pLogger != NULL && m_lpfnDeleteLogger != NULL)
00200 {
00201 ((LPFN_FELOGMNG_DELETE_LOGGER)m_lpfnDeleteLogger)(m_pLogger);
00202 m_pLogger = NULL;
00203 }
00204 #endif
00205 }
00206
00207 void* LoadLib(const char* pszLibName)
00208 {
00209 void* pLib = NULL;
00210
00211 #ifdef _FELOGMNG_SUPPORT
00212 #if defined(_FEDM_WINDOWS)
00213 pLib = (void*)LoadLibrary(pszLibName);
00214 #elif defined(_WIN32_WCE)
00215 pLib = (void*)LoadLibrary(_T(pszLibName));
00216 #elif defined(_FEDM_LINUX)
00217 pLib = dlopen(pszLibName, RTLD_NOW | RTLD_GLOBAL);
00218 #endif
00219 #endif
00220
00221 return pLib;
00222 }
00223
00224 void CloseLib(void* pLib)
00225 {
00226 #ifdef _FELOGMNG_SUPPORT
00227 #if defined(_FEDM_WINDOWS)
00228 if(pLib != NULL)
00229 FreeLibrary((HINSTANCE)pLib);
00230 #endif
00231
00232 #if defined(_FEDM_LINUX)
00233 if(pLib != NULL)
00234 dlclose(pLib);
00235 #endif
00236 #endif
00237 }
00238
00239 void* GetFunctionPtr(void* pLib, const char* szFctName)
00240 {
00241 #ifdef _FELOGMNG_SUPPORT
00242 #ifdef _FEDM_WINDOWS
00243 #ifdef _WIN32_WCE
00244 #ifdef _FEDM_EVC4
00245 FARPROC pAdr = NULL;
00246 wchar_t* pwc = (wchar_t *)malloc( sizeof( wchar_t )*sizeof(szFctName));
00247 mbstowcs( pwc, szFctName, sizeof(szFctName) );
00248 pAdr = GetProcAddress((HINSTANCE)pLib, pwc);
00249 free(pwc);
00250 return pAdr;
00251 #else
00252 return GetProcAddress((HINSTANCE)pLib, CA2W(szFctName));
00253 #endif
00254 #else
00255 return GetProcAddress((HINSTANCE)pLib, szFctName);
00256 #endif
00257 #endif
00258 #ifdef _FEDM_LINUX
00259 return dlsym(pLib, szFctName);
00260 #endif
00261 #else
00262 return NULL;
00263 #endif
00264 }
00265
00266 public:
00267 void* m_pLogger;
00268 void* m_pLib;
00269 void* m_lpfnCreateLogger;
00270 void* m_lpfnDeleteLogger;
00271 void* m_lpfnSetLoggerProp1;
00272 void* m_lpfnSetLoggerProp2;
00273 void* m_lpfnAddLogMessage;
00274 void* m_lpfnAddLogMessageFnc;
00275
00276 };
00277
00278 #endif // !defined(_FEDM_LOGGER_H_INCLUDED_)