1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
30 #define TAG ("occlient")
34 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
35 void handleSigInt(int signum) {
36 if (signum == SIGINT) {
41 // This is a function called back when a device is discovered
42 OCStackApplicationResult applicationDiscoverCB(
43 OCClientResponse * clientResponse) {
44 OC_LOG(INFO, TAG, "Entering applicationDiscoverCB (Application Layer CB)");
45 OC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %s:%d",
46 clientResponse->resJSONPayload,
47 clientResponse->devAddr.addr,
48 clientResponse->devAddr.port);
49 //return OC_STACK_DELETE_TRANSACTION;
50 return OC_STACK_KEEP_TRANSACTION;
54 OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
56 /* Initialize OCStack*/
57 if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
58 OC_LOG(ERROR, TAG, "OCStack init error");
62 /* Start a discovery query*/
63 char szQueryUri[64] = { 0 };
64 strcpy(szQueryUri, OC_EXPLICIT_DEVICE_DISCOVERY_URI);
65 if (OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS,
66 0, 0, 0) != OC_STACK_OK) {
67 OC_LOG(ERROR, TAG, "OCStack resource error");
71 // Break from loop with Ctrl+C
72 OC_LOG(INFO, TAG, "Entering occlient main loop...");
73 signal(SIGINT, handleSigInt);
76 if (OCProcess() != OC_STACK_OK) {
77 OC_LOG(ERROR, TAG, "OCStack process error");
82 }OC_LOG(INFO, TAG, "Exiting occlient main loop...");
84 if (OCStop() != OC_STACK_OK) {
85 OC_LOG(ERROR, TAG, "OCStack stop error");