示例#1
0
void nsclient_core::settings_client::startup() {
	if (started_)
		return;
	if (!core_->boot_init(true)) {
		std::cout << "boot::init failed" << std::endl;
		return;
	}
	if (load_all_)
		core_->preboot_load_all_plugin_files();

	if (!core_->boot_load_all_plugins()) {
		std::cout << "boot::load_all_plugins failed!" << std::endl;
		return;
	}
	if (!core_->boot_start_plugins(false)) {
		std::cout << "boot::start_plugins failed!" << std::endl;
		return;
	}
	if (default_) {
		get_core()->update_defaults();
	}
	if (remove_default_) {
		std::cout << "Removing default values" << std::endl;
		get_core()->remove_defaults();
	}
	started_ = true;
}
示例#2
0
void nsclient_core::settings_client::dump_path(std::string root) {
	BOOST_FOREACH(const std::string &path, get_core()->get()->get_sections(root)) {
		if (!root.empty())
			dump_path(root + "/" + path);
		else
			dump_path(path);
	}
	BOOST_FOREACH(std::string key, get_core()->get()->get_keys(root)) {
		std::cout << root << "." << key << "=" << get_core()->get()->get_string(root, key) << std::endl;
	}
示例#3
0
bool Scheduler::handle_schedule(schedules::target_object item) {
	try {
		std::string response;
		nscapi::core_helper ch(get_core(), get_id());
		if (!ch.simple_query(item->command.c_str(), item->arguments, response)) {
			NSC_LOG_ERROR("Failed to execute: " + item->command);
			if (item->channel.empty()) {
				NSC_LOG_ERROR_WA("No channel specified for ", item->get_alias());
				return true;
			}
			nscapi::protobuf::functions::create_simple_submit_request(item->channel, item->command, NSCAPI::query_return_codes::returnUNKNOWN, "Command was not found: " + item->command, "", response);
			std::string result;
			get_core()->submit_message(item->channel, response, result);
			return true;
		}
		Plugin::QueryResponseMessage resp_msg;
		resp_msg.ParseFromString(response);
		Plugin::QueryResponseMessage resp_msg_send;
		resp_msg_send.mutable_header()->CopyFrom(resp_msg.header());
		BOOST_FOREACH(const Plugin::QueryResponseMessage::Response &p, resp_msg.payload()) {
			if (nscapi::report::matches(item->report, nscapi::protobuf::functions::gbp_to_nagios_status(p.result())))
				resp_msg_send.add_payload()->CopyFrom(p);
		}
		if (resp_msg_send.payload_size() > 0) {
			if (item->channel.empty()) {
				NSC_LOG_ERROR_STD("No channel specified for " + item->get_alias() + " mssage will not be sent.");
				return true;
			}
			nscapi::protobuf::functions::make_submit_from_query(response, item->channel, item->get_alias(), item->target_id, item->source_id);
			std::string result;
			if (!get_core()->submit_message(item->channel, response, result)) {
				NSC_LOG_ERROR_STD("Failed to submit: " + item->get_alias());
				return true;
			}
			std::string error;
			if (!nscapi::protobuf::functions::parse_simple_submit_response(result, error)) {
				NSC_LOG_ERROR_STD("Failed to submit " + item->get_alias() + ": " + error);
				return true;
			}
		} else {
			NSC_DEBUG_MSG("Filter not matched for: " + item->get_alias() + " so nothing is reported");
		}
		return true;
	} catch (nscapi::nscapi_exception &e) {
		NSC_LOG_ERROR_EXR("Failed to register command: ", e);
		return false;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("Exception: ", e);
		return false;
	} catch (...) {
		NSC_LOG_ERROR_EX(item->get_alias());
		return false;
	}
}
示例#4
0
文件: LUAScript.cpp 项目: jkells/nscp
bool LUAScript::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {
	//std::wstring appRoot = file_helpers::folders::get_local_appdata_folder(SZAPPNAME);
	try {

		root_ = get_core()->getBasePath();

		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias(alias, _T("lua"));

		settings.alias().add_path_to_settings()
			(_T("LUA SCRIPT SECTION"), _T("Section for the LUAScripts module."))

			(_T("scripts"), sh::fun_values_path(boost::bind(&LUAScript::loadScript, this, _1, _2)), 
			_T("LUA SCRIPTS SECTION"), _T("A list of scripts available to run from the LuaSCript module."))
			;

		settings.register_all();
		settings.notify();

// 		if (!scriptDirectory_.empty()) {
// 			addAllScriptsFrom(scriptDirectory_);
// 		}




		BOOST_FOREACH(script_container &script, scripts_) {
			try {
				instances_.push_back(script_wrapper::lua_script::create_instance(get_core(), get_id(), registry, script.alias, script.script.string()));
			} catch (const lua_wrappers::LUAException &e) {
				NSC_LOG_ERROR_STD(_T("Could not load script ") + script.to_wstring() + _T(": ") + e.getMessage());
			} catch (const std::exception &e) {
				NSC_LOG_ERROR_STD(_T("Could not load script ") + script.to_wstring() + _T(": ") + utf8::to_unicode(e.what()));
			}
		}

		// 	} catch (nrpe::server::nrpe_exception &e) {
		// 		NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what());
		// 		return false;
	} catch (const std::exception &e) {
		NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::to_unicode(e.what()));
		return false;
	} catch (...) {
		NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>"));
		return false;
	}

// 	std::list<std::wstring>::const_iterator it;
// 	for (it = commands.begin(); it != commands.end(); ++it) {
// 		loadScript((*it));
// 	}
	return true;
}
示例#5
0
		REGSettings(settings::settings_core *core, std::string context) : settings::settings_interface_impl(core, context), root(reg_key::from_context(context)) {
			std::list<std::string> list;
			reg_key path = get_reg_key("/includes");
			getValues_(path, list);
			get_core()->register_path(999, "/includes", "INCLUDED FILES", "Files to be included in the configuration", false, false);
			BOOST_FOREACH(const std::string &s, list) {
				op_string child = getString_(path, s);
				if (child) {
					get_core()->register_key(999, "/includes", s, settings::settings_core::key_string, "INCLUDED FILE", *child, *child, false, false);
					add_child_unsafe(*child);
				}
			}
示例#6
0
void set_cores(struct device *processors[], int processors_count)
{
	int cores_count = get_cores_count();

	//NO CORES FOUND (add an sample???)
	if (cores_count == 0)
		return;

	if (processors_count == 0)
		return;

	//ONE PROCESSOR (all the cores belongs to him)
	int i;
	if (processors_count == 1) {
		for (i = 0; i < cores_count; i++)
			set_child(processors[0], get_core(i));
		return;
	}
	//INCOMPLATIBLE DMIDECODE and CPUINFO || physical_id_uniq_count == 0
	int physical_id_uniq_count = get_physical_id_uniq_count();
	if (physical_id_uniq_count != processors_count) {
		for (i = 0; i < processors_count; i++)
			set_child(processors[i], get_core(0));
		return;
	}

	char *physical_id[cores_count];
	for (i = 0; i < cores_count; i++) {
		physical_id[i] = get_core_physical_id_value(i);
	}

	for (i = 0; i < processors_count; i++) {
		char *physical_id_uniq = get_physical_id_uniq(i);
		int j;
		for (j = 0; j < cores_count; j++) {
			if (physical_id_uniq && physical_id[j]
			    && strcmp(physical_id_uniq, physical_id[j]) == 0) {
				set_child(processors[i], get_core(j));
			}
		}
		delete(&physical_id_uniq);
	}

	for (i = 0; i < cores_count; i++) {
		delete(&physical_id[i]);
	}
}
示例#7
0
void CheckExternalScripts::list(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response) {
	namespace po = boost::program_options;
	namespace pf = nscapi::protobuf::functions;
	po::variables_map vm;
	po::options_description desc;
	bool json = false, query = false, lib = false;

	desc.add_options()
		("help", "Show help.")

		("json", po::bool_switch(&json),
			"Return the list in json format.")
		("query", po::bool_switch(&query),
			"List queries instead of scripts (for aliases).")
		("include-lib", po::bool_switch(&lib),
			"Do not ignore any lib folders.")

		;

	try {
		nscapi::program_options::basic_command_line_parser cmd(request);
		cmd.options(desc);

		po::parsed_options parsed = cmd.run();
		po::store(parsed, vm);
		po::notify(vm);
	} catch (const std::exception &e) {
		return nscapi::program_options::invalid_syntax(desc, request.command(), "Invalid command line: " + utf8::utf8_from_native(e.what()), *response);
	}

	if (vm.count("help")) {
		nscapi::protobuf::functions::set_response_good(*response, nscapi::program_options::help(desc));
		return;
	}
	std::string resp;
	json_spirit::Array data;

	if (query) {
		Plugin::RegistryRequestMessage rrm;
		Plugin::RegistryResponseMessage response;
		nscapi::protobuf::functions::create_simple_header(rrm.mutable_header());
		Plugin::RegistryRequestMessage::Request *payload = rrm.add_payload();
		payload->mutable_inventory()->set_fetch_all(true);
		payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_QUERY);
		std::string pb_response;
		get_core()->registry_query(rrm.SerializeAsString(), pb_response);
		response.ParseFromString(pb_response);
		BOOST_FOREACH(const ::Plugin::RegistryResponseMessage_Response &p, response.payload()) {
			BOOST_FOREACH(const ::Plugin::RegistryResponseMessage_Response_Inventory &i, p.inventory()) {
				if (json) {
					json_spirit::Value v = i.name();
					data.push_back(v);
				} else {
					resp += i.name() + "\n";
				}
			}
		}
	} else {
示例#8
0
bool CheckNSCP::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode) {
	start_ = boost::posix_time::microsec_clock::local_time();

	std::string path;
	sh::settings_registry settings(get_settings_proxy());
	crashFolder = get_core()->expand_path(CRASH_ARCHIVE_FOLDER);
	NSC_DEBUG_MSG_STD("Crash folder is: " + crashFolder.string());
	return true;
}
fun_info fun_info_manager::get(expr const & e) {
    auto it = m_cache_get.find(e);
    if (it != m_cache_get.end())
        return it->second;
    buffer<param_info> pinfos;
    auto result_deps = get_core(e, pinfos, std::numeric_limits<unsigned>::max(), true);
    fun_info r(pinfos.size(), to_list(pinfos), result_deps);
    m_cache_get.insert(mk_pair(e, r));
    return r;
}
示例#10
0
文件: fun_info.cpp 项目: sakas--/lean
fun_info get_fun_info(type_context & ctx, expr const & e) {
    fun_info_cache & cache = get_fun_info_cache_for(ctx);
    auto it = cache.m_cache_get.find(e);
    if (it != cache.m_cache_get.end())
        return it->second;
    buffer<param_info> pinfos;
    auto result_deps = get_core(ctx, e, pinfos, std::numeric_limits<unsigned>::max(), true);
    fun_info r(pinfos.size(), to_list(pinfos), result_deps);
    cache.m_cache_get.insert(mk_pair(e, r));
    return r;
}
示例#11
0
NSCAPI::nagiosReturn nscapi::core_helper::simple_query(const std::string command, const std::vector<std::string> & arguments, std::string & result) 
{
	std::string request;
	try {
		nscapi::protobuf::functions::create_simple_query_request(command, arguments, request);
	} catch (std::exception &e) {
		CORE_LOG_ERROR_EXR("Failed to extract return message", e);
		return NSCAPI::returnUNKNOWN;
	}
	return get_core()->query(request, result);
}
fun_info fun_info_manager::get(expr const & e, unsigned nargs) {
    expr_unsigned key(e, nargs);
    auto it = m_cache_get_nargs.find(key);
    if (it != m_cache_get_nargs.end())
        return it->second;
    buffer<param_info> pinfos;
    auto result_deps = get_core(e, pinfos, nargs, true);
    fun_info r(pinfos.size(), to_list(pinfos), result_deps);
    m_cache_get_nargs.insert(mk_pair(key, r));
    return r;
}
示例#13
0
	void camera::update( float lag )
	{
		tnode::update( lag );
		const math::matrix44 mat = m_local_transform.get_matrix();
		math::vector3 eye(0,0,0), lookat(0,0,1);
		math::vec_transform( &eye, &mat );
		math::vec_transform( &lookat, &mat );
		math::matrix44 viewtransform;
		math::build_matrix_lookat_lh( &viewtransform, &eye, &lookat, &vector3(0,1,0) );
		get_core()->get_scene_renderer()->set_viewtransform(viewtransform);
	}
示例#14
0
void SyslogClient::add_command(std::string key, std::string arg) {
	try {
		nscapi::core_helper core(get_core(), get_id());
		std::string k = client_.add_command(key, arg);
		if (!k.empty())
			core.register_command(k.c_str(), "Syslog relay for: " + key);
	} catch (const std::exception &e) {
		NSC_LOG_ERROR_EXR("Failed to add command: " + key, e);
	} catch (...) {
		NSC_LOG_ERROR_EX("Failed to add command: " + key);
	}
}
示例#15
0
void NRDPClient::add_command(std::string name, std::string args) {
	nscapi::core_helper core(get_core(), get_id());
	try {
		std::string key = commands.add_command(name, args);
		if (!key.empty())
			core.register_command(key, "NRPE relay for: " + name);
	} catch (boost::program_options::validation_error &e) {
		NSC_LOG_ERROR_EXR("Failed to add command: " + name, e);
	} catch (...) {
		NSC_LOG_ERROR_EX("Failed to add target: " + name);
	}
}
示例#16
0
int nsclient_core::settings_client::migrate_to(std::string target) {
	try {
		debug_msg("Migrating to: " + expand_context(target));
		get_core()->migrate_to(expand_context(target));
		return 1;
	} catch (settings::settings_exception e) {
		error_msg("Failed to initialize settings: " + e.reason());
	} catch (...) {
		error_msg("FATAL ERROR IN SETTINGS SUBSYTEM");
	}
	return -1;
}
示例#17
0
文件: fun_info.cpp 项目: sakas--/lean
fun_info get_fun_info(type_context & ctx, expr const & e, unsigned nargs) {
    fun_info_cache & cache = get_fun_info_cache_for(ctx);
    expr_unsigned key(e, nargs);
    auto it = cache.m_cache_get_nargs.find(key);
    if (it != cache.m_cache_get_nargs.end())
        return it->second;
    buffer<param_info> pinfos;
    auto result_deps = get_core(ctx, e, pinfos, nargs, true);
    fun_info r(pinfos.size(), to_list(pinfos), result_deps);
    cache.m_cache_get_nargs.insert(mk_pair(key, r));
    return r;
}
示例#18
0
void CheckMKClient::add_command(std::string name, std::string args) {
	try {
		nscapi::core_helper core(get_core(), get_id());
		std::string key = commands.add_command(name, args);
		if (!key.empty())
			core.register_command(key.c_str(), "check_mk relay for: " + name);
	} catch (const std::exception &e) {
		NSC_LOG_ERROR_EXR("Failed to add command: " + name, e);
	} catch (...) {
		NSC_LOG_ERROR_EX("Failed to add command: " + name);
	}
}
示例#19
0
bool DistributedClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) {
	std::map<std::wstring,std::wstring> commands;

	try {


		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias(_T("distributed"), alias, _T("client"));
		target_path = settings.alias().get_settings_path(_T("targets"));

		settings.alias().add_path_to_settings()
			(_T("Distributed NSCP CLIENT SECTION"), _T("Section for NSCP active/passive check module."))

			(_T("handlers"), sh::fun_values_path(boost::bind(&DistributedClient::add_command, this, _1, _2)), 
			_T("CLIENT HANDLER SECTION"), _T(""))

			(_T("targets"), sh::fun_values_path(boost::bind(&DistributedClient::add_target, this, _1, _2)), 
			_T("REMOTE TARGET DEFINITIONS"), _T(""))

			;

		settings.alias().add_key_to_settings()
			(_T("channel"), sh::wstring_key(&channel_, _T("DNSCP")),
			_T("CHANNEL"), _T("The channel to listen to."))

			;

		settings.register_all();
		settings.notify();

		targets.add_missing(get_settings_proxy(), target_path, _T("default"), _T(""), true);


		get_core()->registerSubmissionListener(get_id(), channel_);
		register_command(_T("dnscp_query"), _T("Submit a query to a remote host via NSCP"));
		register_command(_T("dnscp_forward"), _T("Forward query to remote NSCP host"));
		register_command(_T("dnscp_submit"), _T("Submit a query to a remote host via NSCP"));
		register_command(_T("dnscp_exec"), _T("Execute remote command on a remote host via NSCP"));
		register_command(_T("dnscp_help"), _T("Help on using NSCP Client"));

	} catch (nscapi::nscapi_exception &e) {
		NSC_LOG_ERROR_STD(_T("NSClient API exception: ") + utf8::to_unicode(e.what()));
		return false;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_STD(_T("Exception caught: ") + utf8::to_unicode(e.what()));
		return false;
	} catch (...) {
		NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>"));
		return false;
	}
	return true;
}
示例#20
0
void CheckNSCP::check_nscp_version(const Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response) {
	nscp_version version;
	try {
		version = nscp_version(get_core()->getApplicationVersionString());
	} catch (const nsclient::nsclient_exception &e) {
		nscapi::protobuf::functions::set_response_bad(*response, "Failed to parse version: " + e.reason());
		return;
	} catch (const std::exception &e) {
		nscapi::protobuf::functions::set_response_bad(*response, "Failed to parse version: " + utf8::utf8_from_native(e.what()));
		return;
	}
	check_nscp_version::check(version, request, response);
}
示例#21
0
void NSCAServer::handle(nsca::packet p) {
	std::string response;
	std::string::size_type pos = p.result.find('|');
	nscapi::core_helper helper(get_core(), get_id());
	if (pos != std::string::npos) {
		std::string msg = p.result.substr(0, pos);
		std::string perf = p.result.substr(++pos);
		helper.submit_simple_message(channel_, p.service, nscapi::plugin_helper::int2nagios(p.code), msg, perf, response);
	} else {
		std::string empty, msg = p.result;
		helper.submit_simple_message(channel_, p.service, nscapi::plugin_helper::int2nagios(p.code), msg, empty, response);
	}
}
示例#22
0
bool nscapi::core_helper::submit_simple_message(const std::string channel, const std::string command, const NSCAPI::nagiosReturn code, const std::string & message, const std::string & perf, std::string & response) {
	std::string request, buffer;
	nscapi::protobuf::functions::create_simple_submit_request(channel, command, code, message, perf, request);
	NSCAPI::nagiosReturn ret = get_core()->submit_message(channel, request, buffer);
	if (ret == NSCAPI::returnIgnored) {
		response = "No handler for this message";
		return false;
	}
	if (buffer.size() == 0) {
		response = "Missing response from submission";
		return false;
	}
	nscapi::protobuf::functions::parse_simple_submit_response(buffer, response);
	return ret == NSCAPI::isSuccess;
}
示例#23
0
void on_remove_address_clicked(GtkButton *button,gpointer user_data)
{
	GtkTreeSelection *select;
	GtkTreeIter iter;
	GtkTreeModel *model;
	GtkWidget *address_list=lookup_widget(gtk_widget_get_toplevel(GTK_WIDGET(button)),"address_list");
	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (address_list));
	if (gtk_tree_selection_get_selected (select, &model, &iter))
	{
		LinphoneFriend *lf=NULL;
		gtk_tree_model_get(model,&iter,FRIEND_REFERENCE,&lf,-1);
		linphone_core_remove_friend(get_core(),lf);
		gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
	}
}
示例#24
0
NSCAPI::nagiosReturn nscapi::core_helper::simple_query(const std::string command, const std::list<std::string> & arguments, std::string & result) 
{
	std::string request;
	try {
		nscapi::protobuf::functions::create_simple_query_request(command, arguments, request);
	} catch (std::exception &e) {
		CORE_LOG_ERROR_EXR("Failed to extract return message: ", e);
		return NSCAPI::returnUNKNOWN;
	}
	NSCAPI::nagiosReturn retC = get_core()->query(request, result);
	if (retC != NSCAPI::isSuccess) {
		CORE_LOG_ERROR("Failed to execute command: " + command);
	}
	return retC;
}
示例#25
0
bool NSCPClient::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode ) {
	std::map<std::wstring,std::wstring> commands;

	try {

		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias("nscp", alias, "client");
		target_path = settings.alias().get_settings_path("targets");

		settings.alias().add_path_to_settings()
			("NSCP CLIENT SECTION", "Section for NSCP active/passive check module.")

			("handlers", sh::fun_values_path(boost::bind(&NSCPClient::add_command, this, _1, _2)), 
			"CLIENT HANDLER SECTION", "",
			"CLIENT HANDLER", "For more configuration options add a dedicated section")

			("targets", sh::fun_values_path(boost::bind(&NSCPClient::add_target, this, _1, _2)), 
			"REMOTE TARGET DEFINITIONS", "",
			"TARGET", "For more configuration options add a dedicated section")
			;

		settings.alias().add_key_to_settings()
			("channel", sh::string_key(&channel_, "NSCP"),
			"CHANNEL", "The channel to listen to.")

			;

		settings.register_all();
		settings.notify();

		targets.add_samples(get_settings_proxy(), target_path);
		targets.add_missing(get_settings_proxy(), target_path, "default", "", true);
		nscapi::core_helper::core_proxy core(get_core(), get_id());
		core.register_channel(channel_);
	} catch (nscapi::nscapi_exception &e) {
		NSC_LOG_ERROR_EXR("load", e);
		return false;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("load", e);
		return false;
	} catch (...) {
		NSC_LOG_ERROR_EX("load");
		return false;
	}
	return true;
}
示例#26
0
bool SMTPClient::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode) {
	std::wstring template_string, sender, recipient;
	try {
		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias("SMTP", alias, "client");
		client_.set_path(settings.alias().get_settings_path("targets"));

		settings.alias().add_path_to_settings()
			("SMTP CLIENT SECTION", "Section for SMTP passive check module.")
			("handlers", sh::fun_values_path(boost::bind(&SMTPClient::add_command, this, _1, _2)),
				"CLIENT HANDLER SECTION", "",
				"CLIENT HANDLER", "For more configuration options add a dedicated section")

			("targets", sh::fun_values_path(boost::bind(&SMTPClient::add_target, this, _1, _2)),
				"REMOTE TARGET DEFINITIONS", "",
				"TARGET", "For more configuration options add a dedicated section")
			;

		settings.alias().add_key_to_settings()
			("channel", sh::string_key(&channel_, "SMTP"),
				"CHANNEL", "The channel to listen to.")

			;

		settings.register_all();
		settings.notify();

		client_.finalize(get_settings_proxy());

		nscapi::core_helper core(get_core(), get_id());
		core.register_channel(channel_);
	} catch (const nsclient::nsclient_exception &e) {
		NSC_LOG_ERROR_EXR("load", e);
		return false;
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("NSClient API exception: ", e);
		return false;
	} catch (...) {
		NSC_LOG_ERROR_EX("NSClient API exception: ");
		return false;
	}
	return true;
}
示例#27
0
void fill_address_book(GtkWidget *address_list){
	GtkListStore *store;
	GtkTreeIter iter;
	GtkTreeModel *model;
	MSList *elem;
	gchar *tmpstr;
	/* fill the store */
	elem=linphone_core_get_friend_list(get_core());
	model=gtk_tree_view_get_model(GTK_TREE_VIEW(address_list));
	store=GTK_LIST_STORE(model);
	gtk_list_store_clear(store);
	for(;elem!=NULL;elem=ms_list_next(elem)){
		LinphoneFriend *lf=(LinphoneFriend*)elem->data;
		tmpstr=linphone_friend_get_url(lf);
		gtk_list_store_append(store,&iter);
		gtk_list_store_set(store,&iter,SIP_ADDRESS_COLUMN,tmpstr,FRIEND_REFERENCE,(gpointer)lf,-1);
		ms_free(tmpstr);
	}
}
示例#28
0
/**
	Called when a new job arrives.
 
	If multiple cores are idle, the job should be assigned to the core with the
	lowest id.
	If the job arriving should be scheduled to run during the next
	time cycle, return the zero-based index of the core the job should be
	scheduled on. If another job is already running on the core specified,
	this will preempt the currently running job.
	Assumptions:
		- You may assume that every job wil have a unique arrival time.
	@param job_number a globally unique identification number of the job arriving.
	@param time the current time of the simulator.
	@param running_time the total number of time units this job will run before it will be finished.
	@param priority the priority of the job. (The lower the value, the higher the priority.)
	@return index of core job should be scheduled on
	@return -1 if no scheduling changes should be made. 
 
 */
