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 mpEntityHandler(const std::shared_ptr< OCResourceRequest > request)
32 cout << "mpEntityHandler:\n";
36 // Get the request type and request flag
37 std::string requestType = request->getRequestType();
38 int requestFlag = request->getRequestHandlerFlag();
41 if (requestFlag == RequestHandlerFlag::InitFlag)
43 cout << "\trequestFlag : Init\n";
45 // entity handler to perform resource initialization operations
47 else if (requestFlag == RequestHandlerFlag::RequestFlag)
49 cout << "\trequestFlag : Request\n";
51 OCRepresentation rp = request->getResourceRepresentation();
53 // If the request type is GET
54 if (requestType == "GET")
56 cout << "\t\trequestType : GET\n";
58 else if (requestType == "PUT")
60 cout << "\t\trequestType : PUT\n";
62 action = rp.getValue< std::string >("play");
63 cout << "\t\t\tplay : " << action << endl;
65 else if (requestType == "POST")
67 cout << "\t\trequestType : POST\n";
69 else if (requestType == "DELETE")
71 cout << "\t\trequestType : DELETE\n";
74 else if (requestFlag == RequestHandlerFlag::ObserverFlag)
76 cout << "\trequestFlag : Observer\n";
81 cout << "Request invalid" << endl;
87 int main(int argc, char* argv[])
89 // Create PlatformConfig object
91 { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
93 OCPlatform::Configure(cfg);
97 OCResourceHandle mpResourceHandle = NULL;
104 cout << "(1) CREATE MUSIC PLAYER | (2) DELETE MUSIC PLAYER" << endl;
106 std::cin >> selectedMenu;
108 if (selectedMenu == 1)
110 if (mpResourceHandle)
112 cout << "Music player resource is registered already." << endl;
116 std::string resourceURi = "/core/musicplayer";
117 std::string resourceTypeName = "core.musicplayer";
118 std::string resourceInterface = DEFAULT_INTERFACE;
120 result = OCPlatform::registerResource(mpResourceHandle, resourceURi,
121 resourceTypeName, resourceInterface, mpEntityHandler,
122 OC_DISCOVERABLE | OC_OBSERVABLE);
123 if (OC_STACK_OK == result)
125 cout << "To register music player resource was successful\n";
129 cout << "To register music player resource was unsuccessful\n";
132 else if (selectedMenu == 2)
134 if (NULL == mpResourceHandle)
137 << "Error! No resource to unregister. Register resource first!"
142 result = OCPlatform::unregisterResource(mpResourceHandle);
143 if (OC_STACK_OK == result)
145 cout << "To unregister music player resource was successful\n";
149 cout << "To unregister music player resource was unsuccessful\n";
152 mpResourceHandle = NULL;
156 catch (OCException& e)