GameBase::GameBase(Logger &inlog, const std::optional<RWArgConfigLayer> &args) : log(inlog), config(buildConfig(args)) { log.info("Game", "Build: " + kBuildStr); bool fullscreen = config.fullscreen(); size_t w = config.width(), h = config.height(); if (SDL_Init(SDL_INIT_VIDEO) < 0) throw std::runtime_error("Failed to initialize SDL2!"); window.create(kWindowTitle + " [" + kBuildStr + "]", w, h, fullscreen); SET_RW_ABORT_CB([this]() {window.showCursor();}, [this]() {window.hideCursor();}); }
void CompositeMessageTest::testCompositeMessage() { ::fwServices::registry::ActiveWorkers::sptr activeWorkers = ::fwServices::registry::ActiveWorkers::getDefault(); activeWorkers->initRegistry(); const std::string objAUUID = "imageUUID"; const std::string service1UUID = "service1UUID"; const std::string service2UUID = "service2UUID"; // build composite ::fwRuntime::ConfigurationElement::sptr config = buildConfig() ; // Create the object and its services from the configuration ::fwServices::AppConfigManager::sptr configManager = ::fwServices::AppConfigManager::New(); configManager->setConfig( config ); configManager->create(); ::fwData::Composite::sptr compo = configManager->getConfigRoot< ::fwData::Composite >(); ::fwData::Object::sptr image = compo->getContainer()[objAUUID]; // get service 1 ::fwComEd::ut::TestService::sptr serviceCompo; serviceCompo = ::fwComEd::ut::TestService::dynamicCast( ::fwServices::get(service1UUID) ); CPPUNIT_ASSERT(serviceCompo); // get service 2 ::fwComEd::ut::TestService::sptr serviceCompo2; serviceCompo2 = ::fwComEd::ut::TestService::dynamicCast( ::fwServices::get(service2UUID) ); CPPUNIT_ASSERT(serviceCompo2); // start services configManager->start(); CPPUNIT_ASSERT(serviceCompo->isStarted()); CPPUNIT_ASSERT(serviceCompo2->isStarted()); // register communication channel ::fwServices::helper::SigSlotConnection::sptr helper = ::fwServices::helper::SigSlotConnection::New(); helper->connect( compo, serviceCompo, serviceCompo->getObjSrvConnections() ); helper->connect( compo, serviceCompo2, serviceCompo2->getObjSrvConnections() ); ::fwComEd::CompositeMsg::sptr compoMsg; compoMsg = ::fwComEd::CompositeMsg::New(); compoMsg->appendAddedKey(objAUUID, image); ::fwServices::IEditionService::notify(serviceCompo2, compo, compoMsg); // Wait a little notification system ::boost::this_thread::sleep_for( ::boost::chrono::milliseconds(500) ); // test message is received CPPUNIT_ASSERT(serviceCompo->getIsUpdatedMessage()); CPPUNIT_ASSERT(!serviceCompo2->getIsUpdatedMessage()); CPPUNIT_ASSERT_EQUAL(::fwComEd::CompositeMsg::ADDED_KEYS, serviceCompo->getMessageEvent()); ::fwData::Composite::sptr addedKeys = compoMsg->getAddedKeys(); CPPUNIT_ASSERT((*addedKeys).find(objAUUID) != (*addedKeys).end()); CPPUNIT_ASSERT_EQUAL(image, (*addedKeys)[objAUUID]); ::fwData::Object::sptr newImage = ::fwData::Image::New(); compoMsg = ::fwComEd::CompositeMsg::New(); compoMsg->appendChangedKey(objAUUID, image, newImage); ::fwServices::IEditionService::notify(serviceCompo2, compo, compoMsg); // Wait a little notification system ::boost::this_thread::sleep_for( ::boost::chrono::milliseconds(500) ); // test message is received CPPUNIT_ASSERT(serviceCompo->getIsUpdatedMessage()); CPPUNIT_ASSERT(!serviceCompo2->getIsUpdatedMessage()); CPPUNIT_ASSERT_EQUAL(::fwComEd::CompositeMsg::CHANGED_KEYS, serviceCompo->getMessageEvent()); ::fwData::Composite::sptr oldChangedKeys = compoMsg->getOldChangedKeys(); ::fwData::Composite::sptr newChangedKeys = compoMsg->getNewChangedKeys(); CPPUNIT_ASSERT((*oldChangedKeys).find(objAUUID) != (*oldChangedKeys).end() ); CPPUNIT_ASSERT_EQUAL(image, (*oldChangedKeys)[objAUUID]); CPPUNIT_ASSERT((*newChangedKeys).find(objAUUID) != (*newChangedKeys).end() ); CPPUNIT_ASSERT_EQUAL(newImage, (*newChangedKeys)[objAUUID]); compoMsg = ::fwComEd::CompositeMsg::New(); compoMsg->appendRemovedKey(objAUUID, image); ::fwServices::IEditionService::notify(serviceCompo2, compo, compoMsg); // Wait a little notification system ::boost::this_thread::sleep_for( ::boost::chrono::milliseconds(500) ); // test message is received CPPUNIT_ASSERT(serviceCompo->getIsUpdatedMessage()); CPPUNIT_ASSERT(!serviceCompo2->getIsUpdatedMessage()); CPPUNIT_ASSERT_EQUAL(::fwComEd::CompositeMsg::REMOVED_KEYS, serviceCompo->getMessageEvent()); ::fwData::Composite::sptr removedKeys = compoMsg->getRemovedKeys(); CPPUNIT_ASSERT((*removedKeys).find(objAUUID) != (*removedKeys).end()); CPPUNIT_ASSERT_EQUAL(image, (*removedKeys)[objAUUID]); // unregister communication channel helper->disconnect(); helper.reset(); // stop services configManager->stopAndDestroy(); activeWorkers->clearRegistry(); }