9#include <nv/index/iindex.h>
12#include <nv/index/app/forwarding_logger.h>
13#include <nv/index/app/iapplication_layer.h>
14#include <nv/index/app/iapplication_layer_plugin.h>
15#include <nv/index/app/iapplication_layer_component.h>
16#include <nv/index/app/istring_dict.h>
21#ifndef MI_PLATFORM_WINDOWS
23#include <netinet/in.h>
38void exit_with_fail_message(
const char* msg,
const char* filename,
int line)
40 fprintf(stderr,
"Error in file %s, line %d: \"%s\".\n", filename, line, msg);
46#define check_success(expr) \
47 { if (!(expr)) { exit_with_fail_message(#expr, __FILE__, __LINE__); } }
51template <
class Interface>
52Interface* load_and_get_interface(
53 const std::string& lib_file_basename,
54 const std::string& lib_symbol_name)
56#ifdef MI_PLATFORM_WINDOWS
59 const std::string lib_file_name = lib_file_basename +
".dll";
61 void* handle = LoadLibrary(TEXT(lib_file_name.c_str()));
64 printf(
"error: Could not retrieve a handle to the %s library\n", lib_file_name.c_str());
67 void* symbol = GetProcAddress((HMODULE)handle, lib_symbol_name.c_str());
70 printf(
"error: Could not retrieve the entry point into the %s library\n", lib_file_name.c_str());
76 const std::string lib_file_name = lib_file_basename +
".so";
77 void* handle = dlopen(lib_file_name.c_str(),
RTLD_LAZY);
80 printf(
"error: iindex: handle: %s\n", dlerror());
84 void* symbol = dlsym(handle, lib_symbol_name.c_str());
87 printf(
"error: iindex: symbol: %s\n", dlerror());
92 return nv::index::nv_factory<Interface>(symbol);
97void initialize_log_module(nv::index::IIndex* iindex)
101 mi::base::Handle<mi::neuraylib::ILogging_configuration> logging_configuration(
102 iindex->get_api_component<mi::neuraylib::ILogging_configuration>());
106 logging_configuration->set_log_locally(
true);
113 logging_configuration->set_log_level(mi::base:
:MESSAGE_SEVERITY_VERBOSE);
114 logging_configuration->set_log_level_by_category(
"ALL", mi::base:
:MESSAGE_SEVERITY_VERBOSE);
115 INFO_LOG <<
"Set logging level to " << mi::base:
:MESSAGE_SEVERITY_VERBOSE;
120void configure_application_layer(nv::index::app::IApplication_layer* application_layer)
126 mi::base::Handle<nv::index::app::IString_dict> config(
127 application_layer->create<nv::index::app::IString_dict>());
128 const mi::Sint32 ret = application_layer->set_configuration(config.get());
129 INFO_LOG <<
"RET: " << ret;
136void load_application_layer_components(nv::index::app::IApplication_layer* application_layer)
141 const char* component_dso_basename_vec[] = {
142 "libnvindex_application_layer_example_template_component",
143 "libnvindex_application_layer_canvas_infrastructure",
144 "libnvindex_application_layer_canvas_infrastructure_opengl",
145 "libnvindex_application_layer_command_database",
146 "libnvindex_application_layer_command_replay",
147 "libnvindex_application_layer_html5_integration",
148 "libnvindex_application_layer_scene_management_center",
153 for (mi::Size i = 0; component_dso_basename_vec[i] != 0; ++i)
155 const std::string dso_basename = component_dso_basename_vec[i];
156 const bool is_loaded = application_layer->load_application_layer_component(dso_basename.c_str());
159 nv::index::app::IApplication_layer_component* component
160 = application_layer->get_application_layer_component(dso_basename.c_str());
162 INFO_LOG <<
"Loaded NVIDIA IndeX application layer component: " << dso_basename
163 <<
" (" << component->get_component_name() <<
")";
166 mi::base::Handle<nv::index::app::IString_dict> config(
167 application_layer->create<nv::index::app::IString_dict>());
170 const bool is_ok = component->set_configuration(config.get());
177 check_success (application_layer->is_application_layer_component_registered(
"libnvindex_application_layer_scene_management_center"));
180 check_success (!application_layer->is_application_layer_component_registered(
"libnvindex_application_layer_io"));
183 check_success(application_layer->load_application_layer_component(
"libnvindex_application_layer_io"));
186 check_success (application_layer->is_application_layer_component_registered(
"libnvindex_application_layer_io"));
191void load_application_layer_plugins(nv::index::app::IApplication_layer* application_layer)
195 const char* plugin_dso_basename_vec[] = {
196 "libnvindex_plugin_advanced_stats",
197 "libnvindex_plugin_base_importer",
202 for (mi::Size i = 0; plugin_dso_basename_vec[i] != 0; ++i)
204 const std::string dso_basename = plugin_dso_basename_vec[i];
205 const bool is_loaded = application_layer->load_application_layer_plugin(dso_basename.c_str());
208 nv::index::app::IApplication_layer_plugin* plugin
209 = application_layer->get_application_layer_plugin(dso_basename.c_str());
211 INFO_LOG <<
"Loaded NVIDIA IndeX application layer plugin: " << dso_basename
212 <<
" (" << plugin->get_plugin_name() <<
")";
215 mi::base::Handle<nv::index::app::IString_dict> config(
216 application_layer->create<nv::index::app::IString_dict>());
219 const bool is_ok = plugin->set_configuration(config.get());
226 check_success (application_layer->is_application_layer_plugin_registered(
"libnvindex_plugin_base_importer"));
229 check_success (!application_layer->is_application_layer_plugin_registered(
"libnvindex_plugin_example_template"));
232 check_success(application_layer->load_application_layer_plugin(
"libnvindex_plugin_example_template"));
235 check_success (application_layer->is_application_layer_plugin_registered(
"libnvindex_plugin_example_template"));
241int main(
int argc,
char* argv[])
244 const std::string index_lib_basename =
"libnvindex";
245 const std::string index_lib_symbol_name =
"nv_factory";
246 mi::base::Handle<nv::index::IIndex> iindex(
247 load_and_get_interface<nv::index::IIndex>(index_lib_basename, index_lib_symbol_name));
251 const std::string applayer_lib_basename =
"libnvindex_application_layer_application_layer";
252 const std::string applayer_lib_symbol_name =
"nvindex_application_layer_application_layer_factory";
253 mi::base::Handle<nv::index::app::IApplication_layer> applayer(
254 load_and_get_interface<nv::index::app::IApplication_layer>(
255 applayer_lib_basename, applayer_lib_symbol_name));
259 initialize_log_module(iindex.get());
260 INFO_LOG <<
"NVIDIA IndeX version: "<< iindex->get_version();
263 applayer->initialize(iindex.get());
266 configure_application_layer(applayer.get());
269 load_application_layer_components(applayer.get());
272 load_application_layer_plugins(applayer.get());
275 const mi::Sint32 index_ret = iindex->start();
277 INFO_LOG <<
"IndeX service has been started.";
281 const mi::Sint32 applayer_ret = applayer->start();
283 INFO_LOG <<
"Application_layer service has been started.";
287 INFO_LOG <<
"shutdown application_layer";
288 applayer->shutdown();
289 applayer->deinitialize();
294 mi::base::Handle< mi::neuraylib::ILogging_configuration > logging_configuration(
295 iindex->get_api_component< mi::neuraylib::ILogging_configuration >());
297 logging_configuration->set_receiving_logger(0);
301 mi::Sint32 index_shutdown = iindex->shutdown();
302 if (index_shutdown != 0)
304 fprintf(stderr,
"error: failed NVIDIA IndeX shutdown (code: %d)\n", index_shutdown);
int main(int argc, char *argv[])
#define check_success(expr)