/* 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(); }
/*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); }
/*buxton_set_value callback and function for boolean*/ void bsb_cb(BuxtonResponse response, void *data) { bool *ret = (bool*)data; if(buxton_response_status(response)){ printf("Failed to set boolean.\n"); return; } printf("Value has been set: %i(bool)\n", *ret); 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_set_value callback and function for double*/ void bsd_cb(BuxtonResponse response, void *data) { double *ret = (double*)data; if (buxton_response_status(response)){ printf("Failed to set double.\n"); return; } printf("Value has been set: %e(double)\n", *ret); 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_set_value callback and function for uint64_t*/ void bsui64_cb(BuxtonResponse response, void *data) { uint64_t *ret = (uint64_t*)data; if (buxton_response_status(response)){ printf("Failed to set uint64_t.\n"); return; } printf("Value has been set: ""%"PRIu64"(uint64_t)\n", *ret); 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_set_value callback and function for string*/ void bss_cb(BuxtonResponse response, void *data) { char **ret=(char**)data; if (buxton_response_status(response)){ printf("Failed to set string.\n"); return; } printf("Value has been set: %s(string)\n", *ret); 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)); }
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); }
/*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); }