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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "EasySetup.hpp"
23 #include "OCPlatform.h"
25 #include "ESException.h"
26 #include "RemoteEnrollee.h"
34 #define EASYSETUP_TAG "ES_EASY_SETUP"
36 EasySetup * EasySetup::s_instance = nullptr;
38 EasySetup::EasySetup()
42 EasySetup* EasySetup::getInstance ()
44 if (s_instance == nullptr)
46 s_instance = new EasySetup ();
51 std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (std::shared_ptr< OC::OCResource > resource)
53 OIC_LOG(INFO, EASYSETUP_TAG, "createRemoteEnrollee IN");
57 if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
58 resource->connectivityType() & CT_ADAPTER_TCP)
60 OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is not valid due to wrong rt or conntype");
64 auto interfaces = resource->getResourceInterfaces();
65 for(auto interface : interfaces)
67 if(interface.compare(BATCH_INTERFACE) == 0)
69 OIC_LOG (INFO, EASYSETUP_TAG, "RemoteEnrollee object is succeessfully created");
70 OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "HOST: %s", resource->host().c_str());
71 OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "URI: %s", resource->uri().c_str());
72 OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "SID: %s", resource->sid().c_str());
73 OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "CONNECTIVITY: %d", resource->connectivityType());
74 return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource));
79 OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is NULL");