示例#1
0
/**
 * Loads all modules configured for the current bar
 */
void Bar::load(std::shared_ptr<Registry> registry)
{
  this->registry = registry;

  auto add_modules = [&](std::string modlist, std::vector<std::string> &vec){
    std::vector<std::string> modules;
    string::split_into(modlist, ' ', modules);

    for (auto &&mod : modules) {
      std::unique_ptr<modules::ModuleInterface> module;
      auto type = config::get<std::string>("module/"+ mod, "type");

      if (!ENABLE_ALSA && type == "internal/volume")
        throw CompiledWithoutModuleSupport(type);
      if (!ENABLE_I3 && type == "internal/i3")
        throw CompiledWithoutModuleSupport(type);
      if (!ENABLE_MPD && type == "internal/mpd")
        throw CompiledWithoutModuleSupport(type);
      if (!ENABLE_NETWORK && type == "internal/network")
        throw CompiledWithoutModuleSupport(type);

           if (type == "internal/counter") module = std::make_unique<modules::CounterModule>(mod);
      else if (type == "internal/backlight") module = std::make_unique<modules::BacklightModule>(mod);
      else if (type == "internal/battery") module = std::make_unique<modules::BatteryModule>(mod);
      else if (type == "internal/bspwm") module = std::make_unique<modules::BspwmModule>(mod, this->opts->monitor->name);
      else if (type == "internal/cpu") module = std::make_unique<modules::CpuModule>(mod);
      else if (type == "internal/date") module = std::make_unique<modules::DateModule>(mod);
      else if (type == "internal/memory") module = std::make_unique<modules::MemoryModule>(mod);
      #if ENABLE_I3
      else if (type == "internal/i3") module = std::make_unique<modules::i3Module>(mod, this->opts->monitor->name);
      #endif
      #if ENABLE_MPD
      else if (type == "internal/mpd") module = std::make_unique<modules::MpdModule>(mod);
      #endif
      #if ENABLE_ALSA
      else if (type == "internal/volume") module = std::make_unique<modules::VolumeModule>(mod);
      #endif
      #if ENABLE_NETWORK
      else if (type == "internal/network") module = std::make_unique<modules::NetworkModule>(mod);
      #endif
      else if (type == "custom/text") module = std::make_unique<modules::TextModule>(mod);
      else if (type == "custom/script") module = std::make_unique<modules::ScriptModule>(mod);
      else if (type == "custom/menu") module = std::make_unique<modules::MenuModule>(mod);
      else throw ConfigurationError("Unknown module: "+ mod);

      module->attach_registry(this->registry);

      vec.emplace_back(module->name());
      this->registry->insert(std::move(module));
    }
  };

  add_modules(config::get<std::string>(this->config_path, "modules-left", ""), this->mod_left);
  add_modules(config::get<std::string>(this->config_path, "modules-center", ""), this->mod_center);
  add_modules(config::get<std::string>(this->config_path, "modules-right", ""), this->mod_right);

  if (this->mod_left.empty() && this->mod_center.empty() && this->mod_right.empty())
    throw ConfigurationError("The bar does not contain any modules...");
}
示例#2
0
void AgoApp::setupLogging() {
    log_container::initDefault();

    std::string level_str;
    if(cli_vars["debug"].as<bool>())
        level_str = "DEBUG";
    else if(cli_vars["trace"].as<bool>())
        level_str = "TRACE";
    else if(cli_vars.count("log-level"))
        level_str = cli_vars["log-level"].as<std::string>();
    else
        level_str = getConfigOption("log_level", "info", ExtraConfigNameList("system"));

    try {
        logLevel = log_container::getLevel(level_str);
        log_container::setCurrentLevel(logLevel);
    }catch(std::runtime_error &e) {
        throw ConfigurationError(e.what());
    }

    std::string method;
    if(cli_vars["debug"].as<bool>() || cli_vars["trace"].as<bool>())
        method = "console";
    else if(cli_vars.count("log-method"))
        method = cli_vars["log-method"].as<std::string>();
    else
        method = getConfigOption("log_method", "console", ExtraConfigNameList("system"));

    if(method == "syslog") {
        std::string facility_str;
        if(cli_vars.count("log-syslog-facility"))
            facility_str = cli_vars["log-syslog-facility"].as<std::string>();
        else
            facility_str = getConfigOption("syslog_facility", "local0", ExtraConfigNameList("system"));

        int facility = log_container::getFacility(facility_str);
        if(facility == -1) {
            throw ConfigurationError("Bad syslog facility '" + facility_str + "'");
        }

        log_container::setOutputSyslog(boost::to_lower_copy(appName), facility);
        AGO_DEBUG() << "Using syslog facility " << facility_str << ", level " << level_str;
    }
    else if(method == "console") {
        AGO_DEBUG() << "Using console log, level " << level_str;
    }
    else {
        throw ConfigurationError("Bad log_method '" + method + "'");
    }

    method = getConfigOption("log_method", "console", ExtraConfigNameList("system"));
}
示例#3
0
/// Loads configuration from a serialized and signed Protobuf
/// Configuration message.
/// Unauthenticated.
void PluginAPI::configure(const std::string &config_str_hex)
{
    try {
        const std::string config_str = utils::hex_decode(config_str_hex);
        const uint8_t *config_buf = (const uint8_t *)config_str.c_str();
        const size_t config_len = config_str.size();
        bool verified = false;

        if (config_len >= utils::SIGNATURE_LENGTH)
            verified = utils::signature_verify(config_buf,
                                               config_buf + utils::SIGNATURE_LENGTH,
                                               config_len - utils::SIGNATURE_LENGTH);
        if (!verified) {
            FBLOG_ERROR("configure()", "Signature verification failed");
            throw ConfigurationError("Signature verification failed");
        }

        Configuration config;
        config.ParseFromArray(config_buf + utils::SIGNATURE_LENGTH,
                              config_len - utils::SIGNATURE_LENGTH);
        acquire_plugin()->configure(config);

    } catch (const std::exception &e) {
        FBLOG_ERROR("configure()", "Exception caught");
        FBLOG_ERROR("configure()", e.what());
        throw FB::script_error(e.what());
    }
}
示例#4
0
boolean CUSBHIDDevice::Configure (void)
{
	if (GetNumEndpoints () < 1)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}
	
	TUSBEndpointDescriptor *pEndpointDesc =
		(TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT);
	if (   pEndpointDesc == 0
	    || (pEndpointDesc->bEndpointAddress & 0x80) != 0x80		// Input EP
	    || (pEndpointDesc->bmAttributes     & 0x3F)	!= 0x03)	// Interrupt EP
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	assert (m_pReportEndpoint == 0);
	m_pReportEndpoint = new CUSBEndpoint (GetDevice (), pEndpointDesc);
	assert (m_pReportEndpoint != 0);

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set interface");

		return FALSE;
	}

	if (GetHost ()->ControlMessage (GetEndpoint0 (),
					REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_INTERFACE,
					SET_PROTOCOL, BOOT_PROTOCOL,
					GetInterfaceNumber (), 0, 0) < 0)
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set boot protocol");

		return FALSE;
	}

	return StartRequest ();
}
示例#5
0
void ConfigurationFile::loadFromFile(const char *file_name)
{
        std::ifstream ifs(file_name);
        if (!ifs.is_open())
        {
                throw ConfigurationError("File does not exists");
                return;
        }
        std::string line;
        ConfigurationSection section;
        std::string section_name;
        root_ = SectionContainerRefPtr(new SectionContainer);
        while (getline(ifs,line))
        {
                std::string new_section_name;
                std::string key;
                std::string value;
                if (isCommentLine(line))
                {
                        continue;
                }
                if (isSectionLine(line,new_section_name))
                {
                        if (!section_name.empty())
                        {
                                section.setRoot(section_name,root_);
                                root_->insert(std::make_pair(section_name,section));
                                section_name.clear();
                        }
                        section_name = new_section_name;
                        section.clear();
                }
                else if (isKeyValueLine(line,key,value))
                {
                        section.insert(key,value);
                }
        }

        if (!section_name.empty())
        {
                section.setRoot(section_name,root_);
                root_->insert(std::make_pair(section_name,section));
                section_name.clear();
        }

        //std::cerr << "After Building " << (unsigned long long )root_.get() << "\t" <<root_.use_count() << std::endl;
}
示例#6
0
    void Configuration::save() const {
        FILE* file = fopen(FILENAME.c_str(), "w");
        if (!file) {
            throw ConfigurationError("Error opening " + FILENAME);
        }

        fprintf(file, "<server-configuration>\n");
        writeAttr(file, "serverPort", serverPort);
        writeAttr(file, "shouldStartServer", shouldStartServer);
        writeAttr(file, "windowPositionX", windowPosition.x);
        writeAttr(file, "windowPositionY", windowPosition.y);
        writeAttr(file, "windowSizeWidth", windowSize.GetWidth());
        writeAttr(file, "windowSizeHeight", windowSize.GetHeight());
        writeAttr(file, "map", map);
        fprintf(file, "</server-configuration>\n");

        fclose(file);
    }
