Created
September 21, 2015 19:33
-
-
Save gabrielschulhof/dcb4597683da1f000fc4 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 ); | |
| 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 ); | |
| } | |
| } | |
| } | |
| } | |
| 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:27:29 PM EEST | |
| [22:27][nix@boundary][/home/nix/iot/iotivity]/$ git show --oneline | |
| ad8521c [Resource Encapsulation] Fixed Sample APP issue | |
| diff --git a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp | |
| index 1e9ecf9..f7c946c 100755 | |
| --- a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp | |
| +++ b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp | |
| @@ -105,8 +105,8 @@ RCSSetResponse requestHandlerForSet(const RCSRequest& request, | |
| std::cout << "Recieved a Set request from Client" << std::endl; | |
| std::cout << "\n\nSending response to Client : " << std::endl; | |
| - printAttribute(server->getAttributes()); | |
| - | |
| + RCSResourceObject::LockGuard lock(*server); | |
| + printAttribute(attrs); | |
| return RCSSetResponse::defaultAction(); | |
| } | |
| @@ -226,7 +226,7 @@ void process() | |
| { | |
| displayControlTemperatureMenu(); | |
| - if(selectControlTemperatureMenu() == QUIT) break; | |
| + if (selectControlTemperatureMenu() == QUIT) return; | |
| } | |
| } | |
| @@ -237,6 +237,7 @@ int main(void) | |
| try | |
| { | |
| process(); | |
| + server = NULL; | |
| } | |
| catch (const std::exception& e) | |
| { | |
| [22:27][nix@boundary][/home/nix/iot/iotivity]/$ ( git clean -x -d -f -f && \ | |
| > git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor && \ | |
| > scons VERBOSE=true -j9 liboctbstack samples && \ | |
| > ( cd resource/csdk/doc; doxygen; ) ; ) > /dev/null 2>&1 | |
| [22:28][nix@boundary][/home/nix/iot/iotivity]/$ cp ../client.c ../server.c . | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 \ | |
| > -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 | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 \ | |
| > -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` \ | |
| > server.c -o server | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ ./server & | |
| [1] 4632 | |
| ** Message: OCInit: 0 | |
| ** Message: OCCreateResource: 0 | |
| ** Message: OCStartPresence: 0 | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ ./client | |
| ** Message: OCInit: 0 | |
| ** Message: OCDoResource(discovery): 0 | |
| discovery: response: | |
| discovery: ->devAddr: | |
| discovery: ->devAddr.adapter: 1 | |
| discovery: ->devAddr.flags: 64 | |
| discovery: ->devAddr.interface: 0 | |
| discovery: ->devAddr.port: 44874 | |
| discovery: ->devAddr.addr: 192.168.1.45 | |
| discovery: response->payload: present | |
| discovery: response->payload->type: 1 | |
| discovery: response->payload->resources->uri: /a/iotivity-node-presence-sample | |
| ^C** Message: Cleaning up and exiting | |
| ** Message: OCStop: 0 | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ fg | |
| ./server | |
| ^C** Message: Cleaning up and exiting | |
| ** Message: OCStopPresence: 0 | |
| ** Message: OCStop: 0 | |
| [22:29][nix@boundary][/home/nix/iot/iotivity]/$ git checkout 1.0.0-RC1 | |
| Previous HEAD position was ad8521c... [Resource Encapsulation] Fixed Sample APP issue | |
| HEAD is now at 7033427... Merge branch 'plugin-interface' into master | |
| [22:30][nix@boundary][/home/nix/iot/iotivity]/$ git show --oneline | |
| 7033427 Merge branch 'plugin-interface' into master | |
| [22:30][nix@boundary][/home/nix/iot/iotivity]/$ ( git clean -x -d -f -f && \ | |
| > git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/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:31][nix@boundary][/home/nix/iot/iotivity]/$ cp ../client.c ../server.c . | |
| [22:31][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 \ | |
| > -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 | |
| [22:31][nix@boundary][/home/nix/iot/iotivity]/$ cc -g -Wall -O0 \ | |
| > -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` \ | |
| > server.c -o server | |
| [22:32][nix@boundary][/home/nix/iot/iotivity]/$ ./server & | |
| [1] 8131 | |
| [22:32][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: 40732 | |
| discovery: ->devAddr.addr: fe80::a288:b4ff:fe17:d0c8 | |
| discovery: response->payload: absent | |
| ^C** Message: Cleaning up and exiting | |
| ** Message: OCStop: 0 | |
| [22:32][nix@boundary][/home/nix/iot/iotivity]/$ fg | |
| ./server | |
| ^C** Message: Cleaning up and exiting | |
| ** Message: OCStopPresence: 0 | |
| ** Message: OCStop: 0 | |
| [22:32][nix@boundary][/home/nix/iot/iotivity]/$ exit | |
| Script done on Mon 21 Sep 2015 10:32:24 PM EEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment