void AddonsManagerTestCase::TestOneManager()
{
  InitializedAddonsCount = 0;

  Common::AddonInformation dmConfig;
  dmConfig.Id = DeviceManager::ManagerId;
  dmConfig.Factory = Common::AddonFactory::UniquePtr(new DeviceIOManagerFactory);
  dmConfig.Dependencies = std::vector<Common::AddonId>(1, PropertyTree::ManagerId);
  CPPUNIT_ASSERT_NO_THROW(Addons->Register(dmConfig));

  Common::AddonInformation ptConfig;
  ptConfig.Id = PropertyTree::ManagerId;
  ptConfig.Factory = Common::AddonFactory::UniquePtr(new PropertyTreeAddonFactory);
  CPPUNIT_ASSERT_NO_THROW(Addons->Register(ptConfig));

  CPPUNIT_ASSERT_NO_THROW(Addons->Start(/*Common::AddonsConfiguration()*/));
  CPPUNIT_ASSERT_THROW(Addons->Start(/*Common::AddonsConfiguration()*/), Common::Error);

  std::shared_ptr<PropertyTreeAddon> propertyTree;
  CPPUNIT_ASSERT_NO_THROW(propertyTree = Common::GetAddon<PropertyTreeAddon>(*Addons, PropertyTree::ManagerId));
  CPPUNIT_ASSERT(propertyTree);
  CPPUNIT_ASSERT(propertyTree->IsInitialized());
  
  CPPUNIT_ASSERT_NO_THROW(Addons->Stop());
  CPPUNIT_ASSERT(propertyTree->IsStopped());

  CPPUNIT_ASSERT_THROW(Addons->Stop(), Common::Error);
}
Пример #2
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;
}