Result PluginInstance::currentResult() { Result resReturn = defaultResult(); if(m_mtxCycleResults.try_lock()) { resReturn = m_resCycleResult; m_resCycleResult = defaultResult(); m_mtxCycleResults.unlock(); } return resReturn; }
// A default run method TestResult* TestCase::run() { TestResult* result = defaultResult(); run(result); return result; }
Result PLUGIN_CLASS::deinit() { Result resReturn = defaultResult(); for(InteractiveObject* ioDelete : m_lstInteractiveObjects) { delete ioDelete; } return resReturn; }
PluginInstance::PluginInstance() { m_strName = ""; m_vdLibHandle = NULL; m_piInstance = NULL; m_thrdPluginCycle = NULL; m_bRunCycle = true; m_resCycleResult = defaultResult(); this->setMessagePrefixLabel("plugin-instance"); }
Result PluginInstance::loadPluginLibrary(std::string strFilepath) { Result resLoad = defaultResult(); std::fstream fsFile; fsFile.open(strFilepath.c_str(), std::fstream::in); if(fsFile.is_open()) { fsFile.close(); m_vdLibHandle = dlopen(strFilepath.c_str(), RTLD_LAZY); if(m_vdLibHandle) { plugins::Plugin* (*createInstance)(); createInstance = (plugins::Plugin* (*)())dlsym(m_vdLibHandle, "createInstance"); m_piInstance = (plugins::Plugin*)createInstance(); m_strName = strFilepath; // Remove path const size_t last_slash_idx = m_strName.find_last_of("\\/"); if(std::string::npos != last_slash_idx) { m_strName.erase(0, last_slash_idx + 1); } // Remove extension const size_t period_idx = m_strName.rfind('.'); if(std::string::npos != period_idx) { m_strName.erase(period_idx); } // Remove plugin prefix std::string strPrefix = "libsr_plugin_"; m_strName = m_strName.substr(strPrefix.size()); std::string strVersionString = m_piInstance->pluginVersion(); this->info("Loaded plugin '" + m_strName + "'" + (strVersionString == "" ? "" : " (version: " + strVersionString + ")")); m_piInstance->setPluginName(m_strName); if(m_piInstance->isDeprecated()) { this->warn("This plugin has been declared deprecated by one of its authors. It may not work properly or will stop working properly in the near future."); } } else { resLoad.riResultIdentifier = RI_PLUGIN_LOADING_FAILED; resLoad.bSuccess = false; resLoad.strErrorMessage = "Failed to load library `" + strFilepath + "'."; this->fail("Could not open shared library: " + std::string(dlerror())); } } else { resLoad.riResultIdentifier = RI_FILE_NOT_FOUND; resLoad.bSuccess = false; resLoad.strErrorMessage = "File `" + strFilepath + "' could not be found."; } return resLoad; }
Result PLUGIN_CLASS::init(int argc, char** argv) { Result resInit = defaultResult(); // Initialize server m_imsServer = new interactive_markers::InteractiveMarkerServer("interactive_semrec", "", false); // Subscribe to internal events this->setSubscribedToEvent("symbolic-add-object", true); this->setSubscribedToEvent("symbolic-remove-object", true); this->setSubscribedToEvent("symbolic-update-object-pose", true); this->setSubscribedToEvent("symbolic-set-interactive-object-menu", true); return resInit; }
Result PLUGIN_CLASS::cycle() { Result resCycle = defaultResult(); for(InteractiveObject* ioCurrent : m_lstInteractiveObjects) { std::list<InteractiveObjectCallbackResult> lstCBResults = ioCurrent->callbackResults(); for(InteractiveObjectCallbackResult iocrResult : lstCBResults) { this->info("Interactive callback for object '" + iocrResult.strObject + "': '" + iocrResult.strCommand + "', '" + iocrResult.strParameter + "'"); Event evCallback = defaultEvent("interactive-callback"); evCallback.cdDesignator = new Designator(); evCallback.cdDesignator->setType(Designator::DesignatorType::ACTION); evCallback.cdDesignator->setValue("object", iocrResult.strObject); evCallback.cdDesignator->setValue("command", iocrResult.strCommand); evCallback.cdDesignator->setValue("parameter", iocrResult.strParameter); this->deployEvent(evCallback); } } this->deployCycleData(resCycle); return resCycle; }