Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Last active September 23, 2015 06:10
Show Gist options
  • Save gabrielschulhof/1ee202e991fd29da7e98 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/1ee202e991fd29da7e98 to your computer and use it in GitHub Desktop.
CAProcessSendData (data=0x8054700) at resource/csdk/connectivity/src/camessagehandler.c:541
541 if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
Missing separate debuginfos, use: debuginfo-install glib2-2.42.2-1.fc21.i686 libffi-3.1-7.fc21.i686 libselinux-2.3-10.fc21.i686 libuuid-2.25.2-3.fc21.i686 pcre-8.35-12.fc21.i686 zlib-1.2.8-7.fc21.i686
(gdb) bt
#0 0xffffffff in CASendThreadProcess (data=0x8054700) at resource/csdk/connectivity/src/camessagehandler.c:541
#1 0xffffffff in CASendThreadProcess (threadData=0x8054700) at resource/csdk/connectivity/src/camessagehandler.c:636
#2 0xffffffff in CAQueueingThreadBaseRoutine (threadValue=0xb7fd6700 <g_sendThread>)
at resource/csdk/connectivity/src/caqueueingthread.c:82
#3 0xffffffff in ca_thread_pool_pthreads_delegate (data=0x8053068)
at resource/csdk/connectivity/common/src/cathreadpool_pthreads.c:62
#4 0xffffffff in start_thread () at /lib/libpthread.so.0
#5 0xffffffff in clone () at /lib/libc.so.6
0xb7cb464a in free () from /lib/libc.so.6
Missing separate debuginfos, use: debuginfo-install glib2-2.42.2-1.fc21.i686 libffi-3.1-7.fc21.i686 libselinux-2.3-10.fc21.i686 libuuid-2.25.2-3.fc21.i686 pcre-8.35-12.fc21.i686 zlib-1.2.8-7.fc21.i686
(gdb) bt
#0 0xffffffff in free () at /lib/libc.so.6
#1 0xffffffff in OICFree (ptr=0x4fff4) at resource/c_common/oic_malloc/src/oic_malloc.c:135
#2 0xffffffff in CAFreeEndpoint (rep=0x4fff4) at resource/csdk/connectivity/common/src/caremotehandler.c:162
#3 0xffffffff in CADestroyData (data=0x80546e8, size=24) at resource/csdk/connectivity/src/camessagehandler.c:333
#4 0xffffffff in CAQueueingThreadBaseRoutine (threadValue=0xb7fd6700 <g_sendThread>)
at resource/csdk/connectivity/src/caqueueingthread.c:87
#5 0xffffffff in ca_thread_pool_pthreads_delegate (data=0x8053068)
at resource/csdk/connectivity/common/src/cathreadpool_pthreads.c:62
#6 0xffffffff in start_thread () at /lib/libpthread.so.0
#7 0xffffffff in clone () at /lib/libc.so.6
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <glib.h>
#include <ocstack.h>
#include <ocpayload.h>
static int observationCount = 0;
static GMainLoop *loop = NULL;
static guint timeout_id = 0;
static char *sampleUri = "/a/light";
static void deleteContextNoop( void *context ) {}
static void cleanupAndExit( int whatSignal ) {
g_message( "Cleaning up and exiting" );
g_source_remove( timeout_id );
g_message( "OCStop: %d", OCStop() );
g_main_loop_quit( loop );
}
static gboolean run_OCProcess( void *nothingHere ) {
g_message( "OCProcess: %d", OCProcess() );
return TRUE;
}
static void dumpResponse( const char *prefix, OCClientResponse *response ) {
_Bool state;
int64_t power;
printf( "%s: response:\n", prefix );
printf( "%s: ->devAddr:\n", prefix );
printf( "%s: ->devAddr.adapter: %d\n", prefix, response->devAddr.adapter );
printf( "%s: ->devAddr.flags: %d\n", prefix, response->devAddr.flags );
printf( "%s: ->devAddr.interface: %d\n", prefix, response->devAddr.interface );
printf( "%s: ->devAddr.port: %d\n", prefix, response->devAddr.port );
printf( "%s: ->devAddr.addr: %s\n", prefix, response->devAddr.addr );
printf( "%s: response->payload: %s\n", prefix, response->payload ? "present": "absent" );
if ( response->payload ) {
printf( "%s: response->payload->type: %d\n", prefix, response->payload->type );
if ( response->payload->type == PAYLOAD_TYPE_DISCOVERY ) {
OCDiscoveryPayload *discoveryPayload = ( OCDiscoveryPayload * )( response->payload );
if ( discoveryPayload->resources ) {
printf( "%s: response->payload->resources->uri: %s\n", prefix, discoveryPayload->resources->uri );
}
} else if ( response->payload->type == PAYLOAD_TYPE_REPRESENTATION ) {
if ( OCRepPayloadGetPropBool( ( OCRepPayload * )( response->payload ), "state", &state ) &&
OCRepPayloadGetPropInt( ( OCRepPayload * )( response->payload ), "power", &power ) ) {
printf( "%s: payload values: { state: %s, power: %d }\n", prefix, state ? "true" : "false", (int)power );
} else {
printf( "%s: Failed to retrieve payload values\n", prefix );
}
}
}
}
static OCStackApplicationResult observeCallback( void *nothingHere, OCDoHandle handle, OCClientResponse *response ) {
dumpResponse( "observe", response );
if ( observationCount++ >= 10 ) {
g_message( "OCCancel: %d", OCCancel( handle, OC_HIGH_QOS, NULL, 0 ) );
}
return OC_STACK_KEEP_TRANSACTION;
}
static OCStackApplicationResult discoverCallback( void *nothingHere, OCDoHandle handle, OCClientResponse *response ) {
OCResourcePayload *iter = 0;
OCCallbackData observeData = { NULL, observeCallback, deleteContextNoop };
OCDoHandle observeHandle = NULL;
dumpResponse( "discovery", response );
if ( response->payload->type == PAYLOAD_TYPE_DISCOVERY ) {
for ( iter = ( ( OCDiscoveryPayload * )response->payload )->resources ; iter; iter = iter->next ) {
if ( iter->uri && !strcmp( iter->uri, sampleUri ) ) {
g_message( "OCDoResource(observation): %d", OCDoResource(
&observeHandle,
OC_REST_OBSERVE,
sampleUri,
response->addr,
NULL,
CT_DEFAULT,
OC_HIGH_QOS,
&observeData,
NULL,
0 ) );
return OC_STACK_DELETE_TRANSACTION;
}
}
}
return OC_STACK_KEEP_TRANSACTION;
}
int main( int argc, char **argv ) {
OCDoHandle discoverHandle;
OCCallbackData discoverData = { NULL, discoverCallback, deleteContextNoop };
loop = g_main_loop_new( NULL, false );
timeout_id = g_timeout_add( 1000, run_OCProcess, NULL );
signal( SIGINT, cleanupAndExit );
g_message( "OCInit: %d", OCInit( NULL, 0, OC_CLIENT ) );
g_message( "OCDoResource(discovery): %d", OCDoResource(
&discoverHandle,
OC_REST_DISCOVER,
OC_MULTICAST_DISCOVERY_URI,
NULL,
NULL,
CT_DEFAULT,
OC_HIGH_QOS,
&discoverData,
NULL,
0 ) );
g_main_loop_run( loop );
return 0;
}
cc -g -Wall -O0 \
-DROUTING_EP -DTCP_ADAPTER \
-I$(pwd)/resource/c_common \
-I$(pwd)/resource/csdk/stack/include \
-L$(pwd)/out/linux/x86/release/ \
-Wl,-rpath $(pwd)/out/linux/x86/release \
-loctbstack \
`pkg-config --cflags --libs glib-2.0` \
client.c -o client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment