MCPcopy Create free account
hub / github.com/OSVR/OSVR-Core / configureServerFromFile

Function configureServerFromFile

inc/osvr/Server/ConfigureServerFromFile.h:67–166  ·  view source on GitHub ↗

@brief This is the basic common code of a server app's setup, ripped out of the main server app to make alternate server-acting apps simpler to develop.

Source from the content-addressed store, hash-verified

65 /// of the main server app to make alternate server-acting apps simpler to
66 /// develop.
67 inline ServerPtr configureServerFromFile(std::string const &configName) {
68 using detail::out;
69 using detail::err;
70 using std::endl;
71 ServerPtr ret;
72 out << "Using config file '" << configName << "'" << endl;
73 std::ifstream config(configName);
74 if (!config.good()) {
75 err << "\n"
76 << "Could not open config file!" << endl;
77 err << "Searched in the current directory; file may be "
78 "misspelled, missing, or in a different directory." << endl;
79 return nullptr;
80 }
81
82 osvr::server::ConfigureServer srvConfig;
83 out << "Constructing server as configured..." << endl;
84 try {
85 srvConfig.loadConfig(config);
86 ret = srvConfig.constructServer();
87 } catch (std::exception &e) {
88 err << "Caught exception constructing server from JSON config "
89 "file: " << e.what() << endl;
90 return nullptr;
91 }
92
93 {
94 out << "Loading auto-loadable plugins..." << endl;
95 srvConfig.loadAutoPlugins();
96 }
97
98 {
99 out << "Loading plugins..." << endl;
100 srvConfig.loadPlugins();
101 if (!srvConfig.getSuccessfulPlugins().empty()) {
102 out << "Successful plugins:" << endl;
103 for (auto const &plugin : srvConfig.getSuccessfulPlugins()) {
104 out << " - " << plugin << endl;
105 }
106 out << "\n";
107 }
108 if (!srvConfig.getFailedPlugins().empty()) {
109 out << "Failed plugins:" << endl;
110 for (auto const &pluginError : srvConfig.getFailedPlugins()) {
111 out << " - " << pluginError.first << "\t"
112 << pluginError.second << endl;
113 }
114 out << "\n";
115 }
116
117 out << "\n";
118 }
119
120 {
121 out << "Instantiating configured drivers..." << endl;
122 bool success = srvConfig.instantiateDrivers();
123 if (!srvConfig.getSuccessfulInstantiations().empty()) {
124 out << "Successes:" << endl;

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 11

loadConfigMethod · 0.80
constructServerMethod · 0.80
instantiateDriversMethod · 0.80
processRoutesMethod · 0.80
processAliasesMethod · 0.80
processDisplayMethod · 0.80
loadAutoPluginsMethod · 0.45
loadPluginsMethod · 0.45
emptyMethod · 0.45
triggerHardwareDetectMethod · 0.45

Tested by

no test coverage detected