void SDL2Manager::init() { #ifdef HAVE_SDL2 bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER) == 0); if (initSuccess) { int joystickCount = SDL_NumJoysticks(); for (int i = 0; i < joystickCount; i++) { SDL_GameController* controller = SDL_GameControllerOpen(i); if (controller) { SDL_JoystickID id = getInstanceId(controller); if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; auto userInputMapper = DependencyManager::get<UserInputMapper>(); joystick->registerToUserInputMapper(*userInputMapper); joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } } _isInitialized = true; } else { qDebug() << "Error initializing SDL2 Manager"; } #endif }
/* * Return the object path for the single instance for this server */ wbem::framework::instance_names_t* wbem::software::ManagementSoftwareIdentityFactory::getInstanceNames() throw (wbem::framework::Exception) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); framework::instance_names_t *pNames = new framework::instance_names_t(); try { m_hostName = m_systemService.getHostName(); framework::attributes_t keys; // Instance ID = "HostSoftware" + host name keys[INSTANCEID_KEY] = framework::Attribute(getInstanceId(), true); // create the object path framework::ObjectPath path(m_hostName, NVM_NAMESPACE, MANAGEMENTSWIDENTITY_CREATIONCLASSNAME, keys); pNames->push_back(path); } catch (framework::Exception &) // clean up and re-throw { delete pNames; throw; } catch (core::LibraryException &e) { delete pNames; throw exception::NvmExceptionLibError(e.getErrorCode()); } return pNames; }
JoystickScriptingInterface::JoystickScriptingInterface() : #ifdef HAVE_SDL2 _openJoysticks(), #endif _isInitialized(false) { #ifdef HAVE_SDL2 bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER) == 0); if (initSuccess) { int joystickCount = SDL_NumJoysticks(); for (int i = 0; i < joystickCount; i++) { SDL_GameController* controller = SDL_GameControllerOpen(i); if (controller) { SDL_JoystickID id = getInstanceId(controller); Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; } } _isInitialized = true; } else { qDebug() << "Error initializing SDL"; } #endif }
TEST(ClientNetworkManager, NetworkInstanceIdIsCorrect) { auto gameObject = new MockNetworkGameObject(); initialClientNetworkGameObject(gameObject); clientGame1->addGameObject(gameObject); CHECK_EQUAL(gameObject, clientManager1->findNetworkGameObject(gameObject->getInstanceId())); }
void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) { #ifdef HAVE_SDL2 if (_isInitialized) { auto userInputMapper = DependencyManager::get<UserInputMapper>(); for (auto joystick : _openJoysticks) { joystick->update(deltaTime, jointsCaptured); } PerformanceTimer perfTimer("SDL2Manager::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; joystick->registerToUserInputMapper(*userInputMapper); joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); userInputMapper->removeDevice(joystick->getDeviceID()); emit joystickRemoved(joystick); } } } #endif }
void JoystickScriptingInterface::update() { #ifdef HAVE_SDL2 if (_isInitialized) { PerformanceTimer perfTimer("JoystickScriptingInterface::update"); SDL_GameControllerUpdate(); SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_CONTROLLERAXISMOTION) { Joystick* joystick = _openJoysticks[event.caxis.which]; if (joystick) { joystick->handleAxisEvent(event.caxis); } } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) { Joystick* joystick = _openJoysticks[event.cbutton.which]; if (joystick) { joystick->handleButtonEvent(event.cbutton); } if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) { // this will either start or stop a global back event QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFBackEvent::startType() : HFBackEvent::endType(); HFBackEvent backEvent(backType); qApp->sendEvent(qApp, &backEvent); } else if (event.cbutton.button == SDL_CONTROLLER_BUTTON_A) { // this will either start or stop a global action event QEvent::Type actionType = (event.type == SDL_CONTROLLERBUTTONDOWN) ? HFActionEvent::startType() : HFActionEvent::endType(); // global action events fire in the center of the screen HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->computeViewPickRay(0.5f, 0.5f)); qApp->sendEvent(qApp, &actionEvent); } } else if (event.type == SDL_CONTROLLERDEVICEADDED) { SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which); SDL_JoystickID id = getInstanceId(controller); Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; emit joystickAdded(joystick); } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); emit joystickRemoved(joystick); } } } #endif }
/* * Retrieve a specific instance given an object path */ wbem::framework::Instance* wbem::software::ManagementSoftwareIdentityFactory::getInstance( framework::ObjectPath &path, framework::attribute_names_t &attributes) throw (wbem::framework::Exception) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); // create the instance, initialize with attributes from the path framework::Instance *pInstance = new framework::Instance(path); try { m_hostName = m_systemService.getHostName(); checkAttributes(attributes); // make sure the instance ID passed in matches this host framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY); if (instanceID.stringValue() == getInstanceId()) { core::Result<core::system::SoftwareInfo> swInfo = m_systemService.getSoftwareInfo(); // ElementName - mgmt sw name + host name if (containsAttribute(ELEMENTNAME_KEY, attributes)) { framework::Attribute a(getElementName(), false); pInstance->setAttribute(ELEMENTNAME_KEY, a, attributes); } // MajorVersion - Mgmt sw major version number if (containsAttribute(MAJORVERSION_KEY, attributes)) { framework::Attribute a(swInfo.getValue().getMgmtSoftwareMajorVersion(), false); pInstance->setAttribute(MAJORVERSION_KEY, a, attributes); } // MinorVersion - Mgmt sw minor version number if (containsAttribute(MINORVERSION_KEY, attributes)) { framework::Attribute a(swInfo.getValue().getMgmtSoftwareMinorVersion(), false); pInstance->setAttribute(MINORVERSION_KEY, a, attributes); } // RevisionNumber - Mgmt sw hotfix number if (containsAttribute(REVISIONNUMBER_KEY, attributes)) { framework::Attribute a(swInfo.getValue().getMgmtSoftwareHotfixVersion(), false); pInstance->setAttribute(REVISIONNUMBER_KEY, a, attributes); } // BuildNumber - Mgmt sw build number if (containsAttribute(BUILDNUMBER_KEY, attributes)) { framework::Attribute a(swInfo.getValue().getMgmtSoftwareBuildVersion(), false); pInstance->setAttribute(BUILDNUMBER_KEY, a, attributes); } // VersionString - Mgmt sw version as a string if (containsAttribute(VERSIONSTRING_KEY, attributes)) { framework::Attribute a(swInfo.getValue().getMgmtSoftwareVersion(), false); pInstance->setAttribute(VERSIONSTRING_KEY, a, attributes); } // Manufacturer - Intel if (containsAttribute(MANUFACTURER_KEY, attributes)) { framework::Attribute a("Intel", false); pInstance->setAttribute(MANUFACTURER_KEY, a, attributes); } // Classifications - 3, "Configuration Software" if (containsAttribute(CLASSIFICATIONS_KEY, attributes)) { framework::UINT16_LIST classifications; classifications.push_back(MANAGEMENTSWIDENTITY_CLASSIFICATIONS_CONFIGSW); framework::Attribute a(classifications, false); pInstance->setAttribute(CLASSIFICATIONS_KEY, a, attributes); } // IsEntity = true if (containsAttribute(ISENTITY_KEY, attributes)) { framework::Attribute a(true, false); pInstance->setAttribute(ISENTITY_KEY, a, attributes); } } else { throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str()); } } catch (framework::Exception &) // clean up and re-throw { delete pInstance; throw; } catch (core::LibraryException &e) { delete pInstance; throw exception::NvmExceptionLibError(e.getErrorCode()); } return pInstance; }
int GmModule::doLogin() { int ok = 0; apLog_Verbose((LOG_CHANNEL, LOG_CONTEXT, "")); if (!hasGmLoginData()) { bLoginOnRegister_ = 1; ok = doRegister(); } else { if (nLoginRequests_ > Apollo::getModuleConfig(MODULE_NAME, "Login/MaxRetries", 1000000000)) { apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "Login/MaxRetries=%d exceeded, giving up", nLoginRequests_)); } else { String sUrl = Apollo::getModuleConfig(MODULE_NAME, "Srpc/Url", ""); if (sUrl.empty()) { apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "Missing Srpc/Url")); } else { Apollo::KeyValueList kvClientInfo; Msg_Core_GetLoadedModules msgCGLM; if (msgCGLM.Request()) { for (Apollo::ValueElem* e = 0; (e = msgCGLM.vlModules.nextElem(e)) != 0; ) { Msg_Core_GetModuleInfo msgCGMI; msgCGMI.sModuleName = e->getString(); if (msgCGMI.Request()) { Apollo::KeyValueElem* e = msgCGMI.kvInfo.find("Version"); if (e) { kvClientInfo.add(msgCGMI.sModuleName, e->getString()); } else { kvClientInfo.add(msgCGMI.sModuleName, ""); } } } } kvClientInfo.add("Instance", getInstanceId()); kvClientInfo.add("Machine", getMachineId()); SrpcMessage srpc; srpc.set(Srpc::Key::Method, GmService_Method_Login); srpc.set("Token", Apollo::getModuleConfig(MODULE_NAME, "Srpc/Token", "8uzxXXZTAmHcni6tK3t-Apollo-3")); srpc.set("User", Apollo::getModuleConfig(MODULE_NAME, "User", "")); srpc.set("Password", getPassword()); srpc.set("Client", kvClientInfo.toString()); LoginClient* pClient = new LoginClient(this); if (pClient != 0) { ok = pClient->Post(sUrl, srpc); if (!ok) { apLog_Error((LOG_CHANNEL, LOG_CONTEXT, "LoginClient::Post(%s) failed", _sz(sUrl))); } else { nLoginRequests_++; } } } // sUrl.empty } // nLoginRequests_ } return ok; }