replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / src / EasySetup.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "EasySetup.hpp"
22
23 #include "OCPlatform.h"
24 #include "logger.h"
25 #include "ESException.h"
26 #include "RemoteEnrollee.h"
27
28 using namespace OC;
29
30 namespace OIC
31 {
32     namespace Service
33     {
34         #define EASYSETUP_TAG "ES_EASY_SETUP"
35
36         EasySetup * EasySetup::s_instance = nullptr;
37
38         EasySetup::EasySetup()
39         {
40         }
41
42         EasySetup* EasySetup::getInstance ()
43         {
44             if (s_instance == nullptr)
45             {
46                 s_instance = new EasySetup ();
47             }
48             return s_instance;
49         }
50
51         std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (std::shared_ptr< OC::OCResource > resource)
52         {
53             OIC_LOG(INFO, EASYSETUP_TAG, "createRemoteEnrollee IN");
54
55             if(resource)
56             {
57                 if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
58                    resource->connectivityType() & CT_ADAPTER_TCP)
59                 {
60                     OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is not valid due to wrong rt or conntype");
61                     return nullptr;
62                 }
63
64                 auto interfaces = resource->getResourceInterfaces();
65                 for(auto interface : interfaces)
66                 {
67                     if(interface.compare(BATCH_INTERFACE) == 0)
68                     {
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));
75                     }
76                 }
77             }
78
79             OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is NULL");
80             return nullptr;
81         }
82     }
83 }
84