/** * Check if the device factory or proxy factory can handle the element. */ bool InputManager::configureProxy(jccl::ConfigElementPtr element) { std::string proxy_name = element->getFullName(); vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("gadget::InputManager::configureProxy: Named: ") + proxy_name + std::string("\n"), std::string("done configuring proxy\n")); Proxy* new_proxy; // Tell the factory to load the proxy // NOTE: The config for the proxy registers it with the input manager new_proxy = ProxyFactory::instance()->loadProxy(element); // Check for success if(NULL == new_proxy) { vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED,"ERROR:") << " gadget::InputManager::configureProxy: Proxy construction failed:" << proxy_name << std::endl << vprDEBUG_FLUSH; return false; } vprASSERT(proxy_name == new_proxy->getName()); // -- Add to proxy table if(false == addProxy(new_proxy)) { return false; } return true; }
void Debug(const DebugEnabler* local, int level, const char* format, ...) { if (!s_debugging) return; const char* facility = 0; if (!local) { if (level > s_debug || level < DebugMin) return; } else { if (!local->debugAt(level)) return; facility = local->debugName(); } if (reentered()) return; if (!format) format = ""; char buf[64]; if (facility) ::snprintf(buf,sizeof(buf),"<%s:%s> ",facility,dbg_level(level)); else ::sprintf(buf,"<%s> ",dbg_level(level)); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(level,buf,format,va); ind_mux.unlock(); va_end(va); if (s_abort && (level == DebugFail)) abort(); }
/** * Removes a proxy aliases in config database. * @pre none * @post (alias not in list) ==> returns = false<br> * (alias is in list) ==> (alias is removed from list) returns true */ bool InputManager::removeProxyAlias(jccl::ConfigElementPtr element) { vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("gadget::InputManager::removeProxyAlias\n"), std::string("...done removing alias.\n")); vprASSERT(element->getID() == "alias"); std::string alias_name, proxy_name; // The string of the alias, name of proxy to pt to alias_name = element->getName(); if(mProxyAliases.end() == mProxyAliases.find(alias_name)) { vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED,"ERROR:") << "gadget::InputManager::RemoveProxyAlias: Alias: " << alias_name << " cannot find proxy: " << proxy_name.c_str() << std::endl << vprDEBUG_FLUSH; return false; } mProxyAliases.erase(alias_name); vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_CONFIG_LVL) << " alias:" << alias_name.c_str() << " index:" << mProxyAliases[proxy_name] << " has been removed." << std::endl << vprDEBUG_FLUSH; return true; }
static void dbg_dist_helper(int level, const char* buf, const char* fmt, ...) { va_list va; va_start(va,fmt); dbg_output(level,buf,fmt,va); va_end(va); }
void Node::debugDump(int debug_level) { vpr::DebugOutputGuard dbg_output(gadgetDBG_NET_MGR, debug_level, std::string("-------------- Node --------------\n"), std::string("-----------------------------------------\n")); vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Node Name: " << mName << std::endl << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Hostname: " << mHostname << std::endl << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Port: " << mPort << std::endl << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "SockStream " << (NULL == mSockStream ? "is NULL" : "is NOT NULL") << std::endl << vprDEBUG_FLUSH; if (CONNECTED == getStatus()) { vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrGREEN,"CONNECTED") << std::endl << vprDEBUG_FLUSH; } else if (NEWCONNECTION == getStatus()) { vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrRED,"NEW CONNECTION") << std::endl << vprDEBUG_FLUSH; } else { vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrRED,"DISCONNECTED") << std::endl << vprDEBUG_FLUSH; } }
void AbstractNetworkManager::debugDumpNodes(int debug_level) { vpr::DebugOutputGuard dbg_output(gadgetDBG_NET_MGR,debug_level, std::string("-------------- Cluster Network --------------\n"), std::string("---------------------------------------------\n")); for(std::vector<Node*>::iterator j = mNodes.begin(); j != mNodes.end(); j++) { (*j)->debugDump( debug_level ); } }
/** * Removes the element from the current configuration. */ bool InputManager::configRemove(jccl::ConfigElementPtr element) { vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("InputManager: Removing config...\n"), std::string("done removing config.\n")); vprASSERT(configCanHandle(element)); bool ret_val = false; // Flag to return success // NEED TO FIX!!!! if (cluster::ClusterManager::instance()->recognizeRemoteDeviceConfig(element)) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL) << "InputManager can not handle remote devices, we must use Remote Input Manager." << vprDEBUG_FLUSH; ret_val = false; } else if(DeviceFactory::instance()->recognizeDevice(element)) { ret_val = removeDevice(element); } else if(recognizeProxyAlias(element)) { ret_val = removeProxyAlias(element); } else if(ProxyFactory::instance()->recognizeProxy(element)) { ret_val = removeProxy(element); } else if(element->getID() == std::string("display_system")) { mDisplaySystemElement.reset(); // Keep track of the display system element ret_val = true; // We successfully configured. // This tell processPending to remove it to the active config } else { ret_val = false; } if(ret_val) { resetAllDevicesAndProxies(); updateAllDevices(); // Update all the input data updateAllProxies(); // Update all the input data BaseDeviceInterface::refreshAllInterfaces(); // Refresh all the device interface handles vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_VERB_LVL) << "InputManager::configRemove(): Updated all data" << std::endl << vprDEBUG_FLUSH; } return ret_val; // Return the success flag if we added at all }
Debugger::Debugger(int level, const char* name, const char* format, ...) : m_name(name), m_level(level) { if (s_debugging && m_name && (s_debug >= level) && !reentered()) { char buf[64]; ::snprintf(buf,sizeof(buf),">>> %s",m_name); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(m_level,buf,format,va); va_end(va); s_indent++; ind_mux.unlock(); } else m_name = 0; }
void Alarm(const char* component, int level, const char* format, ...) { if (!format || level < DebugMin || reentered()) return; if (TelEngine::null(component)) component = "unknown"; char buf[64]; ::snprintf(buf,sizeof(buf),"<%s:%s> ",component,dbg_level(level)); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(level,buf,format,va,component); ind_mux.unlock(); va_end(va); if (s_abort && (level == DebugFail)) abort(); }
void Alarm(const DebugEnabler* component, const char* info, int level, const char* format, ...) { if (!format || level < DebugMin || reentered()) return; const char* name = (component && !TelEngine::null(component->debugName())) ? component->debugName() : "unknown"; char buf[64]; ::snprintf(buf,sizeof(buf),"<%s:%s> ",name,dbg_level(level)); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(level,buf,format,va,name,info); ind_mux.unlock(); va_end(va); if (s_abort && (level == DebugFail)) abort(); }
/** * Configures proxy aliases in config database. * @pre none * @post (alias not already in list) ==> Alias is added to proxyAlias list<br> * (alias was already is list) ==> Alias is set to point to the new proxy instead */ bool InputManager::configureProxyAlias(jccl::ConfigElementPtr element) { vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("gadget::InputManager: Configuring proxy alias\n"), std::string("...done configuring alias.\n")); vprASSERT(element->getID() == "alias"); std::string alias_name, proxy_name; // The string of the alias, name of proxy to pt to alias_name = element->getName(); proxy_name = element->getProperty<std::string>("proxy"); addProxyAlias(alias_name, proxy_name); return true; }
void Debug(int level, const char* format, ...) { if (!s_debugging) return; if (level > s_debug) return; if (reentered()) return; if (!format) format = ""; char buf[32]; ::sprintf(buf,"<%s> ",dbg_level(level)); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(level,buf,format,va); ind_mux.unlock(); va_end(va); if (s_abort && (level == DebugFail)) abort(); }
void Debug(const char* facility, int level, const char* format, ...) { if (!s_debugging) return; if (level > s_debug || level < DebugMin) return; if (reentered()) return; if (!format) format = ""; char buf[64]; ::snprintf(buf,sizeof(buf),"<%s:%s> ",facility,dbg_level(level)); va_list va; va_start(va,format); ind_mux.lock(); dbg_output(level,buf,format,va); ind_mux.unlock(); va_end(va); if (s_abort && (level == DebugFail)) abort(); }
bool InputManager::removeProxy(const std::string& proxyName) { vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("gadget::InputManager::removeProxy\n"), std::string("\n")); if(mProxyTable.end() == mProxyTable.find(proxyName)) { vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED,"ERROR:") << "gadget::InputManager::removeProxy: proxy: " << proxyName << " cannot find proxy: " << proxyName.c_str() << std::endl << vprDEBUG_FLUSH; return false; } mProxyTable.erase(proxyName); vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_CONFIG_LVL) << " proxy:" << proxyName.c_str() << " has been removed." << std::endl << vprDEBUG_FLUSH; return true; }
Node* AbstractNetworkManager::getNodeByHostname(const std::string& host_name) { vpr::DebugOutputGuard dbg_output( gadgetDBG_NET_MGR, vprDBG_VERB_LVL, std::string("-------- getNodeByHostname() --------\n"), std::string("--------------------------------------------\n")); vpr::InetAddr searching_for_node; searching_for_node.setAddress( host_name, 0 ); vprDEBUG( gadgetDBG_NET_MGR, vprDBG_VERB_LVL ) << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" ) << " Looking for Node with hostname: " << host_name << std::endl << vprDEBUG_FLUSH; // -Find Node with given hostname and return a pointer to it. // -If we do not find one, return NULL for (std::vector<Node*>::iterator i = mNodes.begin(); i != mNodes.end() ; i++) { vpr::InetAddr testing_node; testing_node.setAddress( (*i)->getHostname(), 0 ); vprDEBUG( gadgetDBG_NET_MGR, vprDBG_VERB_LVL ) << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" ) << " Searcing for: " << searching_for_node.getAddressString() << " Testing: " << testing_node.getAddressString() << std::endl << vprDEBUG_FLUSH; if (searching_for_node.getAddressString() == testing_node.getAddressString()) { return(*i); } } return(NULL); }
/** * Check if the device factory or proxy factory can handle the element. */ bool InputManager::configureDevice(jccl::ConfigElementPtr element) { bool ret_val; std::string dev_name = element->getFullName(); vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("InputManager::configureDevice: device[") + dev_name + std::string("]\n"), std::string("done configuring device\n")); Input* new_device; new_device = DeviceFactory::instance()->loadDevice(element); if ((new_device != NULL) && (new_device->startSampling())) { addDevice(new_device); ret_val = true; vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL) << " Successfully added device: " << dev_name << std::endl << vprDEBUG_FLUSH; } else { vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED,"ERROR:") << "New device " << clrSetBOLD(clrCYAN) << dev_name << clrRESET << " failed to start. Deleting instance" << std::endl << vprDEBUG_FLUSH; if ( NULL != new_device ) { delete new_device; } ret_val = false; } return ret_val; }
bool InputManager::configureInputManager(jccl::ConfigElementPtr element) { bool have_bad_elt = (element->getID() != std::string("input_manager")); vprASSERT(!have_bad_elt); if(have_bad_elt) { return false; } bool ret_val = false; vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL, std::string("Handling input_manager element:\n"), std::string("-- end state -- \n")); // Keep this up to date with the version of the element definition we're // expecting to handle. const unsigned int cur_version(2); // If the element version is less than cur_version, we will not try to // proceed. Instead, we'll print an error message and return false so // that the Config Manager knows this element wasn't consumed. if ( element->getVersion() < cur_version ) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": [gadget::InputManager::configureInputManager()] Element named '" << element->getName() << "'" << std::endl << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "is version " << element->getVersion() << ", but we require at least version " << cur_version << std::endl << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "Ignoring this element and moving on." << std::endl << vprDEBUG_FLUSH; ret_val = false; } // We got the right version of the config element and can proceed. else { const std::string driver_path_prop_name("driver_path"); const int path_count(element->getNum(driver_path_prop_name)); std::vector<fs::path> search_path(path_count); for ( unsigned int i = 0; i < search_path.size(); ++i ) { std::string temp_str = vpr::replaceEnvVars(element->getProperty<std::string>(driver_path_prop_name, i)); try { search_path[i] = fs::path(temp_str, fs::native); } catch(fs::filesystem_error& fsEx) { vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED, "ERROR") << ": [gadget::InputManager::configureInputManager()] File " << "system exception caught while converting\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL) << "'" << temp_str << "'\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL) << "to a Boost.Filesystem path.\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(vprDBG_ERROR, vprDBG_CRITICAL_LVL) << fsEx.what() << std::endl << vprDEBUG_FLUSH; } } // Append a default driver search path to search_path. const fs::path default_search_dir = gadget::getDefaultPluginRoot() / std::string("drivers"); vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_VERB_LVL) << "[gadget::InputManager::configureInputManager()] Appending " << "default search path '" << default_search_dir.native_directory_string() << "'\n" << vprDEBUG_FLUSH; #if defined(GADGET_DEBUG) // For a debug build, search in the debug subdirectory of // default_search_dir before looking in default_search_dir. search_path.push_back(default_search_dir / std::string("debug")); #endif search_path.push_back(default_search_dir); // --- Load device driver dsos -- // // - Load individual drivers const std::string driver_prop_name("driver"); const std::string get_version_func("getGadgeteerVersion"); const std::string driver_init_func("initDevice"); int driver_count = element->getNum(driver_prop_name); std::string driver_dso_name; for ( int i = 0; i < driver_count; ++i ) { driver_dso_name = element->getProperty<std::string>(driver_prop_name, i); if ( ! driver_dso_name.empty() ) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) << "[gadget::InputManager::configureInputManager()] Loading " << "driver DSO '" << driver_dso_name << "'\n" << vprDEBUG_FLUSH; vpr::LibraryPtr dso = vpr::LibraryLoader::findDSO(driver_dso_name, search_path); if ( dso.get() != NULL ) { try { VersionCheckCallable version_functor; vpr::LibraryLoader::callEntryPoint(dso, get_version_func, version_functor); DriverInitCallable init_functor(this); vpr::LibraryLoader::callEntryPoint(dso, driver_init_func, init_functor); mLoadedDrivers.push_back(dso); } catch (gadget::PluginVersionException& ex) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": Version mismatch while loading driver DSO '" << driver_dso_name << "'\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "This driver will not be usable.\n" << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << ex.getExtendedDescription() << std::endl << vprDEBUG_FLUSH; } catch (vpr::Exception& ex) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": Failed to load driver DSO '" << driver_dso_name << "'\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "This driver will not be usable.\n" << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << ex.what() << std::endl << vprDEBUG_FLUSH; } } else { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": Failed to find driver DSO '" << driver_dso_name << "'\n" << vprDEBUG_FLUSH; } } } // - Load driver directory const std::string dir_prop_name("driver_scan_path"); int dir_count = element->getNum(dir_prop_name); std::string driver_dir; #if defined(VPR_OS_Windows) const std::string driver_ext("dll"); #elif defined(VPR_OS_Darwin) const std::string driver_ext("dylib"); #else const std::string driver_ext("so"); #endif for ( int i = 0; i < dir_count; ++i ) { driver_dir = vpr::replaceEnvVars(element->getProperty<std::string>(dir_prop_name, i)); // The vpr::LibraryFinder will throw an exception if driver_dir is // (somehow) an invalid path. try { fs::path drv_path(driver_dir, fs::native); if ( fs::exists(drv_path) ) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "[gadget::InputManager::configureInputManager()] " << "Searching for driver DSOs in '" << driver_dir << "'\n" << vprDEBUG_FLUSH; vpr::LibraryFinder finder(driver_dir, driver_ext); vpr::LibraryFinder::LibraryList libs = finder.getLibraries(); VersionCheckCallable version_functor; DriverInitCallable init_functor(this); for ( vpr::LibraryFinder::LibraryList::iterator lib = libs.begin(); lib != libs.end(); ++lib ) { try { vpr::LibraryLoader::callEntryPoint(*lib, get_version_func, version_functor); vpr::LibraryLoader::callEntryPoint(*lib, driver_init_func, init_functor); mLoadedDrivers.push_back(*lib); } catch (vpr::Exception& ex) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrRED, "ERROR") << ": Failed to load driver DSO '" << (*lib)->getName() << "'\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << "This driver will not be usable.\n" << vprDEBUG_FLUSH; vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << ex.what() << std::endl << vprDEBUG_FLUSH; } } } else { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutBOLD(clrYELLOW, "WARNING") << ": [gadget::InputManager::configureInputManager()] " << "Invalid directory for driver DSOs: " << driver_dir << std::endl << vprDEBUG_FLUSH; } } catch(fs::filesystem_error& fsEx) { vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED, "ERROR") << ": [gadget::InputManager::configureInputManager()] File " << "system exception caught!\n" << vprDEBUG_FLUSH; vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) << fsEx.what() << std::endl << vprDEBUG_FLUSH; } } ret_val = true; } return ret_val; }