Example #1
0
int main(int argc, char **argv)
{
	abus_t *abus;
	int ret;

	abus = abus_init(NULL);

	ret = abus_decl_method(abus, "examplearraysvc", "sqr", &svc_array_sqr_cb,
					ABUS_RPC_FLAG_NONE,
					"square cookie",
					"Compute square value of all the elements of an array. Serves as an example of how to deal with array in A-Bus",
					"k:i:some contant,my_array:(a:i:value to be squared,arg_index:i:index of arg for demo):array of stuff",
					"res_k:i:same contant,res_array:(res_a:i:squared value):array of squared stuff");
	if (ret != 0) {
		abus_cleanup(abus);
		return EXIT_FAILURE;
	}

	/* do other stuff */
	sleep(10000);

	abus_cleanup(abus);

	return EXIT_SUCCESS;
}
Example #2
0
int main(int argc, char **argv)
{
	abus_t *abus;
	const char *servicename = "exampleattrsvc";
	int i, ret;

	int my_int = 42;
	int my_auto_count = 0;


	abus = abus_init(NULL);

	ret = abus_decl_attr_int(abus, servicename, "tree.some_int", &my_int,
					ABUS_RPC_FLAG_NONE,
					"Some integer, for demo purpose");
	if (ret != 0) {
	    abus_cleanup(abus);
	    return EXIT_FAILURE;
	}

	/* No pointer is given for some_other_int, hence it will
	   be auto-allocated by libabus, and initialized to zero.
	   Access must be done through get and set.
	 */
	abus_decl_attr_int(abus, servicename, "tree.some_other_int", NULL,
					ABUS_RPC_FLAG_NONE,
					"Some other integer, still for demo purpose");

	abus_decl_attr_int(abus, servicename, "tree.auto_count", &my_auto_count,
					ABUS_RPC_FLAG_NONE,
					"Counter incremented every 5 seconds");

	/* do other stuff */
	for (i = 0; i < 1000; i++) {
		sleep(5);

		my_auto_count++;
		/* trigger event notification */
		abus_attr_changed(abus, servicename, "tree.auto_count");
	}

	abus_cleanup(abus);

	return EXIT_SUCCESS;
}
Example #3
0
int main(int argc, char **argv)
{
	abus_t *abus;
	CExamplesvc *examplesvc = new CExamplesvc("foo");
	int ret;

	abus = abus_init(NULL);

	ret = abus_decl_method_cxx(abus, "examplesvc", "sum", examplesvc, svc_sum_cb,
					ABUS_RPC_FLAG_NONE,
					"Compute summation of two integers",
					"a:i:first operand,b:i:second operand",
					"res_value:i:summation");
	if (ret != 0) {
		abus_cleanup(abus);
		return EXIT_FAILURE;
	}

	ret = abus_decl_method_cxx(abus, "examplesvc", "mult", examplesvc, svc_mult_cb,
					ABUS_RPC_FLAG_NONE,
					"Compute multiplication of two integers",
					"a:i:first operand,b:i:second operand",
					"res_value:i:multiplication");
	if (ret != 0) {
		abus_cleanup(abus);
		return EXIT_FAILURE;
	}

	/* do other stuff */
	sleep(10000);

	delete examplesvc;

	abus_cleanup(abus);

	return EXIT_SUCCESS;
}
Example #4
0
int main(int argc, char **argv)
{
	abus_t *abus;
	const char *service_name;
	int ret, opt;

	while ((opt = getopt(argc, argv, "hvVT")) != -1) {
		switch (opt) {
		case 'h':
			usage(argv[0], EXIT_SUCCESS);
			break;
		case 'v':
			++opt_verbose;
			setenv("ABUS_MSG_VERBOSE", "1", 1);
			break;
		case 'T':
			opt_rpc_threaded = 1;
			break;
		case 'V':
			printf("%s: %s\n%s", argv[0], abus_get_version(), abus_get_copyright());
			exit(EXIT_SUCCESS);
			break;
		default:
			break;
		}
	}
	if (optind+3 > argc)
		usage(argv[0], EXIT_FAILURE);

	abus = abus_init(NULL);

	service_name = argv[optind++];

	while (optind+2 <= argc) {
		const char *method_name = argv[optind++];
		const char *method_command = argv[optind++];

		ret = abus_decl_method(abus, service_name,
					method_name,
					&svc_rpc_caller,
					opt_rpc_threaded ? ABUS_RPC_THREADED : ABUS_RPC_FLAG_NONE,
					(void*)method_command,
					NULL, NULL, NULL);
		if (ret != 0) {
			fprintf(stderr, "A-Bus method declaration failed: %s\n", abus_strerror(ret));
			abus_cleanup(abus);
			exit(EXIT_FAILURE);
		}
	}

	ret = abus_decl_method(abus, service_name,
				"terminate",
				&svc_terminate_cb,
				ABUS_RPC_FLAG_NONE,
				NULL,
				"Terminate service", NULL, NULL);
	if (ret != 0) {
		abus_cleanup(abus);
		exit(EXIT_FAILURE);
	}

	/* do other stuff */
	while(!terminate) {
		sleep(1);
	}

	abus_cleanup(abus);

	return EXIT_SUCCESS;
}
int wpa_abus_init(struct wpa_supplicant *wpa) {
    abus_t *abus;
    int ret;
    abus_conf_t abus_conf;
    int fd=0;
    abus = abus_init(NULL);

    abus_get_conf(abus, &abus_conf);
    
    abus_conf.poll_operation = 1;
    abus_set_conf(abus, &abus_conf);
    
    if(ret == -1)
    	return EXIT_FAILURE;
    

    ret = abus_decl_method(abus, "wpa_supp", "ap_scan", &svc_ap_scan_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "Send a notification to begin scanning",
                                            "a:i:type of ap_scan (0,1,2)",
                                            " ");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }
    ret = abus_decl_method(abus, "wpa_supp", "scan_results", &svc_scan_results_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "Read the results of scanning",
                                            "",
                                            "reply:s:Read the results");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }
    ret = abus_decl_method(abus, "wpa_supp", "add_network", &svc_add_network_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "add a network",
                                            "",
                                            "");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }
    ret = abus_decl_method(abus, "wpa_supp", "set_network", &svc_set_network_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "Set a network",
                                            "str:s:write the commande : <network id> <variable name> <value>",
                                            "");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }
    ret = abus_decl_method(abus, "wpa_supp", "select_network", &svc_select_network_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "Select a network",
                                            "str:s:write the id of the network",
                                            "");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }
    ret = abus_decl_method(abus, "wpa_supp", "remove_network", &svc_remove_network_cb,
                                            ABUS_RPC_FLAG_NONE,
                                            wpa,
                                            "remove a network",
                                            "str:s:write the id of the network",
                                            "");
    if (ret != 0) {
        abus_cleanup(abus);
        return EXIT_FAILURE;
    }

    fd = abus_get_fd(abus);
    ret = eloop_register_read_sock(fd, wpa_abus_event,wpa, abus);


    return EXIT_SUCCESS;
}