1 //******************************************************************
3 // Copyright 2015 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "IotivityandZigbeeServer.h"
26 #define TAG "IoTivityZigbeeServer"
28 int main(int argc, char* argv[])
31 OC_LOG(INFO, TAG, "Initializing IoTivity...");
34 result = OCInit(NULL, 0, OC_SERVER);
35 if (result != OC_STACK_OK)
37 OC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
42 result = SetPlatformInfo();
43 if (result != OC_STACK_OK)
45 OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
50 result = SetDeviceInfo();
51 if (result != OC_STACK_OK)
53 OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
57 result = OCStartPresence(0);
58 if (result != OC_STACK_OK)
60 OC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
65 PIPluginBase* plugin = NULL;
66 OC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
67 result = PIStartPlugin(PLUGIN_ZIGBEE, &plugin);
68 if (result != OC_STACK_OK)
70 OC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
74 if (signal(SIGINT, processCancel) == SIG_ERR)
76 OC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
80 OC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
82 while (processSignal(false) && result == OC_STACK_OK)
85 if (result != OC_STACK_OK)
87 OC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
91 result = PIProcess(plugin);
92 if (result != OC_STACK_OK)
94 OC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
99 OC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
101 OC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
102 result = PIStopPlugin(plugin);
103 if (result != OC_STACK_OK)
105 OC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
110 OC_LOG(INFO, TAG, "Stopping IoTivity...");
112 if (result != OC_STACK_OK)
114 OC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
118 OC_LOG(INFO, TAG, "Application Completed Successfully");
121 OCStackResult SetPlatformInfo()
123 static const OCPlatformInfo platformInfo =
125 .platformID = "IoTivityZigbeeID",
126 .manufacturerName = "IoTivity",
127 .manufacturerUrl = "http://iotivity.org",
128 .modelNumber = "T1000",
129 .dateOfManufacture = "January 14th, 2015",
130 .platformVersion = "0.9.2",
131 .operatingSystemVersion = "7",
132 .hardwareVersion = "0.5",
133 .firmwareVersion = "0",
134 .supportUrl = "http://iotivity.org",
138 return OCSetPlatformInfo(platformInfo);
141 OCStackResult SetDeviceInfo()
143 static const OCDeviceInfo deviceInfo =
145 .deviceName = "IoTivity/Zigbee Server Sample"
148 return OCSetDeviceInfo(deviceInfo);
151 bool processSignal(bool set)
153 static bool signal = false;
156 // boolean assignments are atomic, and since we
157 // only have a single modifier, and only in one direction,
158 // this does not require locking.
165 void processCancel(int signal)