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
00035
00036
00037
00038
00039
00040
00041 #include <new>
00042
00043 #include "PerformanceLib.h"
00044
00045
00046
00047
00048 #define OPT_DEFINE
00049
00050
00051 #include "OptimizedFunctions.h"
00052
00053
00054 #ifdef WIN32
00055 #include <windows.h>
00056 #elif defined(LOAD_KPP)
00057 #include <dlfcn.h>
00058 #endif
00059
00060 #include <stdio.h>
00061
00062
00063
00064 #ifdef WIN32
00065
00066 #else
00067 CPerformanceLibInitializer performanceLibInitializer;
00068 #endif
00069
00070
00071 #if defined(WIN32)
00072 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = (DefOptimized##name) GetProcAddress(hMod, #name);
00073 #elif defined(LOAD_KPP)
00074 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = (DefOptimized##name) dlsym(m_pLibHandle, #name);
00075 #else
00076
00077 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = 0;
00078 #endif
00079
00080
00081
00082 #undef DECLARE_OPTIMIZED_FUNCTION_0
00083 #undef DECLARE_OPTIMIZED_FUNCTION_1
00084 #undef DECLARE_OPTIMIZED_FUNCTION_2
00085 #undef DECLARE_OPTIMIZED_FUNCTION_3
00086 #undef DECLARE_OPTIMIZED_FUNCTION_4
00087 #undef DECLARE_OPTIMIZED_FUNCTION_5
00088 #undef DECLARE_OPTIMIZED_FUNCTION_5_RET
00089 #undef DECLARE_OPTIMIZED_FUNCTION_8
00090 #undef DECLARE_OPTIMIZED_FUNCTION_9
00091
00092 #define DECLARE_OPTIMIZED_FUNCTION_0(name) LOAD_OPTIMIZED_FUNCTION(name)
00093 #define DECLARE_OPTIMIZED_FUNCTION_1(name, p1) LOAD_OPTIMIZED_FUNCTION(name)
00094 #define DECLARE_OPTIMIZED_FUNCTION_2(name, p1, p2) LOAD_OPTIMIZED_FUNCTION(name)
00095 #define DECLARE_OPTIMIZED_FUNCTION_3(name, p1, p2, p3) LOAD_OPTIMIZED_FUNCTION(name)
00096 #define DECLARE_OPTIMIZED_FUNCTION_4(name, p1, p2, p3, p4) LOAD_OPTIMIZED_FUNCTION(name)
00097 #define DECLARE_OPTIMIZED_FUNCTION_5(name, p1, p2, p3, p4, p5) LOAD_OPTIMIZED_FUNCTION(name)
00098 #define DECLARE_OPTIMIZED_FUNCTION_5_RET(name, p1, p2, p3, p4, p5) LOAD_OPTIMIZED_FUNCTION(name)
00099 #define DECLARE_OPTIMIZED_FUNCTION_8(name, p1, p2, p3, p4, p5, p6, p7, p8) LOAD_OPTIMIZED_FUNCTION(name)
00100 #define DECLARE_OPTIMIZED_FUNCTION_9(name, p1, p2, p3, p4, p5, p6, p7, p8, p9) LOAD_OPTIMIZED_FUNCTION(name)
00101
00102
00103 CPerformanceLibInitializer::CPerformanceLibInitializer() : m_pLibHandle(0)
00104 {
00105 LoadPerformanceLib();
00106 }
00107
00108 CPerformanceLibInitializer::~CPerformanceLibInitializer()
00109 {
00110 FreePerformanceLib();
00111 }
00112
00113 void CPerformanceLibInitializer::LoadPerformanceLib()
00114 {
00115
00116 if (m_pLibHandle != 0)
00117 return;
00118
00119 #if defined(WIN32)
00120 HMODULE hMod = LoadLibrary("KPP.dll");
00121 if (hMod == NULL)
00122 return;
00123 m_pLibHandle = hMod;
00124 #elif defined(LOAD_KPP)
00125 #ifdef __APPLE__
00126 m_pLibHandle = dlopen("libkpp.dylib", RTLD_NOW);
00127 #else
00128 m_pLibHandle = dlopen("libkpp.so", RTLD_NOW);
00129 #endif
00130 if (m_pLibHandle == 0)
00131 return;
00132 #else
00133 return;
00134 #endif
00135
00136
00137
00138 #include "OptimizedFunctionsList.h"
00139
00140
00141 typedef bool (*ActivateFunction) (const char *);
00142 ActivateFunction f = 0;
00143
00144 #ifdef WIN32
00145 f = (ActivateFunction) GetProcAddress(hMod, "Activate");
00146 #elif defined(LOAD_KPP)
00147 f = (ActivateFunction) dlsym(m_pLibHandle, "Activate");
00148 #endif
00149
00150 if (f)
00151 {
00152 printf("info: loaded Keyetech Performance Primitives (KPP)\n");
00153
00154 if (f("license_kpp.txt"))
00155 printf("info: activated KPP with license key\n");
00156 else
00157 {
00158 printf("info: KPP activation with licensey key failed\n");
00159 printf("info: The KPP thus run as a demo version.\n");
00160 }
00161 }
00162 }
00163
00164
00165
00166 #undef DECLARE_OPTIMIZED_FUNCTION_0
00167 #undef DECLARE_OPTIMIZED_FUNCTION_1
00168 #undef DECLARE_OPTIMIZED_FUNCTION_2
00169 #undef DECLARE_OPTIMIZED_FUNCTION_3
00170 #undef DECLARE_OPTIMIZED_FUNCTION_4
00171 #undef DECLARE_OPTIMIZED_FUNCTION_5
00172 #undef DECLARE_OPTIMIZED_FUNCTION_5_RET
00173 #undef DECLARE_OPTIMIZED_FUNCTION_8
00174 #undef DECLARE_OPTIMIZED_FUNCTION_9
00175
00176 #define DECLARE_OPTIMIZED_FUNCTION_0(name) Optimized##name = 0;
00177 #define DECLARE_OPTIMIZED_FUNCTION_1(name, p1) Optimized##name = 0;
00178 #define DECLARE_OPTIMIZED_FUNCTION_2(name, p1, p2) Optimized##name = 0;
00179 #define DECLARE_OPTIMIZED_FUNCTION_3(name, p1, p2, p3) Optimized##name = 0;
00180 #define DECLARE_OPTIMIZED_FUNCTION_4(name, p1, p2, p3, p4) Optimized##name = 0;
00181 #define DECLARE_OPTIMIZED_FUNCTION_5(name, p1, p2, p3, p4, p5) Optimized##name = 0;
00182 #define DECLARE_OPTIMIZED_FUNCTION_5_RET(name, p1, p2, p3, p4, p5) Optimized##name = 0;
00183 #define DECLARE_OPTIMIZED_FUNCTION_8(name, p1, p2, p3, p4, p5, p6, p7, p8) Optimized##name = 0;
00184 #define DECLARE_OPTIMIZED_FUNCTION_9(name, p1, p2, p3, p4, p5, p6, p7, p8, p9) Optimized##name = 0;
00185
00186 void CPerformanceLibInitializer::FreePerformanceLib()
00187 {
00188 if (m_pLibHandle != 0)
00189 {
00190 #if defined(WIN32)
00191 HMODULE hMod = (HMODULE) m_pLibHandle;
00192 FreeLibrary(hMod);
00193 #elif defined(LOAD_KPP)
00194 dlclose(m_pLibHandle);
00195 #endif
00196
00197 m_pLibHandle = 0;
00198 }
00199
00200
00201
00202 #include "OptimizedFunctionsList.h"
00203 }