1 //******************************************************************
3 // Copyright 2014 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #include "OCPlatform.h"
26 #include "ThingsManager.h"
30 OCEntityHandlerResult speakerEntityHandler(const std::shared_ptr< OCResourceRequest > request)
32 cout << "speakerEntityHandler:\n";
36 // Get the request type and request flag
37 std::string requestType = request->getRequestType();
38 int requestFlag = request->getRequestHandlerFlag();
41 if (requestFlag == RequestHandlerFlag::RequestFlag)
43 cout << "\trequestFlag : Request\n";
45 OCRepresentation rp = request->getResourceRepresentation();
47 // If the request type is GET
48 if (requestType == "GET")
50 cout << "\t\trequestType : GET\n";
52 else if (requestType == "PUT")
54 cout << "\t\trequestType : PUT\n";
56 action = rp.getValue< std::string >("volume");
57 cout << "\t\t\tvolume : " << action << endl;
59 else if (requestType == "POST")
61 cout << "\t\trequestType : POST\n";
63 else if (requestType == "DELETE")
65 cout << "\t\trequestType : DELETE\n";
68 else if (requestFlag == RequestHandlerFlag::ObserverFlag)
70 cout << "\trequestFlag : Observer\n";
75 cout << "Request invalid" << endl;
81 int main(int argc, char* argv[])
84 // Create PlatformConfig object
86 { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
88 OCPlatform::Configure(cfg);
90 OCPlatform::startPresence(30);
94 OCResourceHandle speakerResourceHandle = NULL;
101 cout << "(1) CREATE SPEAKER | (2) DELETE SPEAKER" << endl;
103 std::cin >> selectedMenu;
105 if (selectedMenu == 1)
107 if (speakerResourceHandle)
109 cout << "Speaker resource is registered already." << endl;
113 std::string resourceURi = "/core/speaker";
114 std::string resourceTypeName = "core.speaker";
116 std::string resourceInterface = DEFAULT_INTERFACE;
118 result = OCPlatform::registerResource(speakerResourceHandle, resourceURi,
119 resourceTypeName, resourceInterface, speakerEntityHandler,
120 OC_DISCOVERABLE | OC_OBSERVABLE);
121 if (OC_STACK_OK == result)
123 cout << "To register speaker resource was successful\n";
127 cout << "To register speaker resource was unsuccessful\n";
130 else if (selectedMenu == 2)
132 if (NULL == speakerResourceHandle)
135 << "Error! No resource to unregister. Register resource first!"
140 result = OCPlatform::unregisterResource(speakerResourceHandle);
141 if (OC_STACK_OK == result)
143 cout << "To unregister speaker resource was successful\n";
147 cout << "To unregister speaker resource was unsuccessful\n";
150 speakerResourceHandle = NULL;
154 catch (OCException& e)
156 std::cout << "Exception: " << e.what() << std::endl;