コード例 #1
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);



}
コード例 #2
0
ファイル: lbuxtonsimple.c プロジェクト: jobol/buxton
/* Set and get char * value for buxton key with type BUXTON_TYPE_STRING */
void sbuxton_set_string(char *key, char *value )
{
	/* make sure client connection is open */
	if (!_client_connection()) {
		errno = ENOTCONN;
		return;
	}
	/* create key */
	BuxtonKey _key = buxton_key_create(_group, key, _layer, BUXTON_TYPE_STRING);
	/* return value and status */
	vstatus ret;
	ret.type = BUXTON_TYPE_STRING;
	ret.val.sval = value;
	saved_errno = errno;
	/* set value */
	if (buxton_set_value(client, _key, value, _bs_cb, &ret, true)) {
		buxton_debug("Set string call failed.\n");
	}
	if (!ret.status) {
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	_client_disconnect();
}
コード例 #3
0
ファイル: lbuxtonsimple.c プロジェクト: jobol/buxton
/* Set and get int32_t value for buxton key with type BUXTON_TYPE_INT32 */
void sbuxton_set_int32(char *key, int32_t value)
{
	/* make sure client connection is open */
	if (!_client_connection()) {
		errno = ENOTCONN;
		return;
	}
	/* create key  */
	BuxtonKey _key = buxton_key_create(_group, key, _layer, BUXTON_TYPE_INT32);
	/* return value and status */
	vstatus ret;
	ret.type = BUXTON_TYPE_INT32;
	ret.val.i32val = value;
	saved_errno = errno;
	/* call buxton_set_value for type BUXTON_TYPE_INT32 */
	if (buxton_set_value(client, _key, &value, _bs_cb, &ret, true)) {
		buxton_debug("Set int32_t call failed.\n");
		return;
	}
	if (!ret.status) {
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	_client_disconnect();
}
コード例 #4
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
/*Initialization of group*/
void buxtond_set_group(char *group, char *layer)
{
	client_connection();
	save_errno();
	if(_layer){
		free(_layer);
	}
	if(_group){
		free(_group);
	}
	_layer = strdup(layer);
	if(!_layer){
		printf("Layer assignment failed. Aborting operation.\n");
		return;
	}
	_group = strdup(group);
	if(!_group){
		printf("Group assignment failed. Aborting operation.\n");
		return;
	}
	BuxtonKey g = buxton_key_create(_group, NULL, _layer, STRING);
	int status;
	if (buxton_create_group(client, g, cg_cb, &status, true)){
		printf("Create group call failed.\n");
	} else {
		printf("Switched to group: %s, layer: %s.\n", buxton_key_get_group(g), buxton_key_get_layer(g));
		errno = saved_errno;
	}
	buxton_key_free(g);
}
コード例 #5
0
ファイル: lbuxtonsimple.c プロジェクト: jobol/buxton
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;
}
コード例 #6
0
ファイル: lbuxtonsimple.c プロジェクト: jobol/buxton
/* Initialization of group */
void sbuxton_set_group(char *group, char *layer)
{
	if (!_client_connection()) {
		errno = ENOTCONN;
		return;
	}
	saved_errno = errno;
	int status = 0;
	/* strcpy the name of the layer and group*/
	strncpy(_layer, layer, MAX_LG_LEN-1);
	strncpy(_group, group, MAX_LG_LEN-1);
	/* In case a string is longer than MAX_LG_LEN, set the last byte to null */
	_layer[MAX_LG_LEN -1] = '\0';
	_group[MAX_LG_LEN -1] = '\0';
	BuxtonKey g = buxton_key_create(_group, NULL, _layer, BUXTON_TYPE_STRING);
	buxton_debug("buxton key group = %s\n", buxton_key_get_group(g));
	if (buxton_create_group(client, g, _cg_cb, &status, true)
		|| !status) {
		buxton_debug("Create group call failed.\n");
		errno = EBADMSG;
	} else {
		buxton_debug("Switched to group: %s, layer: %s.\n", buxton_key_get_group(g),
	buxton_key_get_layer(g));
		errno = saved_errno;
	}
	_client_disconnect();
}
コード例 #7
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
BuxtonKey buxtond_create_group2(char *group_name, char *layer)
{
	client_connection();
	BuxtonKey group = buxton_key_create(group_name, NULL, layer, STRING);
	if (buxton_create_group(client, group, NULL, NULL, true)){
		printf("Create group call failed.\n");
		buxton_key_free(group);
		return;
	}
	return group;
	/*Buxton free key? TODO*/
}
コード例 #8
0
void my_set_group(BuxtonClient client, BuxtonKey key)
{
	BuxtonKey group;
	/*create a group*/
	group=buxton_key_create("test_group",NULL,"user",STRING);
	if(buxton_create_group(client,group,NULL,NULL,true)){
		printf("create group call failed.\n");
		buxton_key_free(group);
		return;
	}
	buxton_key_free(group);
}
コード例 #9
0
ファイル: helloget.c プロジェクト: jobol/buxton
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;
}
コード例 #10
0
ファイル: helloset.c プロジェクト: jobol/buxton
int main(void)
{
	BuxtonClient client;
	BuxtonKey key;
	struct pollfd pfd[1];
	int r;
	int fd;
	int32_t set;

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

	key = buxton_key_create("hello", "test", "user", BUXTON_TYPE_INT32);
	if (!key) {
		return -1;
	}

	set = 10;

	if (buxton_set_value(client, key, &set, set_cb,
			     NULL, false)) {
		printf("set 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;
	}

	buxton_key_free(key);
	buxton_close(client);
	return 0;
}
コード例 #11
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
void buxtond_set_bool(char *key, bool value)
{
	/*make sure client connection is open*/
	client_connection();
	/*create key*/
	BuxtonKey _key = buxton_key_create(_group, strdup(key), _layer, BOOLEAN);
	/*Return value and status*/
	struct vstatus ret;
	ret.type = BOOLEAN;
	ret.bval = value;
	save_errno();
	if(buxton_set_value(client, _key, &value, bs_cb, &ret, true)){
		printf("Set bool call failed.\n");
	}
	if (!ret.status){
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	buxton_key_free(_key);
}
コード例 #12
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
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;
}
コード例 #13
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
void buxtond_set_int32(char *key, int32_t value)
{
	/*make sure client connection is open*/
	client_connection();
	/*check if a key has been created*/
	/*create key */
	BuxtonKey _key = buxton_key_create(_group, strdup(key), _layer, INT32);
	/*Return value and status*/
	struct vstatus ret;
	ret.type = INT32;
	ret.i32val = value;
	save_errno();
	/*call buxton_set_value for type INT32*/
	if (buxton_set_value(client, _key, &value, bs_cb, &ret, true)){
		printf("Set int32_t call failed.\n");
		return;
	}
	if (!ret.status){
		errno = EACCES;
	} else {
		errno = saved_errno;
	}
	buxton_key_free(_key);
}
コード例 #14
0
ファイル: helloget.c プロジェクト: sviswana/buxton-temp
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;
}
コード例 #15
0
ファイル: hellonotify.c プロジェクト: AlexeyPerevalov/buxton
int main(void)
{
	BuxtonClient client;
	BuxtonKey key;
	bool status = true;
	struct pollfd pfd[1];
	int r;
	int fd;
	int repoll_count = 10;

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

	key = buxton_key_create("hello", "test", NULL, INT32);
	if (!key) {
		return -1;
	}

	if (buxton_register_notification(client, key, notify_cb, &status, false)) {
		printf("set call failed to run\n");
		return -1;
	}
repoll:
	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;
	} else if (r == 0) {
		if (repoll_count-- > 0) {
			goto out;
		}
		goto repoll;
	}

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

	if (!status) {
		printf("Failed to register for notification\n");
		return -1;
	}

	goto repoll;

out:
	if (buxton_unregister_notification(client, key, NULL, NULL, true)) {
		printf("Unregistration of notification failed\n");
		return -1;
	}

	buxton_key_free(key);
	buxton_close(client);

	return 0;
}
コード例 #16
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
/*create a client side group TODO: create BuxtonGroup type*/
BuxtonKey buxton_group_create(char *name, char *layer)
{
	client_connection();
	BuxtonKey ret = buxton_key_create(name, NULL, layer, STRING);
	return ret;
}
コード例 #17
0
ファイル: lbuxton-simp1.c プロジェクト: sviswana/buxton-temp
/*buxton_key_free insert char key name and type*/
void buxtond_key_free(char * key_name, BuxtonDataType type)
{
	BuxtonKey k = buxton_key_create(_group, strdup(key_name), _layer, type);
	buxton_key_free(k);
}