示例#1
0
/* 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();
}
示例#2
0
/* 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();
}
void my_set_key(BuxtonClient client, BuxtonKey key)
{
	uint32_t rand_key_value;
	/*random integer value for the key*/
	srand(time(NULL));
	rand_key_value=rand()%100+1;
	printf("random value=%i\n", rand_key_value);
	if(buxton_set_value(client, key, &rand_key_value,sv_cb,&rand_key_value,true)){
		printf("set value call failed.\n");
	}
			
}
示例#4
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;
}
示例#5
0
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);
}
示例#6
0
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);
}