Exemplo n.º 1
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);
}
Exemplo n.º 2
0
/*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);
}
Exemplo n.º 3
0
void notify_cb(BuxtonResponse response, void *data)
{
	bool *status = (bool *)data;
	BuxtonKey key;
	int32_t *value;
	char *name;

	if (buxton_response_status(response) != 0) {
		*status = false;
		return;
	}

	key = buxton_response_key(response);
	name = buxton_key_get_name(key);

	value = (int32_t*)buxton_response_value(response);
	if (value) {
		printf("key %s updated with new value %d\n", name, *value);
	} else {
		printf("key %s was removed\n", name);
	}

	buxton_key_free(key);
	free(value);
	free(name);
}
Exemplo n.º 4
0
void buxtond_remove_group2(char *group_name, char *layer)
{
	client_connection();
	BuxtonKey group = buxton_group_create(group_name, layer);
	if (buxton_remove_group(client, group, rg_cb, NULL, true)){
		printf("Remove group call failed.\n");
	}
	buxton_key_free(group);
}
Exemplo n.º 5
0
/*create a buxtond side group*/
void buxtond_create_group(BuxtonKey group)
{
	client_connection();
	if (buxton_create_group(client, group, NULL, NULL, true)){
		printf("Create group call failed.\n");
		buxton_key_free(group);
		return;
	}
	/*TODO*/
	//buxton_key_free(group);
}
Exemplo n.º 6
0
void buxton_close(BuxtonClient client)
{
	_BuxtonClient *c;
	BuxtonKey key = NULL;
	Iterator i;

	/* Free all remaining allocated keys */
	HASHMAP_FOREACH_KEY(key, key, key_hash, i) {
		hashmap_remove_value(key_hash, key, key);
		buxton_key_free(key);
	}
Exemplo n.º 7
0
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*/
}
Exemplo n.º 8
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.º 9
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.º 10
0
void set_cb(BuxtonResponse response, void *data)
{
	BuxtonKey key;
	char *name;

	if (buxton_response_status(response) != 0) {
		printf("Failed to set value\n");
		return;
	}

	key = buxton_response_key(response);
	name = buxton_key_get_name(key);
	printf("Set value for key %s\n", name);
	buxton_key_free(key);
	free(name);
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
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);
}
Exemplo n.º 13
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.º 14
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;
}
Exemplo n.º 15
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);
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
/*buxton_set_value callback for all buxton data types*/
void bs_cb(BuxtonResponse response, void *data){
	struct vstatus *ret = (struct vstatus*)data;
	//struct vstatus set = *ret;
	char * type = "HOUSTON";
	ret->status = 0;
	/*check response before switch*/
	if (buxton_response_status(response)){
		printf("Failed to set value.\n");
		return;
	}
	ret->status =1;
	switch(ret->type){
		case STRING:
		{
			char * val = ret->sval;
			type = "string";
			break;
		}
		case INT32:
		{
			int32_t val = ret->i32val;
			type = "int32_t";
			/*GoToBuxtonResponseStatusCheck*/
			printf("Value to be set: %i(int32_t)\n", val);
			break;
		}
		case UINT32:
		{
			uint32_t val = ret->ui32val;
			type = "uint32_t";
			break;
		}
		case INT64:
		{
			int64_t val = ret->i64val;
			type = "int64_t";
			break;
		}
		case UINT64:
		{
			uint64_t val = ret->ui64val;
			type = "uint64_t";
			break;
		}
		case FLOAT:
		{
			float val = ret->fval;
			type = "float";
			break;
		}
		case DOUBLE:
		{
			double val = ret->dval;
			type = "double";
			break;
		}
		case BOOLEAN:
		{
			bool val = ret->bval;
			type = "bool";
			break;
		}
	}
	printf("Success: %s value has been set. ", type);
	BuxtonKey k = buxton_response_key(response);
	printf("Key: %s, Group: %s, Layer: %s.\n", buxton_key_get_name(k), buxton_key_get_group(k), buxton_key_get_layer(k));
	buxton_key_free(k);	

}
Exemplo n.º 18
0
/*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);
}