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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34 #include "oic_string.h"
36 #define TAG ("occlient")
40 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
41 void handleSigInt(int signum) {
42 if (signum == SIGINT) {
47 // This is a function called back when a device is discovered
48 OCStackApplicationResult applicationDiscoverCB(
49 OCClientResponse * clientResponse) {
51 OIC_LOG(INFO, TAG, "Entering applicationDiscoverCB (Application Layer CB)");
52 OIC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %s:%d",
53 clientResponse->resourceUri,
54 clientResponse->devAddr.addr,
55 clientResponse->devAddr.port);
56 //return OC_STACK_DELETE_TRANSACTION;
57 return OC_STACK_KEEP_TRANSACTION;
61 OIC_LOG_V(INFO, TAG, "Starting occlient");
63 /* Initialize OCStack*/
64 if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
65 OIC_LOG(ERROR, TAG, "OCStack init error");
69 /* Start a discovery query*/
70 char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
71 OICStrcpy(szQueryUri, MAX_QUERY_LENGTH, OC_MULTICAST_DISCOVERY_URI);
72 if (OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0,
73 CT_DEFAULT, OC_LOW_QOS, 0, 0, 0) != OC_STACK_OK) {
74 OIC_LOG(ERROR, TAG, "OCStack resource error");
78 // Break from loop with Ctrl+C
79 OIC_LOG(INFO, TAG, "Entering occlient main loop...");
80 signal(SIGINT, handleSigInt);
83 if (OCProcess() != OC_STACK_OK) {
84 OIC_LOG(ERROR, TAG, "OCStack process error");
91 OIC_LOG(INFO, TAG, "Exiting occlient main loop...");
93 if (OCStop() != OC_STACK_OK) {
94 OIC_LOG(ERROR, TAG, "OCStack stop error");