Exemplo n.º 1
0
int32_t sbuxton_get_int32(char *key)
{
	/* make sure client connection is open */
	if (!_client_connection()) {
		errno = ENOTCONN;
		return -1;
	}
	/* create key */
	BuxtonKey _key = buxton_key_create(_group, key, _layer, BUXTON_TYPE_INT32);
	/* return value */
	vstatus ret;
	ret.type = BUXTON_TYPE_INT32;
	saved_errno = errno;
	/* get value */
	if (buxton_get_value(client, _key, _bg_cb, &ret, true)) {
		buxton_debug("Get int32_t call failed.\n");
	}
	if (!ret.status) {
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	_client_disconnect();
	return ret.val.i32val;
}
Exemplo n.º 2
0
int main(void)
{
	BuxtonClient client;
	BuxtonKey key;
	struct pollfd pfd[1];
	int r;
	int32_t gvalue = -1;
	int fd;

	if ((fd = buxton_open(&client)) < 0) {
		printf("couldn't connect\n");
		return -1;
	}

/*
 * A fully qualified key-name is being created since both group and key-name are not null.
 * Group: "hello", Key-name: "test", Layer: "user", DataType: INT
 */
	key = buxton_key_create("hello", "test", "user", BUXTON_TYPE_INT32);
	if (!key) {
		return -1;
	}

	if (buxton_get_value(client, key, get_cb,
			     &gvalue, false)) {
		printf("get call failed to run\n");
		return -1;
	}

	pfd[0].fd = fd;
	pfd[0].events = POLLIN;
	pfd[0].revents = 0;
	r = poll(pfd, 1, 5000);

	if (r <= 0) {
		printf("poll error\n");
		return -1;
	}

	if (!buxton_client_handle_response(client)) {
		printf("bad response from daemon\n");
		return -1;
	}

	if (gvalue >= 0) {
		printf("got value: %d\n", gvalue);
	}

	buxton_key_free(key);
	buxton_close(client);
	return 0;
}
Exemplo n.º 3
0
int main(void){
	BuxtonClient client;
	int fd;/*file descriptor*/
	BuxtonKey key;
	struct response_info gotten;
	/*open client*/
	if (buxton_open(&client)<0){
		printf("Failed to open client.\n");
		return -1;
	}
	
	printf("Connection successful.\n");
	/*create a key*/
	key=buxton_key_create("test_group","test_key_name","user",INT32);	
	/*print group name*/
	printf("group: %s \n", buxton_key_get_group(key));	
	/*print the key name*/
	printf("key: %s \n", buxton_key_get_name(key));
	/*print the layer name*/
	printf("layer: %s \n", buxton_key_get_layer(key));
	/*unset the value of the key*/
	if (buxton_unset_value(client, key, usv_cb, NULL,true)){
		printf("Unset call failed to run.\n");
	}
	key=buxton_key_create("test_group","test_key_name","user",UINT32);
	/*get value*/
	if(buxton_get_value(client, key, gv_cb, &gotten,true)){
		printf("get_value call failed.\n");
	}
	if(!gotten.status){
		printf("No value has been set.\n");
		/*create a group and set a key value*/	
		printf("setting value...\n");
		my_set_group(client,key);
		my_set_key(client,key);
	}else{
	/*print the gotten value*/
		my_set_key(client,key);
		printf("the value is was changed from %i.\n", gotten.value);
	}
	/*free the key*/
	buxton_key_free(key);
	/*close the client*/
	buxton_close(client);



}
Exemplo n.º 4
0
bool buxtond_get_bool(char *key)
{
	/*make sure client connection is open*/
	client_connection();
	/*create key*/
	BuxtonKey _key = buxton_key_create(_group, strdup(key), _layer, BOOLEAN);
	/*return value*/
	struct vstatus ret;
	ret.type = BOOLEAN;
	save_errno();
	/*get value*/
	if (buxton_get_value(client, _key, bgb_cb, &ret, true)){
		printf("Get bool call failed.\n");
	}
	if (!ret.status){
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	buxton_key_free(_key);
	return ret.bval;
}
Exemplo n.º 5
0
int main(void)
{
	BuxtonClient client;
	BuxtonKey key;
	int32_t gvalue = -1;
	int fd;

	if ((fd = buxton_open(&client)) < 0) {
		printf("couldn't connect\n");
		return -1;
	}

/*
 * A fully qualified key-name is being created since both group and key-name are not null.
 * Group: "hello", Key-name: "test", Layer: "user", DataType: INT
 */
	key = buxton_key_create("hello", "test", "user", INT32);
	if (!key) {
		return -1;
	}

	if (buxton_get_value(client, key, get_cb,
			     &gvalue, true)) {
		printf("get call failed to run\n");
		return -1;
	}


	if (gvalue >= 0) {
		printf("got value: %d\n", gvalue);
	}

	buxton_key_free(key);
	buxton_close(client);
	return 0;
}