示例#7
0
/// Lists allowed device objects.
/// Authentication required.
/// Returns array of DeviceAPI.
std::vector<FB::JSAPIPtr> PluginAPI::devices()
{
    if (!acquire_plugin()->authenticate()) {
        FBLOG_ERROR("get_devices()", "URL not allowed");
        throw ConfigurationError("URL not allowed");
    }

    try {
        std::vector<DeviceDescriptor> devices = acquire_plugin()->enumerate();
        std::vector<FB::JSAPIPtr> result;

        for (size_t i = 0; i < devices.size(); i++)
            result.push_back(boost::make_shared<DeviceAPI>(devices[i]));

        return result;
        
    } catch (const std::exception &e) {
        FBLOG_ERROR("get_devices()", "Exception caught");
        FBLOG_ERROR("get_devices()", e.what());
        throw FB::script_error(e.what());
    }
}
void Configuration::init(const boost::program_options::variables_map& options) {
  if (options.count("daemon")) {
    daemonize = true;
  }

  if (options.count("register-service")) {
    registerService = true;
  }

  if (options.count("unregister-service")) {
    unregisterService = true;
  }

  if (registerService && unregisterService) {
    throw ConfigurationError("It's impossible to use both \"register-service\" and \"unregister-service\" at the same time");
  }

  if (options.count("testnet")) {
    testnet = true;
  }

  if (options.count("log-file")) {
    logFile = options["log-file"].as<std::string>();
  }

  if (options.count("log-level")) {
    logLevel = options["log-level"].as<std::size_t>();
    if (logLevel > Logging::TRACE) {
      std::string error = "log-level option must be in " + std::to_string(Logging::FATAL) +  ".." + std::to_string(Logging::TRACE) + " interval";
      throw ConfigurationError(error.c_str());
    }
  }

  if (options.count("server-root")) {
    serverRoot = options["server-root"].as<std::string>();
  }

  if (options.count("bind-address")) {
    bindAddress = options["bind-address"].as<std::string>();
  }

  if (options.count("bind-port")) {
    bindPort = options["bind-port"].as<uint16_t>();
  }

  if (options.count("wallet-file")) {
    walletFile = options["wallet-file"].as<std::string>();
  }

  if (options.count("wallet-password")) {
    walletPassword = options["wallet-password"].as<std::string>();
  }

  if (options.count("generate-wallet")) {
    generateNewWallet = true;
  }

  if (options.count("import-keys")) {
    importKeys = options["import-keys"].as<std::string>();
  }

  if (!importKeys.empty() && generateNewWallet) {
    throw ConfigurationError("It's impossible to use both \"import\" and \"generate-wallet\" at the same time");
  }

  if (!registerService && !unregisterService) {
    if (walletFile.empty() || walletPassword.empty()) {
      throw ConfigurationError("Both wallet-file and wallet-password parameters are required");
    }
  }
}
示例#9
0
boolean CUSBBluetoothDevice::Configure (void)
{
	if (GetInterfaceNumber () != 0)
	{
		CLogger::Get ()->Write (FromBluetooth, LogWarning, "Voice channels are not supported");

		return FALSE;
	}

	if (GetNumEndpoints () != 3)
	{
		ConfigurationError (FromBluetooth);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointBulkIn != 0)
				{
					ConfigurationError (FromBluetooth);

					return FALSE;
				}

				m_pEndpointBulkIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointBulkOut != 0)
				{
					ConfigurationError (FromBluetooth);

					return FALSE;
				}

				m_pEndpointBulkOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
		else if ((pEndpointDesc->bmAttributes & 0x3F) == 0x03)		// Interrupt
		{
			if (m_pEndpointInterrupt != 0)
			{
				ConfigurationError (FromBluetooth);

				return FALSE;
			}

			m_pEndpointInterrupt = new CUSBEndpoint (GetDevice (), pEndpointDesc);
		}
	}

	if (   m_pEndpointBulkIn    == 0
	    || m_pEndpointBulkOut   == 0
	    || m_pEndpointInterrupt == 0)
	{
		ConfigurationError (FromBluetooth);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromBluetooth, LogError, "Cannot set interface");

		return FALSE;
	}

	m_pEventBuffer = new u8[m_pEndpointInterrupt->GetMaxPacketSize ()];
	assert (m_pEventBuffer != 0);

	CString DeviceName;
	DeviceName.Format ("ubt%u", s_nDeviceNumber++);
	CDeviceNameService::Get ()->AddDevice (DeviceName, this, FALSE);

	return TRUE;
}
示例#10
0
文件: smsc951x.cpp 项目: rsta2/circle
boolean CSMSC951xDevice::Configure (void)
{
	CBcmPropertyTags Tags;
	TPropertyTagMACAddress MACAddress;
	if (Tags.GetTag (PROPTAG_GET_MAC_ADDRESS, &MACAddress, sizeof MACAddress))
	{
		m_MACAddress.Set (MACAddress.Address);
	}
	else
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot get MAC address");

		return FALSE;
	}
	CString MACString;
	m_MACAddress.Format (&MACString);
	CLogger::Get ()->Write (FromSMSC951x, LogDebug, "MAC address is %s", (const char *) MACString);

	if (GetNumEndpoints () != 3)
	{
		ConfigurationError (FromSMSC951x);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointBulkIn != 0)
				{
					ConfigurationError (FromSMSC951x);

					return FALSE;
				}

				m_pEndpointBulkIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointBulkOut != 0)
				{
					ConfigurationError (FromSMSC951x);

					return FALSE;
				}

				m_pEndpointBulkOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (   m_pEndpointBulkIn  == 0
	    || m_pEndpointBulkOut == 0)
	{
		ConfigurationError (FromSMSC951x);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set interface");

		return FALSE;
	}

	u8 MACAddressBuffer[MAC_ADDRESS_SIZE];
	m_MACAddress.CopyTo (MACAddressBuffer);
	u16 usMACAddressHigh =   (u16) MACAddressBuffer[4]
			       | (u16) MACAddressBuffer[5] << 8;
	u32 nMACAddressLow   =   (u32) MACAddressBuffer[0]
			       | (u32) MACAddressBuffer[1] << 8
			       | (u32) MACAddressBuffer[2] << 16
			       | (u32) MACAddressBuffer[3] << 24;
	if (   !WriteReg (ADDRH, usMACAddressHigh)
	    || !WriteReg (ADDRL, nMACAddressLow))
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set MAC address");

		return FALSE;
	}

	if (   !WriteReg (LED_GPIO_CFG,   LED_GPIO_CFG_SPD_LED
					| LED_GPIO_CFG_LNK_LED
					| LED_GPIO_CFG_FDX_LED)
	    || !WriteReg (MAC_CR,  MAC_CR_RCVOWN
				 //| MAC_CR_PRMS		// promiscous mode
				 | MAC_CR_TXEN
				 | MAC_CR_RXEN)
	    || !WriteReg (TX_CFG, TX_CFG_ON))
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot start device");

		return FALSE;
	}

	AddNetDevice ();

	return TRUE;
}
示例#11
0
boolean CUSBHIDDevice::Configure (unsigned nMaxReportSize)
{
	if (GetNumEndpoints () < 1)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x03)		// Interrupt EP
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input EP
			{
				if (m_pReportEndpoint != 0)
				{
					ConfigurationError (FromUSBHID);

					return FALSE;
				}

				m_pReportEndpoint = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output EP
			{
				if (m_pEndpointOut != 0)
				{
					ConfigurationError (FromUSBHID);

					return FALSE;
				}

				m_pEndpointOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (m_pReportEndpoint == 0)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set interface");

		return FALSE;
	}

	if (   GetInterfaceClass ()    == 3	// HID class
	    && GetInterfaceSubClass () == 1)	// boot class
	{
		if (GetHost ()->ControlMessage (GetEndpoint0 (),
						REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_INTERFACE,
						SET_PROTOCOL, BOOT_PROTOCOL,
						GetInterfaceNumber (), 0, 0) < 0)
		{
			CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set boot protocol");

			return FALSE;
		}
	}

	if (m_nMaxReportSize == 0)
	{
		m_nMaxReportSize = nMaxReportSize;
		assert (m_nMaxReportSize > 0);

		assert (m_pReportBuffer == 0);
		m_pReportBuffer = new u8[m_nMaxReportSize];
	}
	assert (m_pReportBuffer != 0);

	return TRUE;
}
void Configuration::init(const boost::program_options::variables_map& options) {
  if (options.count("daemon") != 0) {
    daemonize = true;
  }

  if (options.count("register-service") != 0) {
    registerService = true;
  }

  if (options.count("unregister-service") != 0) {
    unregisterService = true;
  }

  if (registerService && unregisterService) {
    throw ConfigurationError("It's impossible to use both \"register-service\" and \"unregister-service\" at the same time");
  }

  if (options["testnet"].as<bool>()) {
    testnet = true;
  }

  if (options.count("log-file") != 0) {
    logFile = options["log-file"].as<std::string>();
  }

  if (options.count("log-level") != 0) {
    logLevel = options["log-level"].as<size_t>();
    if (logLevel > Logging::TRACE) {
      std::string error = "log-level option must be in " + std::to_string(Logging::FATAL) +  ".." + std::to_string(Logging::TRACE) + " interval";
      throw ConfigurationError(error.c_str());
    }
  }

  if (options.count("server-root") != 0) {
    serverRoot = options["server-root"].as<std::string>();
  }

  if (options.count("bind-address") != 0 && (!options["bind-address"].defaulted() || bindAddress.empty())) {
    bindAddress = options["bind-address"].as<std::string>();
  }

  if (options.count("bind-port") != 0 && (!options["bind-port"].defaulted() || bindPort == 0)) {
    bindPort = options["bind-port"].as<uint16_t>();
  }

  if (options.count("rpc-user") != 0 && !options["rpc-user"].defaulted()) {
    rpcUser = options["rpc-user"].as<std::string>();
  }

  if (options.count("rpc-password") != 0 && !options["rpc-password"].defaulted()) {
    rpcPassword = options["rpc-password"].as<std::string>();
  }

  if (options.count("container-file") != 0) {
    containerFile = options["container-file"].as<std::string>();
  }

  if (options.count("container-password") != 0) {
    containerPassword = options["container-password"].as<std::string>();
  }

  if (options.count("generate-container") != 0) {
    generateNewContainer = true;
  }

  if (options.count("address") != 0) {
    printAddresses = true;
  }

  if (!registerService && !unregisterService) {
    if (containerFile.empty() || containerPassword.empty()) {
      throw ConfigurationError("Both container-file and container-password parameters are required");
    }
  }
}
bool ConfigurationManager::init(int argc, char** argv) {
  po::options_description cmdGeneralOptions("Common Options");

  cmdGeneralOptions.add_options()
  ("config,c", po::value<std::string>()->default_value("./configs/-.conf"), "configuration file");

  po::options_description confGeneralOptions;
  confGeneralOptions.add(cmdGeneralOptions).add_options()
      ("testnet", po::value<bool>(), "")
      ("local", po::value<bool>(), "");

  cmdGeneralOptions.add_options()
      ("help,h", "produce this help message and exit")
      ("local", "start with local node (remote is default)")
      ("testnet", "testnet mode");

  command_line::add_arg(cmdGeneralOptions, command_line::arg_data_dir, tools::get_default_data_dir());
  command_line::add_arg(confGeneralOptions, command_line::arg_data_dir, tools::get_default_data_dir());

  Configuration::initOptions(cmdGeneralOptions);
  Configuration::initOptions(confGeneralOptions);

  po::options_description netNodeOptions("Local Node Options");
  CryptoNote::NetNodeConfig::initOptions(netNodeOptions);
  CryptoNote::CoreConfig::initOptions(netNodeOptions);

  po::options_description remoteNodeOptions("Remote Node Options");
  RpcNodeConfiguration::initOptions(remoteNodeOptions);
  po::options_description coinBaseOptions("Coin Base Options");
  CoinBaseConfiguration::initOptions(coinBaseOptions);

  po::options_description cmdOptionsDesc;
  cmdOptionsDesc.add(cmdGeneralOptions).add(remoteNodeOptions).add(netNodeOptions).add(coinBaseOptions);

  po::options_description confOptionsDesc;
  confOptionsDesc.add(confGeneralOptions).add(remoteNodeOptions).add(netNodeOptions).add(coinBaseOptions);

  po::variables_map cmdOptions;
  po::store(po::parse_command_line(argc, argv, cmdOptionsDesc), cmdOptions);
  po::notify(cmdOptions);

  if (cmdOptions.count("help")) {
    std::cout << cmdOptionsDesc << std::endl;
    return false;
  }

  if (cmdOptions.count("config")) {
    std::ifstream confStream(cmdOptions["config"].as<std::string>(), std::ifstream::in);
    if (!confStream.good()) {
      throw ConfigurationError("Cannot open configuration file");
    }

    po::variables_map confOptions;
    po::store(po::parse_config_file(confStream, confOptionsDesc, true), confOptions);
    po::notify(confOptions);

    gateConfiguration.init(confOptions);
    netNodeConfig.init(confOptions);
    coreConfig.init(confOptions);
    remoteNodeConfig.init(confOptions);
    coinBaseConfig.init(confOptions);

    if (confOptions.count("local")) {
      startInprocess = confOptions["local"].as<bool>();
    }
  }

  //command line options should override options from config file
  gateConfiguration.init(cmdOptions);
  netNodeConfig.init(cmdOptions);
  coreConfig.init(cmdOptions);
  remoteNodeConfig.init(cmdOptions);

  if (cmdOptions.count("local")) {
    startInprocess = true;
  }

  return true;
}
示例#14
0
boolean CUSBPrinterDevice::Configure (void)
{
	m_Protocol = (TUSBPrinterProtocol) GetInterfaceProtocol ();
	if (   m_Protocol == USBPrinterProtocolUnknown
	    || m_Protocol > USBPrinterProtocolBidirectional)
	{
		CLogger::Get ()->Write (FromPrinter, LogError, "Protocol %u is not supported", (unsigned) m_Protocol);

		return FALSE;
	}

	if (GetNumEndpoints () < (m_Protocol == USBPrinterProtocolUnidirectional ? 1 : 2))
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointIn != 0)
				{
					ConfigurationError (FromPrinter);

					return FALSE;
				}

				m_pEndpointIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointOut != 0)
				{
					ConfigurationError (FromPrinter);

					return FALSE;
				}

				m_pEndpointOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (m_pEndpointOut == 0)
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	if (   m_Protocol != USBPrinterProtocolUnidirectional
	    && m_pEndpointIn == 0)
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromPrinter, LogError, "Cannot set interface");

		return FALSE;
	}

	CString DeviceName;
	DeviceName.Format ("uprn%u", s_nDeviceNumber++);
	CDeviceNameService::Get ()->AddDevice (DeviceName, this, FALSE);

	return TRUE;
}
示例#15
0
boolean CUSBDevice::Initialize (void)
{
	assert (m_pDeviceDesc == 0);
	m_pDeviceDesc = new TUSBDeviceDescriptor;
	assert (m_pDeviceDesc != 0);
	
	assert (m_pHost != 0);
	assert (m_pEndpoint0 != 0);
	
	assert (sizeof *m_pDeviceDesc >= USB_DEFAULT_MAX_PACKET_SIZE);
	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_DEVICE, DESCRIPTOR_INDEX_DEFAULT,
				    m_pDeviceDesc, USB_DEFAULT_MAX_PACKET_SIZE)
	    != USB_DEFAULT_MAX_PACKET_SIZE)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Cannot get device descriptor (short)");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

	if (   m_pDeviceDesc->bLength	      != sizeof *m_pDeviceDesc
	    || m_pDeviceDesc->bDescriptorType != DESCRIPTOR_DEVICE)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Invalid device descriptor");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

	m_pEndpoint0->SetMaxPacketSize (m_pDeviceDesc->bMaxPacketSize0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_DEVICE, DESCRIPTOR_INDEX_DEFAULT,
				    m_pDeviceDesc, sizeof *m_pDeviceDesc)
	    != (int) sizeof *m_pDeviceDesc)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Cannot get device descriptor");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

