1 //******************************************************************
3 // Copyright 2015 Samsung Electronics 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "OCPlatform.h"
24 #include "oic_string.h"
26 #include "rd_client.h"
30 OCResourceHandle g_curResource_t = NULL;
31 OCResourceHandle g_curResource_l = NULL;
32 char rdAddress[MAX_ADDR_STR_SIZE];
35 void registerLocalResources()
37 std::string resourceURI_thermostat = "/a/thermostat";
38 std::string resourceTypeName_thermostat = "core.thermostat";
39 std::string resourceURI_light = "/a/light";
40 std::string resourceTypeName_light = "core.light";
41 std::string resourceInterface = DEFAULT_INTERFACE;
42 uint8_t resourceProperty = OC_DISCOVERABLE;
44 OCStackResult result = OCPlatform::registerResource(g_curResource_t,
45 resourceURI_thermostat,
46 resourceTypeName_thermostat,
51 if (OC_STACK_OK != result)
53 throw std::runtime_error(
54 std::string("Device Resource failed to start") + std::to_string(result));
57 result = OCPlatform::registerResource(g_curResource_l,
59 resourceTypeName_light,
64 if (OC_STACK_OK != result)
66 throw std::runtime_error(
67 std::string("Device Resource failed to start") + std::to_string(result));
73 std::cout << std::endl;
74 std::cout << "********************************************" << std::endl;
75 std::cout << "* method Type : 1 - Discover RD *" << std::endl;
76 std::cout << "* method Type : 2 - Publish *" << std::endl;
77 std::cout << "* method Type : 3 - Update *" << std::endl;
78 std::cout << "* method Type : 4 - Delete *" << std::endl;
79 std::cout << "* method Type : 5 - Status *" << std::endl;
80 std::cout << "********************************************" << std::endl;
81 std::cout << std::endl;
84 int biasFactorCB(char addr[MAX_ADDR_STR_SIZE], uint16_t port)
86 OICStrcpy(rdAddress, MAX_ADDR_STR_SIZE, addr);
88 std::cout << "RD Address is : " << addr << ":" << port << std::endl;
97 OCPlatform::Configure(cfg);
99 std::cout << "Created Platform..." << std::endl;
103 registerLocalResources();
105 catch (std::runtime_error e)
107 std::cout << "Caught OCException [Code: " << e.what() << std::endl;
114 if (g_curResource_t == NULL || g_curResource_l == NULL)
126 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
127 std::cout << "Invalid input type, please try again" << std::endl;
136 OCRDDiscover(biasFactorCB);
139 OCRDPublish(rdAddress, rdPort, 2, g_curResource_t, g_curResource_l);
144 std::cout << "Invalid input, please try again" << std::endl;
148 catch (OCException e)
150 std::cout << "Caught OCException [Code: " << e.code() << " Reason: " << e.reason() << std::endl;