int scheduler_new_job(int job_number, int time, int running_time, int priority)
{
	int i;
	inc_time(time);
	job_t* job = create_job(job_number, time, running_time, priority);

	if ( (i = get_core()) != -1 )
	{
		insert_job(i,job);
		return i;
	}//if
	else if ( is_prempt() )
	{
		i = preempt(job);
		if ( i == -1 )
			priqueue_offer(jobs,job);
		return i;
	}//else if
	priqueue_offer(jobs,job);
	return -1;
}//scheduler_new_job
示例#29
0
bool NRPEClient::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode mode) {

	try {

		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias("NRPE", alias, "client");
		target_path = settings.alias().get_settings_path("targets");

		settings.alias().add_path_to_settings()
			("NRPE CLIENT SECTION", "Section for NRPE active/passive check module.")

			("handlers", sh::fun_values_path(boost::bind(&NRPEClient::add_command, this, _1, _2)), 
			"CLIENT HANDLER SECTION", "")

			("targets", sh::fun_values_path(boost::bind(&NRPEClient::add_target, this, _1, _2)), 
			"REMOTE TARGET DEFINITIONS", "")
			;

		settings.alias().add_key_to_settings()
			("channel", sh::string_key(&channel_, "NRPE"),
			"CHANNEL", "The channel to listen to.")

			;

		settings.register_all();
		settings.notify();

		nscapi::core_helper::core_proxy core(get_core(), get_id());
		targets.add_samples(get_settings_proxy(), target_path);
		targets.ensure_default(get_settings_proxy(), target_path);
		core.register_channel(channel_);
	} catch (std::exception &e) {
		NSC_LOG_ERROR_EXR("loading", e);
		return false;
	} catch (...) {
		NSC_LOG_ERROR_EX("loading");
		return false;
	}
	return true;
}
示例#30
0
gint contact_ok(GtkWidget *dialog){
	gchar *name,*sipaddr;
	gchar *url;
	gboolean add=FALSE;
	GtkWidget *ab;
	LinphoneFriend *lf;
	int err;
	lf=(LinphoneFriend*)g_object_get_data(G_OBJECT(dialog),"friend_ref");
	add=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(dialog),"add"));
	name=gtk_editable_get_chars(GTK_EDITABLE(lookup_widget(dialog,"name")),0,-1);
	sipaddr=gtk_editable_get_chars(GTK_EDITABLE(lookup_widget(dialog,"sipaddr")),0,-1);
	url=g_strdup_printf("%s <%s>",name,sipaddr);
	/* workaround a bug in osip ? */
	/* something doesn't like addresses like "machin <<sip:truc@bidule>>" */
	if (strchr(sipaddr,'<')==NULL){
		err=linphone_friend_set_sip_addr(lf,url);
	}else err=-1;
	if (err<0){
		linphone_gnome_ui_display_something(get_uiobj(),GTK_MESSAGE_WARNING,_("Bad sip address: a sip address looks like sip:user@domain"));
		linphone_friend_destroy(lf);
		g_free(name);
		g_free(sipaddr);
		g_free(url);
		return -1;		
	}
	g_free(name);
	g_free(sipaddr);
	g_free(url);
	linphone_friend_set_proxy(lf,proxy_combo_box_get_selected(lookup_widget(dialog,"proxy")));
	linphone_friend_set_inc_subscribe_policy(lf,gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(dialog,"pol"))));
	linphone_friend_send_subscribe(lf,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(dialog,"send_subscribe"))));
	if (add){
		linphone_core_add_friend(get_core(),lf);
	}
	else linphone_friend_done(lf);
	/* ask the address book to redraw itself */
	ab=g_object_get_data(G_OBJECT(dialog),"address_book");
	if (ab!=NULL) fill_address_book(lookup_widget(ab,"address_list"));
	return 0;
}