Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dist_man_MANS = \
docs/buxton_client_handle_response.3 \
docs/buxton_close.3 \
docs/buxton_create_group.3 \
docs/buxton_get_key_type.3 \
docs/buxton_get_value.3 \
docs/buxton_key_create.3 \
docs/buxton_key_free.3 \
Expand All @@ -103,8 +104,10 @@ dist_man_MANS = \
docs/sbuxton_get_string.3 \
docs/sbuxton_get_int64.3 \
docs/sbuxton_get_uint64.3 \
docs/sbuxton_get_fd.3 \
docs/sbuxton_get_float.3 \
docs/sbuxton_get_double.3 \
docs/sbuxton_handle_response.3 \
docs/sbuxton_get_bool.3 \
docs/sbuxton_set_int32.3 \
docs/sbuxton_set_uint32.3 \
Expand All @@ -115,7 +118,9 @@ dist_man_MANS = \
docs/sbuxton_set_double.3 \
docs/sbuxton_set_bool.3 \
docs/sbuxton_set_group.3 \
docs/sbuxton_remove_group.3
docs/sbuxton_register_notify.3 \
docs/sbuxton_remove_group.3 \
docs/sbuxton_unregister_notify.3
endif

TESTS = \
Expand Down Expand Up @@ -448,6 +453,7 @@ check_DATA = \
if BUILD_DEMOS
bin_PROGRAMS += \
bxt_timing \
bxt_hello_get_key_type \
bxt_hello_get \
bxt_hello_set \
bxt_hello_set_label \
Expand All @@ -456,7 +462,8 @@ bin_PROGRAMS += \
bxt_hello_unset \
bxt_hello_notify \
bxt_hello_notify_multi \
bxt_hello_simple
bxt_hello_simple \
bxt_hello_notify_simple

# Timing test
bxt_timing_SOURCES = \
Expand All @@ -466,6 +473,13 @@ bxt_timing_LDADD = \
libbuxton-shared.la \
-lrt -lm

bxt_hello_get_key_type_SOURCES = \
demo/hellogetkeytype.c
bxt_hello_get_key_type_CFLAGS = \
$(AM_CFLAGS)
bxt_hello_get_key_type_LDADD =\
libbuxton.la

bxt_hello_get_SOURCES = \
demo/helloget.c
bxt_hello_get_CFLAGS = \
Expand Down Expand Up @@ -529,6 +543,13 @@ bxt_hello_simple_CFLAGS = \
bxt_hello_simple_LDADD = \
libbuxtonsimple.la

bxt_hello_notify_simple_SOURCES = \
demo/hellonotifysimple.c
bxt_hello_notify_simple_CFLAGS = \
$(AM_CFLAGS)
bxt_hello_notify_simple_LDADD = \
libbuxtonsimple.la

if BUILD_GTK_DEMO
bin_PROGRAMS += \
bxt_gtk_client
Expand Down
171 changes: 171 additions & 0 deletions demo/hellogetkeytype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* This file is part of buxton.
*
* Copyright (C) 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

/*
* Run this demo after creating the group with bxt_hello_create_group
* and after setting the key with bxt_hello_set
*/

#define _GNU_SOURCE
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "buxton.h"

void get_cb(BuxtonResponse response, void *data)
{
BuxtonDataType *ret = (BuxtonDataType*) data;

if (buxton_response_status(response) != 0) {

printf("Failed to get value\n");
return;
} else {
printf("Get successful, got type\n");
void *p = buxton_response_value(response);
*ret = *(BuxtonDataType*)p;
return;
}
}

int main(void)
{
BuxtonClient client;
BuxtonKey key;
struct pollfd pfd[1];
int r;
BuxtonDataType d_type = BUXTON_TYPE_MIN;
int fd;
char *type;

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: UNKNOWN
*/
key = buxton_key_create("hello", "test", "user", UNKNOWN);
if (!key) {
return -1;
}

if (buxton_get_key_type(client, key, get_cb,
&d_type, 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;
}

switch (d_type) {
case BUXTON_TYPE_MIN:
{
type = "invalid- still min";
}
case STRING:
{
type = "string";
break;
}
case INT32:
{
type = "int32_t";
break;
}
case UINT32:
{
type = "uint32_t";
break;
}
case INT64:
{
type = "int64_t";
break;
}
case UINT64:
{
type = "uint64_t";
break;
}
case FLOAT:
{
type = "float";
break;
}
case DOUBLE:
{
type = "double";
break;
}
case BOOLEAN:
{
type = "bool";
break;
}
default:
{
type = "unknown";
break;
}
}

printf("type of key is: %d = %s\n", d_type, type);

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

/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/
111 changes: 111 additions & 0 deletions demo/hellonotifysimple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* This file is part of buxton.
*
* Copyright (C) 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

#include <errno.h>
#include <inttypes.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "buxtonsimple.h"

/*
* This demo creates a key "tk_i32" on group "tg_s5" and layer "user".
* It then registers for notification on that key in buxton, and registers
* for notifications on this instance of buxtonsimple in pollfd. Users can then
* changed the value of tk_i32 with the commandline interface (buxtonctl), which
* will trigger this callback, which prints the name of the key, and its new value.
*/

/* Callback function for notifications */
void tk_i32_notify_cb(void *key_data, char *key_name)
{
int32_t *data = (int32_t *)key_data;
if (!data) {
printf("key %s was removed\n", key_name);
} else {
printf("key %s was changed to value %d\n", key_name, *data);
}
}

int main(void)
{
struct pollfd pfd[1];
int r;
int fd;
int repoll_count = 10;

/* Create group */
errno = 0;
sbuxton_set_group("tg_s5", "user");
printf("set_group: 'tg_s5', 'user', Error number: %s.\n", strerror(errno));

/* Test Int setting */
int32_t i32 = (int32_t) rand() % 50 + 1;
printf("value should be set to %d.\n", i32);
errno = 0;
sbuxton_set_int32("tk_i32", i32);
printf("set_int32: 'tg_s5', 'tk_i32', Error number: %s.\n", strerror(errno));

/* Register for notifications in buxton */
printf("Register for int32_t tk_i32\n");
sbuxton_register_notify("tk_i32", &tk_i32_notify_cb);

/* get fd */
fd = sbuxton_get_fd();


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 (!sbuxton_handle_response()) {
printf("bad response from daemon\n");
return -1;
}

goto repoll;

out:
/* unregister notifications */
sbuxton_unregister_notify("tk_i32");

return 0;
}
3 changes: 3 additions & 0 deletions docs/buxton-api.7
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ use these API functions\&.
\fBbuxton_get_value\fR(3)
\(em Get the value of a key
.br
\fBbuxton_get_key_type\fR(3)
\(em Get the type of a key
.br
\fBbuxton_unset_value\fR(3)
\(em Unset the value for a key
.br
Expand Down
2 changes: 1 addition & 1 deletion docs/buxton_client_handle_response.3
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buxton_client_handle_response \- Notification response helper
.SH "SYNOPSIS"
.nf
\fB
#include <buxton.h>
#include <buxtonsimple.h>
\fR
.sp
\fB
Expand Down
Loading