12 #include "uaplatformlayer.h" 22 #include "xmldocument.h" 29 #include <boost/program_options.hpp> 44 int OpcServerMain(
const char* szAppPath,
const char *p_sServerConfig,
const char *p_sDeviceConfig)
47 UaString sDeviceConfig;
51 UaXmlDocument::initParser();
53 ret = UaPlatformLayer::init();
59 UaString sConfigFileName;
62 if (p_sServerConfig) {
65 sConfigFileName = p_sServerConfig;
68 sConfigFileName = szAppPath;
69 sConfigFileName +=
"/ServerConfig.xml";
72 if (p_sDeviceConfig) {
74 sDeviceConfig = p_sDeviceConfig;
78 sDeviceConfig = szAppPath;
79 sDeviceConfig +=
"/OPCUACANOpenServer.xml";
93 pServer->setServerConfig(sConfigFileName, szAppPath);
101 cout <<
"Load Configuration" << endl;
103 cout <<
"Config file " << sDeviceConfig.toUtf8() << endl;
105 cout <<
"Set Server Config " << sConfigFileName.toUtf8() << endl;
106 cout <<
"Create Interface" << endl;
110 if (pControlInterface->CreateXmlParser(sDeviceConfig).isBad())
112 cout <<
"Parser error" << endl;
116 UaString sNodesetFile(UaString(
"%1/AddressSpace.xml").arg(szAppPath));
118 UaBase::BaseNodeFactory* pBaseNodeFactory =
new UaBase::BaseNodeFactory;
121 UaNodeSetXmlParserUaNode* pXmlParser =
new UaNodeSetXmlParserUaNode(sNodesetFile, pNodeManagerCreator, pBaseNodeFactory, NULL);
123 pServer->addModule(pXmlParser);
127 if (pMyNodeManager == 0)
129 cout <<
"Could not Create Node Manager" << endl;
132 ret =
pServer->addNodeManager(pMyNodeManager);
135 cout <<
"Could not Create Node Manager" << endl;
140 cout <<
"Start Server" << endl;
147 cout <<
"Server Could not start" << endl;
153 cout <<
"***************************************************" << endl;
155 cout <<
"***************************************************" << endl;
159 UaThread::msleep(1000);
161 cout <<
"***************************************************" << endl;
163 cout <<
" Shutting down server" << endl;
164 cout <<
"***************************************************" << endl;
181 cout <<
"Server stopped" << endl;
184 UaXmlDocument::cleanupParser();
194 int main(
int argc,
char* argv[])
199 const char *pDeviceConfig = 0;
200 const char *pServerConfig = 0;
208 char szAppPath[MAX_PATH];
209 memset(szAppPath, 0,
sizeof szAppPath);
210 GetModuleFileNameA(NULL, szAppPath, MAX_PATH);
211 szAppPath[MAX_PATH-1] = 0;
212 pszFind = strrchr(szAppPath,
'\\');
214 char szAppPath[PATH_MAX];
215 memset( szAppPath, 0,
sizeof szAppPath );
216 readlink(
"/proc/self/exe", szAppPath,
sizeof(szAppPath));
217 szAppPath[PATH_MAX-1] = 0;
218 pszFind = strrchr(szAppPath,
'/');
227 bool printVersion =
false;
229 options_description desc (
"Allowed options");
232 (
"config_file",
"A path to the config file")
233 (
"server_config",
"server config files")
235 (
"help",
"Print help")
236 (
"noex", bool_switch(&
noExit),
"no Exit if cannot open canbus")
238 (
"version", bool_switch(&printVersion),
"Print version and exit")
240 positional_options_description p;
241 p.add(
"config_file", 1);
242 p.add(
"server_config", 2);
247 store(command_line_parser(argc,argv)
249 .style(command_line_style::allow_long_disguise | command_line_style::unix_style)
256 cout <<
"Couldn't interpret command line, please run with -help " << endl ;
260 if (vm.count(
"help"))
262 cout << desc << endl;
274 if (vm.count(
"config_file") > 0)
275 pDeviceConfig = vm[
"config_file"].as< string > ().c_str();
276 if (vm.count(
"server_config") > 0)
277 pServerConfig = vm[
"server_config"].as< string >().c_str();
286 UaPlatformLayer::cleanup();