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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
35 #define TAG ("occlient")
39 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
40 void handleSigInt(int signum) {
41 if (signum == SIGINT) {
46 // This is a function called back when a device is discovered
47 OCStackApplicationResult applicationDiscoverCB(
48 OCClientResponse * clientResponse) {
49 OIC_LOG(INFO, TAG, "Entering applicationDiscoverCB (Application Layer CB)");
50 OIC_LOG_V(INFO, TAG, "Device =============> Discovered %s @ %s:%d",
51 clientResponse->resourceUri,
52 clientResponse->devAddr.addr,
53 clientResponse->devAddr.port);
54 //return OC_STACK_DELETE_TRANSACTION;
55 return OC_STACK_KEEP_TRANSACTION;
59 OIC_LOG_V(INFO, TAG, "Starting occlient");
61 /* Initialize OCStack*/
62 if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
63 OIC_LOG(ERROR, TAG, "OCStack init error");
67 /* Start a discovery query*/
68 char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
69 strcpy(szQueryUri, OC_MULTICAST_DISCOVERY_URI);
70 if (OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0,
71 CT_DEFAULT, OC_LOW_QOS, 0, 0, 0) != OC_STACK_OK) {
72 OIC_LOG(ERROR, TAG, "OCStack resource error");
76 // Break from loop with Ctrl+C
77 OIC_LOG(INFO, TAG, "Entering occlient main loop...");
78 signal(SIGINT, handleSigInt);
81 if (OCProcess() != OC_STACK_OK) {
82 OIC_LOG(ERROR, TAG, "OCStack process error");
89 OIC_LOG(INFO, TAG, "Exiting occlient main loop...");
91 if (OCStop() != OC_STACK_OK) {
92 OIC_LOG(ERROR, TAG, "OCStack stop error");