示例#1
0
/*
#ifdef _WIN32

int CALLBACK WinMain(_In_  HINSTANCE hInstance, _In_  HINSTANCE hPrevInstance, _In_  LPSTR lpCmdLine, _In_  int nCmdShow)
{
  int argc = __argc;
  char** argv = __argv;

#else
*/
int main(int argc, char ** argv)
{
//#endif
  auto logger = spdlog::stderr_color_mt("server");
  logger->set_level(spdlog::level::info);

  try
    {
      const char ** arv = (const char **)argv;
      OpcUa::Server::CommandLine options(argc, arv);

      if (!options.NeedStartServer())
        {
          return 0;
        }

      OpcUa::Daemon daemon;

      if (options.IsDaemonMode())
        {
          daemon.Daemonize(options.GetLogFile());
        }

      Common::AddonsManager::UniquePtr manager = Common::CreateAddonsManager(logger);
      OpcUa::Server::LoadConfiguration(options.GetConfigDir(), *manager);

      manager->Start();
      daemon.WaitForTerminate();
      manager->Stop();

      return 0;
    }

  catch (const std::exception & exc)
    {
      std::cout << exc.what() << std::endl;
    }

  catch (...)
    {
      std::cout << "Unknown error." << std::endl;
    }

  return -1;
}
示例#2
0
int main(int argc, char** argv)
{
  try
  {
    const char** arv = (const char**)argv;
    OpcUa::UaServer::CommandLine options(argc, arv);
    if (!options.NeedStartServer())
    {
      return 0;
    }

    OpcUa::Daemon daemon;
    if (options.IsDaemonMode())
    {
      daemon.Daemonize(options.GetLogFile());
    }

    std::vector<Common::AddonInformation> addons = options.GetModules();
    AddStandardModules(options.GetParameters(), addons);

    OpcUa::Application::UniquePtr application = OpcUa::CreateApplication();
    application->Start(addons);
    daemon.WaitForTerminate();

    application->Stop();
    return 0;
  }
  catch (const std::exception& exc)
  {
    std::cout << exc.what() << std::endl;
  }
  catch (...)
  {
    std::cout << "Unknown error." << std::endl;
  }
  return -1;
}