#ifndef NDEBUG
	//debug_hexdump (m_pDeviceDesc, sizeof *m_pDeviceDesc, FromDevice);
#endif
	
	u8 ucAddress = s_ucNextAddress++;
	if (ucAddress > USB_MAX_ADDRESS)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Too many devices");

		return FALSE;
	}

	if (!m_pHost->SetAddress (m_pEndpoint0, ucAddress))
	{
		CLogger::Get ()->Write (FromDevice, LogError,
					"Cannot set address %u", (unsigned) ucAddress);

		return FALSE;
	}
	
	SetAddress (ucAddress);

	assert (m_pConfigDesc == 0);
	m_pConfigDesc = new TUSBConfigurationDescriptor;
	assert (m_pConfigDesc != 0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_CONFIGURATION, DESCRIPTOR_INDEX_DEFAULT,
				    m_pConfigDesc, sizeof *m_pConfigDesc)
	    != (int) sizeof *m_pConfigDesc)
	{
		CLogger::Get ()->Write (FromDevice, LogError,
					"Cannot get configuration descriptor (short)");

		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

	if (   m_pConfigDesc->bLength         != sizeof *m_pConfigDesc
	    || m_pConfigDesc->bDescriptorType != DESCRIPTOR_CONFIGURATION
	    || m_pConfigDesc->wTotalLength    >  MAX_CONFIG_DESC_SIZE)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Invalid configuration descriptor");
		
		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

	unsigned nTotalLength = m_pConfigDesc->wTotalLength;

	delete m_pConfigDesc;

	m_pConfigDesc = (TUSBConfigurationDescriptor *) new u8[nTotalLength];
	assert (m_pConfigDesc != 0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_CONFIGURATION, DESCRIPTOR_INDEX_DEFAULT,
				    m_pConfigDesc, nTotalLength)
	    != (int) nTotalLength)
	{
		CLogger::Get ()->Write (FromDevice, LogError, "Cannot get configuration descriptor");

		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

#ifndef NDEBUG
	//debug_hexdump (m_pConfigDesc, nTotalLength, FromDevice);
#endif

	assert (m_pConfigParser == 0);
	m_pConfigParser = new CUSBConfigurationParser (m_pConfigDesc, nTotalLength);
	assert (m_pConfigParser != 0);

	if (!m_pConfigParser->IsValid ())
	{
		ConfigurationError (FromDevice);

		return FALSE;
	}

	return TRUE;
}
示例#16
0
/**
 * Bar constructor
 */
