PerformanceLib.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: PerformanceLib.cpp
37 // Author: Florian Hecht
38 // Date: 2008
39 // ****************************************************************************
40 
41 #include <new> // for explicitly using correct new/delete operators on VC DSPs
42 
43 #include "PerformanceLib.h"
44 
45 
46 // this is needed so that the function pointers are not declared extern
47 // and are defined here
48 #define OPT_DEFINE
49 
50 // include all the function prototypes and function pointers
51 #include "OptimizedFunctions.h"
52 
53 // include the necessary headers to load a dynamic library
54 #ifdef WIN32
55 #include <windows.h>
56 #elif defined(LOAD_KPP)
57 #include <dlfcn.h>
58 #endif
59 
60 #include <stdio.h>
61 
62 // this is the only instance that should be created ever
63 // it's global so it executes before the main function
64 #ifdef WIN32
65 //CPerformanceLibInitializer performanceLibInitializer; // activate this line under Windows to automatically load the KPP
66 #else
68 #endif
69 
70 
71 #if defined(WIN32)
72 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = (DefOptimized##name) GetProcAddress(hMod, #name);
73 #elif defined(LOAD_KPP)
74 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = (DefOptimized##name) dlsym(m_pLibHandle, #name);
75 #else
76 // dummy
77 #define LOAD_OPTIMIZED_FUNCTION(name) Optimized##name = 0;
78 #endif
79 
80 // these macros load a function from the shared library
81 // different macros for different number of parameters
82 #undef DECLARE_OPTIMIZED_FUNCTION_0
83 #undef DECLARE_OPTIMIZED_FUNCTION_1
84 #undef DECLARE_OPTIMIZED_FUNCTION_2
85 #undef DECLARE_OPTIMIZED_FUNCTION_3
86 #undef DECLARE_OPTIMIZED_FUNCTION_4
87 #undef DECLARE_OPTIMIZED_FUNCTION_5
88 #undef DECLARE_OPTIMIZED_FUNCTION_5_RET
89 #undef DECLARE_OPTIMIZED_FUNCTION_8
90 #undef DECLARE_OPTIMIZED_FUNCTION_9
91 
92 #define DECLARE_OPTIMIZED_FUNCTION_0(name) LOAD_OPTIMIZED_FUNCTION(name)
93 #define DECLARE_OPTIMIZED_FUNCTION_1(name, p1) LOAD_OPTIMIZED_FUNCTION(name)
94 #define DECLARE_OPTIMIZED_FUNCTION_2(name, p1, p2) LOAD_OPTIMIZED_FUNCTION(name)
95 #define DECLARE_OPTIMIZED_FUNCTION_3(name, p1, p2, p3) LOAD_OPTIMIZED_FUNCTION(name)
96 #define DECLARE_OPTIMIZED_FUNCTION_4(name, p1, p2, p3, p4) LOAD_OPTIMIZED_FUNCTION(name)
97 #define DECLARE_OPTIMIZED_FUNCTION_5(name, p1, p2, p3, p4, p5) LOAD_OPTIMIZED_FUNCTION(name)
98 #define DECLARE_OPTIMIZED_FUNCTION_5_RET(name, p1, p2, p3, p4, p5) LOAD_OPTIMIZED_FUNCTION(name)
99 #define DECLARE_OPTIMIZED_FUNCTION_8(name, p1, p2, p3, p4, p5, p6, p7, p8) LOAD_OPTIMIZED_FUNCTION(name)
100 #define DECLARE_OPTIMIZED_FUNCTION_9(name, p1, p2, p3, p4, p5, p6, p7, p8, p9) LOAD_OPTIMIZED_FUNCTION(name)
101 
102 
104 {
106 }
107 
109 {
111 }
112 
114 {
115  // only load once
116  if (m_pLibHandle != 0)
117  return;
118 
119  #if defined(WIN32)
120  HMODULE hMod = LoadLibrary("KPP.dll");
121  if (hMod == NULL)
122  return;
123  m_pLibHandle = hMod;
124  #elif defined(LOAD_KPP)
125  #ifdef __APPLE__
126  m_pLibHandle = dlopen("libkpp.dylib", RTLD_NOW);
127  #else
128  m_pLibHandle = dlopen("libkpp.so", RTLD_NOW);
129  #endif
130  if (m_pLibHandle == 0)
131  return;
132  #else
133  return;
134  #endif
135 
136  // this include will generate the necessary loading functions
137  // due to the DECLARE_OPTIMIZED_FUNCTION_x macros
138  #include "OptimizedFunctionsList.h"
139 
140  // activate with license key
141  typedef bool (*ActivateFunction) (const char *);
142  ActivateFunction f = 0;
143 
144  #ifdef WIN32
145  f = (ActivateFunction) GetProcAddress(hMod, "Activate");
146  #elif defined(LOAD_KPP)
147  f = (ActivateFunction) dlsym(m_pLibHandle, "Activate");
148  #endif
149 
150  if (f)
151  {
152  printf("info: loaded Keyetech Performance Primitives (KPP)\n");
153 
154  if (f("license_kpp.txt"))
155  printf("info: activated KPP with license key\n");
156  else
157  {
158  printf("info: KPP activation with licensey key failed\n");
159  printf("info: The KPP thus run as a demo version.\n");
160  }
161  }
162 }
163 
164 
165 // these macros clear the function pointers
166 #undef DECLARE_OPTIMIZED_FUNCTION_0
167 #undef DECLARE_OPTIMIZED_FUNCTION_1
168 #undef DECLARE_OPTIMIZED_FUNCTION_2
169 #undef DECLARE_OPTIMIZED_FUNCTION_3
170 #undef DECLARE_OPTIMIZED_FUNCTION_4
171 #undef DECLARE_OPTIMIZED_FUNCTION_5
172 #undef DECLARE_OPTIMIZED_FUNCTION_5_RET
173 #undef DECLARE_OPTIMIZED_FUNCTION_8
174 #undef DECLARE_OPTIMIZED_FUNCTION_9
175 
176 #define DECLARE_OPTIMIZED_FUNCTION_0(name) Optimized##name = 0;
177 #define DECLARE_OPTIMIZED_FUNCTION_1(name, p1) Optimized##name = 0;
178 #define DECLARE_OPTIMIZED_FUNCTION_2(name, p1, p2) Optimized##name = 0;
179 #define DECLARE_OPTIMIZED_FUNCTION_3(name, p1, p2, p3) Optimized##name = 0;
180 #define DECLARE_OPTIMIZED_FUNCTION_4(name, p1, p2, p3, p4) Optimized##name = 0;
181 #define DECLARE_OPTIMIZED_FUNCTION_5(name, p1, p2, p3, p4, p5) Optimized##name = 0;
182 #define DECLARE_OPTIMIZED_FUNCTION_5_RET(name, p1, p2, p3, p4, p5) Optimized##name = 0;
183 #define DECLARE_OPTIMIZED_FUNCTION_8(name, p1, p2, p3, p4, p5, p6, p7, p8) Optimized##name = 0;
184 #define DECLARE_OPTIMIZED_FUNCTION_9(name, p1, p2, p3, p4, p5, p6, p7, p8, p9) Optimized##name = 0;
185 
187 {
188  if (m_pLibHandle != 0)
189  {
190  #if defined(WIN32)
191  HMODULE hMod = (HMODULE) m_pLibHandle;
192  FreeLibrary(hMod);
193  #elif defined(LOAD_KPP)
194  dlclose(m_pLibHandle);
195  #endif
196 
197  m_pLibHandle = 0;
198  }
199 
200  // this include will generate the necessary clear operations
201  // due to the DECLARE_OPTIMIZED_FUNCTION_x macros
202  #include "OptimizedFunctionsList.h"
203 }
CPerformanceLibInitializer performanceLibInitializer


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28