NIM PC Cross Platform SDK
载入中...
搜索中...
未找到
nim_sdk_util.h
浏览该文件的文档.
1
7#ifndef _NIM_SDK_CPP_NIM_SDK_UTIL_H_
8#define _NIM_SDK_CPP_NIM_SDK_UTIL_H_
9
10#include <functional>
11#include <list>
12#include <map>
13#include <string>
14#include "assert.h"
15#ifdef WIN32
16#include "wtypes.h"
17#else
18#include <dlfcn.h>
19#endif
20
28 BS_TRUE = 1
29};
34namespace nim {
39public:
41 virtual ~SDKInstance();
42
44 bool LoadSdkDll(const char* cur_module_dir, const char* sdk_dll_file_name);
45
47 void UnLoadSdkDll();
48
50 void OnSDKInited();
51
53 void* GetFunction(const std::string& function_name) {
54 void* function_ptr = nullptr;
55 auto it = function_map.find(function_name);
56 if (it != function_map.end()) {
57 function_ptr = it->second;
58 } else {
59 function_ptr = get_proc_address_wrapper_ == nullptr ? nullptr : get_proc_address_wrapper_(function_name.c_str());
60 if (function_ptr)
61 function_map[function_name] = function_ptr;
62 }
63 assert(function_ptr);
64 return function_ptr;
65 }
66
67private:
68#ifdef WIN32
69 HINSTANCE instance_nim_;
70#else
72#endif
73
74 std::map<std::string, void*> function_map;
75 std::function<void*(const std::string&)> get_proc_address_wrapper_;
76};
77
78static void nim_print_unfound_func_name(const char* name) {
79 printf("function [ %s ] not found \n", name);
80}
81
83
84} // namespace nim
85
86#define NIM_SDK_GET_FUNC_FROM_INSTANCE(instance, function_ptr) \
87 (instance != nullptr && (((function_ptr)instance->GetFunction(#function_ptr)) != nullptr) \
88 ? ((function_ptr)instance->GetFunction(#function_ptr)) \
89 : (nim::nim_print_unfound_func_name(#function_ptr), (function_ptr)nim::unfound_function_holder))
90
91#endif //_NIM_SDK_CPP_NIM_SDK_UTIL_H_
SDK库辅助类,提供加载/卸载SDK库以及获取接口的方法
Definition: nim_sdk_util.h:38
void * GetFunction(const std::string &function_name)
Definition: nim_sdk_util.h:53
std::map< std::string, void * > function_map
Definition: nim_sdk_util.h:74
SDKInstance()
Definition: nim_sdk_util.cpp:16
std::function< void *(const std::string &)> get_proc_address_wrapper_
Definition: nim_sdk_util.h:75
void UnLoadSdkDll()
Definition: nim_sdk_util.cpp:62
void OnSDKInited()
Definition: nim_sdk_util.cpp:76
virtual ~SDKInstance()
Definition: nim_sdk_util.cpp:24
void * instance_nim_
Definition: nim_sdk_util.h:71
bool LoadSdkDll(const char *cur_module_dir, const char *sdk_dll_file_name)
Definition: nim_sdk_util.cpp:28
namespace nim
static void nim_print_unfound_func_name(const char *name)
Definition: nim_sdk_util.h:78
static void unfound_function_holder()
Definition: nim_sdk_util.h:82
BoolStatus
Definition: nim_sdk_util.h:22
@ BS_TRUE
true
Definition: nim_sdk_util.h:28
@ BS_NOT_INIT
未初始化
Definition: nim_sdk_util.h:24
@ BS_FALSE
false
Definition: nim_sdk_util.h:26