Bar::Bar() : config_path(config::get_bar_path()), opts(std::make_shared<Options>())
{
  struct Options defaults;

  try {
    this->opts->locale = config::get<std::string>(this->config_path, "locale");
    std::locale::global(std::locale(this->opts->locale.c_str()));
  } catch (config::MissingValueException &e) {}

  auto monitor_name = config::get<std::string>(this->config_path, "monitor", "");
  auto monitors = xcb::monitor::get_list(x::connection(), x::connection().root());

  // In case we're not connected to X, we'll just ignore the monitor
  if (!monitors.empty()) {
    if (monitor_name.empty() && !monitors.empty())
      monitor_name = monitors[0]->name;

    for (auto &&monitor : monitors) {
      if (monitor_name.compare(monitor->name) == 0) {
        this->opts->monitor = monitor;
        break;
      }
    }

    if (!this->opts->monitor)
      throw ConfigurationError("Could not find monitor: "+ monitor_name);
  }

  this->opts->wm_name = "lemonbuddy-"+ this->config_path.substr(4);
  if (this->opts->monitor)
    this->opts->wm_name += "_"+ std::string(this->opts->monitor->name);
  this->opts->wm_name = string::replace(config::get<std::string>(this->config_path, "wm_name", this->opts->wm_name), " ", "-");

  // Create an empty monitor as fallback
  if (!this->opts->monitor)
    this->opts->monitor = xcb::monitor::make_object();

  this->opts->offset_x = config::get<int>(this->config_path, "offset_x", defaults.offset_x);
  this->opts->offset_y = config::get<int>(this->config_path, "offset_y", defaults.offset_y);

  auto width = config::get<std::string>(this->config_path, "width", "100%");
  auto height = config::get<std::string>(this->config_path, "height", "30");

  if (width.find("%") != std::string::npos) {
    this->opts->width = this->opts->monitor->bounds.width * (std::atoi(width.c_str()) / 100.0) + 0.5;
    this->opts->width -= this->opts->offset_x * 2;
  } else {
    this->opts->width = std::atoi(width.c_str());
  }

  if (height.find("%") != std::string::npos) {
    this->opts->height = this->opts->monitor->bounds.height * (std::atoi(height.c_str()) / 100.0) + 0.5;
    this->opts->width -= this->opts->offset_y * 2;
  } else {
    this->opts->height = std::atoi(height.c_str());
  }

  this->opts->background = config::get<std::string>(this->config_path, "background", defaults.background);
  this->opts->foreground = config::get<std::string>(this->config_path, "foreground", defaults.foreground);
  this->opts->linecolor = config::get<std::string>(this->config_path, "linecolor", defaults.linecolor);

  this->opts->bottom = config::get<bool>(this->config_path, "bottom", defaults.bottom);
  this->opts->dock = config::get<bool>(this->config_path, "dock", defaults.dock);
  this->opts->clickareas = config::get<int>(this->config_path, "clickareas", defaults.clickareas);

  this->opts->separator = config::get<std::string>(this->config_path, "separator", defaults.separator);

  this->opts->spacing = config::get<int>(this->config_path, "spacing", defaults.spacing);
  this->opts->lineheight = config::get<int>(this->config_path, "lineheight", defaults.lineheight);

  this->opts->padding_left = config::get<int>(this->config_path, "padding_left", defaults.padding_left);
  this->opts->padding_right = config::get<int>(this->config_path, "padding_right", defaults.padding_right);

  this->opts->module_margin_left = config::get<int>(this->config_path, "module_margin_left", defaults.module_margin_left);
  this->opts->module_margin_right = config::get<int>(this->config_path, "module_margin_right", defaults.module_margin_right);

  for (auto f : config::get_list<std::string>(this->config_path, "font")) {
    std::vector<std::string> font;
    string::split_into(f, ';', font);
    if (font.size() < 2)
      font.emplace_back("0");
    this->opts->fonts.emplace_back(std::make_unique<Font>(font[0], std::stoi(font[1])));
  }
}
示例#17
0
boolean CUSBDevice::Initialize (void)
{
	assert (m_pDeviceDesc == 0);
	m_pDeviceDesc = new TUSBDeviceDescriptor;
	assert (m_pDeviceDesc != 0);
	
	assert (m_pHost != 0);
	assert (m_pEndpoint0 != 0);
	
	assert (sizeof *m_pDeviceDesc >= USB_DEFAULT_MAX_PACKET_SIZE);
	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_DEVICE, DESCRIPTOR_INDEX_DEFAULT,
				    m_pDeviceDesc, USB_DEFAULT_MAX_PACKET_SIZE)
	    != USB_DEFAULT_MAX_PACKET_SIZE)
	{
		LogWrite (LogError, "Cannot get device descriptor (short)");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

	if (   m_pDeviceDesc->bLength	      != sizeof *m_pDeviceDesc
	    || m_pDeviceDesc->bDescriptorType != DESCRIPTOR_DEVICE)
	{
		LogWrite (LogError, "Invalid device descriptor");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

	m_pEndpoint0->SetMaxPacketSize (m_pDeviceDesc->bMaxPacketSize0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_DEVICE, DESCRIPTOR_INDEX_DEFAULT,
				    m_pDeviceDesc, sizeof *m_pDeviceDesc)
	    != (int) sizeof *m_pDeviceDesc)
	{
		LogWrite (LogError, "Cannot get device descriptor");

		delete m_pDeviceDesc;
		m_pDeviceDesc = 0;

		return FALSE;
	}

#ifndef NDEBUG
	//debug_hexdump (m_pDeviceDesc, sizeof *m_pDeviceDesc, FromDevice);
#endif
	
	u8 ucAddress = s_ucNextAddress++;
	if (ucAddress > USB_MAX_ADDRESS)
	{
		LogWrite (LogError, "Too many devices");

		return FALSE;
	}

	if (!m_pHost->SetAddress (m_pEndpoint0, ucAddress))
	{
		LogWrite (LogError, "Cannot set address %u", (unsigned) ucAddress);

		return FALSE;
	}
	
	SetAddress (ucAddress);

	assert (m_pConfigDesc == 0);
	m_pConfigDesc = new TUSBConfigurationDescriptor;
	assert (m_pConfigDesc != 0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_CONFIGURATION, DESCRIPTOR_INDEX_DEFAULT,
				    m_pConfigDesc, sizeof *m_pConfigDesc)
	    != (int) sizeof *m_pConfigDesc)
	{
		LogWrite (LogError, "Cannot get configuration descriptor (short)");

		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

	if (   m_pConfigDesc->bLength         != sizeof *m_pConfigDesc
	    || m_pConfigDesc->bDescriptorType != DESCRIPTOR_CONFIGURATION
	    || m_pConfigDesc->wTotalLength    >  MAX_CONFIG_DESC_SIZE)
	{
		LogWrite (LogError, "Invalid configuration descriptor");
		
		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

	unsigned nTotalLength = m_pConfigDesc->wTotalLength;

	delete m_pConfigDesc;

	m_pConfigDesc = (TUSBConfigurationDescriptor *) new u8[nTotalLength];
	assert (m_pConfigDesc != 0);

	if (m_pHost->GetDescriptor (m_pEndpoint0,
				    DESCRIPTOR_CONFIGURATION, DESCRIPTOR_INDEX_DEFAULT,
				    m_pConfigDesc, nTotalLength)
	    != (int) nTotalLength)
	{
		LogWrite (LogError, "Cannot get configuration descriptor");

		delete m_pConfigDesc;
		m_pConfigDesc = 0;

		return FALSE;
	}

#ifndef NDEBUG
	//debug_hexdump (m_pConfigDesc, nTotalLength, FromDevice);
#endif

	assert (m_pConfigParser == 0);
	m_pConfigParser = new CUSBConfigurationParser (m_pConfigDesc, nTotalLength);
	assert (m_pConfigParser != 0);

	if (!m_pConfigParser->IsValid ())
	{
		ConfigurationError (FromDevice);

		return FALSE;
	}

	CString *pNames = GetNames ();
	assert (pNames != 0);
	LogWrite (LogNotice, "Device %s found", (const char *) *pNames);
	delete pNames;

	unsigned nFunction = 0;
	u8 ucInterfaceNumber = 0;

	TUSBInterfaceDescriptor *pInterfaceDesc;
	while ((pInterfaceDesc = (TUSBInterfaceDescriptor *) m_pConfigParser->GetDescriptor (DESCRIPTOR_INTERFACE)) != 0)
	{
		if (   pInterfaceDesc->bInterfaceNumber != ucInterfaceNumber
		    && pInterfaceDesc->bInterfaceNumber != ucInterfaceNumber+1)
		{
			LogWrite (LogDebug, "Alternate setting %u ignored",
				  (unsigned) pInterfaceDesc->bAlternateSetting);

			if (pInterfaceDesc->bInterfaceNumber == ucInterfaceNumber+1)
			{
				ucInterfaceNumber++;
			}

			continue;
		}

		assert (m_pConfigParser != 0);
		assert (m_pFunction[nFunction] == 0);
		m_pFunction[nFunction] = new CUSBFunction (this, m_pConfigParser);
		assert (m_pFunction[nFunction] != 0);

		if (!m_pFunction[nFunction]->Initialize ())
		{
			LogWrite (LogError, "Cannot initialize function");

			delete m_pFunction[nFunction];
			m_pFunction[nFunction] = 0;

			continue;
		}

		CUSBFunction *pChild = 0;

		if (nFunction == 0)
		{
			pChild = CUSBDeviceFactory::GetDevice (m_pFunction[nFunction], GetName (DeviceNameVendor));
			if (pChild == 0)
			{
				pChild = CUSBDeviceFactory::GetDevice (m_pFunction[nFunction], GetName (DeviceNameDevice));
			}
		}

		if (pChild == 0)
		{
			CString *pName = m_pFunction[nFunction]->GetInterfaceName ();
			assert (pName != 0);
			if (pName->Compare ("unknown") != 0)
			{
				LogWrite (LogNotice, "Interface %s found", (const char *) *pName);

				pChild = CUSBDeviceFactory::GetDevice (m_pFunction[nFunction], pName);
			}
			else
			{
				delete pName;
			}
		}

		delete m_pFunction[nFunction];
		m_pFunction[nFunction] = 0;

		if (pChild == 0)
		{
			LogWrite (LogWarning, "Function is not supported");

			continue;
		}

		m_pFunction[nFunction] = pChild;

		if (++nFunction == USBDEV_MAX_FUNCTIONS)
		{
			LogWrite (LogWarning, "Too many functions per device");

			break;
		}

		ucInterfaceNumber++;
	}

	if (nFunction == 0)
	{
		LogWrite (LogWarning, "Device has no supported function");

		return FALSE;
	}

	return TRUE;
}