Last active
September 21, 2015 19:08
-
-
Save gabrielschulhof/1f2ee0f8d264c71bcd1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <glib.h> | |
#include <ocstack.h> | |
#include <signal.h> | |
static GMainLoop *loop; | |
static guint timeout_id; | |
static void deleteContextNoop( void *context ) {} | |
static void cleanupAndExit( int whatSignal ) { | |
int result; | |
g_message( "Cleaning up and exiting" ); | |
g_source_remove( timeout_id ); | |
result = OCStop(); | |
g_message( "OCStop: %d", result ); | |
g_main_loop_quit( loop ); | |
} | |
static gboolean run_OCProcess( void *nothingHere ) { | |
int result = OCProcess(); | |
if ( result != OC_STACK_OK ) { | |
g_warning( "OCProcess: %d, exiting\n", result ); | |
cleanupAndExit( 0 ); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
static void dumpResponse( const char *prefix, OCClientResponse *response ) { | |
char *new_prefix; | |
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 ); | |
new_prefix = g_strdup_printf( "%s: ->devAddr", prefix ); | |
g_free( new_prefix ); | |
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 ); | |
} | |
} | |
static OCStackApplicationResult discoverCallback( void *nothingHere, OCDoHandle handle, OCClientResponse *response ) { | |
dumpResponse( "discovery", response ); | |
return OC_STACK_KEEP_TRANSACTION; | |
} | |
int main( int argc, char **argv ) { | |
OCStackResult result; | |
OCDoHandle handle; | |
OCCallbackData discoverData = { NULL, discoverCallback, deleteContextNoop }; | |
loop = g_main_loop_new( NULL, false ); | |
timeout_id = g_timeout_add( 1000, run_OCProcess, NULL ); | |
signal( SIGINT, cleanupAndExit ); | |
result = OCInit( NULL, 0, OC_CLIENT ); | |
g_message( "OCInit: %d", result ); | |
result = OCDoResource( | |
&handle, | |
OC_REST_DISCOVER, | |
OC_RSRVD_WELL_KNOWN_URI, | |
NULL, | |
NULL, | |
CT_DEFAULT, | |
OC_HIGH_QOS, | |
&discoverData, | |
NULL, | |
0 ); | |
g_message( "OCDoResource(discovery): %d", result ); | |
g_main_loop_run( loop ); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <glib.h> | |
#include <ocstack.h> | |
#include <signal.h> | |
static GMainLoop *loop; | |
static guint timeout_id; | |
static char *sampleUri = "/a/iotivity-node-presence-sample"; | |
static void cleanupAndExit( int whatSignal ) { | |
int result; | |
g_message( "Cleaning up and exiting" ); | |
g_source_remove( timeout_id ); | |
result = OCStopPresence(); | |
g_message( "OCStopPresence: %d", result ); | |
result = OCStop(); | |
g_message( "OCStop: %d", result ); | |
g_main_loop_quit( loop ); | |
} | |
static gboolean run_OCProcess( void *nothingHere ) { | |
int result = OCProcess(); | |
if ( result != OC_STACK_OK ) { | |
g_warning( "OCProcess: %d, exiting\n", result ); | |
cleanupAndExit( 0 ); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
static OCEntityHandlerResult entityHandler( OCEntityHandlerFlag flag, OCEntityHandlerRequest *request, void *nothingHere ) { | |
g_message( "entity handler: entering and returning OC_EH_OK" ); | |
return OC_EH_OK; | |
} | |
int main( int argc, char **argv ) { | |
OCStackResult result; | |
OCResourceHandle handle; | |
loop = g_main_loop_new( NULL, false ); | |
timeout_id = g_timeout_add( 1000, run_OCProcess, NULL ); | |
signal( SIGINT, cleanupAndExit ); | |
result = OCInit( NULL, 0, OC_SERVER ); | |
g_message( "OCInit: %d", result ); | |
result = OCCreateResource( | |
&handle, | |
"core.fan", | |
OC_RSRVD_INTERFACE_DEFAULT, | |
sampleUri, | |
entityHandler, | |
NULL, | |
OC_DISCOVERABLE ); | |
g_message( "OCCreateResource: %d", result ); | |
result = OCStartPresence( 0 ); | |
g_message( "OCStartPresence: %d", result ); | |
g_main_loop_run( loop ); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Script started on Mon 21 Sep 2015 10:00:30 PM EEST | |
[22:00][nix@boundary][/home/nix/iot/iotivity]/$ git show | |
commit 7033427e9b2787649d5b3a7769a32520e19b47d2 | |
Merge: fab8874 1d238e0 | |
Author: Joseph Morrow <[email protected]> | |
Date: Sun Sep 20 15:06:56 2015 -0700 | |
Merge branch 'plugin-interface' into master | |
Change-Id: Idb58ff366694797d8bc433e974faf2c6124091aa | |
Signed-off-by: Joseph Morrow <[email protected]> | |
[22:00][nix@boundary][/home/nix/iot/iotivity]/$ ( git clean -x -d -f -f && git clone https://github.com/01org/tinycbor.git extlibs/tin ycbor/tinycbor && git clone https://github.com/jbeder/yaml-cpp.git extlibs/yaml/yaml && JAVA_HOME=/ scons VERBOSE=true -j9 liboctbstack samples && ( cd resource/csdk/doc; doxygen; ) ; ) > /dev/null 2>&1 | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ cp ../client.c ../server.c . | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 -I$(pwd)/resource/c_common -I$(pwd)/resource/csdk/stack/include -L$(pw d)/out/linux/x86/release/ -Wl,-rpath $(pwd)/out/linux/x86/release -loctbstack `pkg-config --cflags --libs glib-2.0` client.c -o client | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 -I$(pwd)/resource/c_common -I$(pwd)/resource/csdk/stack/include -L$(pw d)/out/linux/x86/release/ -Wl,-rpath $(pwd)/out/linux/x86/release -loctbstack `pkg-config --cflags --libs glib-2.0` server.c -o server | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ ./server & | |
[1] 22849 | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ ** Message: OCInit: 0 | |
** Message: OCCreateResource: 0 | |
** Message: OCStartPresence: 0 | |
./client | |
** Message: OCInit: 0 | |
** Message: OCDoResource(discovery): 0 | |
discovery: response: | |
discovery: ->devAddr: | |
discovery: ->devAddr.adapter: 1 | |
discovery: ->devAddr.flags: 32 | |
discovery: ->devAddr.interface: 3 | |
discovery: ->devAddr.port: 37946 | |
discovery: ->devAddr.addr: fe80::a288:b4ff:fe17:d0c8 | |
discovery: response->payload: absent | |
discovery: response: | |
discovery: ->devAddr: | |
discovery: ->devAddr.adapter: 1 | |
discovery: ->devAddr.flags: 32 | |
discovery: ->devAddr.interface: 3 | |
discovery: ->devAddr.port: 51558 | |
discovery: ->devAddr.addr: fe80::a288:b4ff:fe17:d0c8 | |
discovery: response->payload: absent | |
^C** Message: Cleaning up and exiting | |
** Message: OCStop: 0 | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ fg | |
./server | |
^C** Message: Cleaning up and exiting | |
** Message: OCStopPresence: 0 | |
** Message: OCStop: 0 | |
[22:01][nix@boundary][/home/nix/iot/iotivity]/$ exit | |
Script done on Mon 21 Sep 2015 10:01:52 PM EEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment