1 //******************************************************************
\r
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
21 #include "EasySetup.h"
\r
24 #include "ESException.h"
\r
25 #include "RemoteEnrollee.h"
\r
31 #define EASYSETUP_TAG "EASY_SETUP"
\r
33 EasySetup * EasySetup::s_instance = nullptr;
\r
35 EasySetup::EasySetup()
\r
40 EasySetup* EasySetup::getInstance ()
\r
42 if (s_instance == nullptr)
\r
44 s_instance = new EasySetup ();
\r
49 RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList (
\r
50 const EnrolleeNWProvInfo& enrolleeNWProvInfo)
\r
52 OC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()");
\r
54 std::vector< std::shared_ptr< RemoteEnrollee > >::iterator it;
\r
56 std::shared_ptr< RemoteEnrollee > remoteEnrollee = nullptr;
\r
57 for(auto it : m_activeEnrolleeList)
\r
59 OC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator");
\r
61 if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,
\r
62 &enrolleeNWProvInfo.netAddressInfo, sizeof(EnrolleeNWProvInfo)))
\r
64 remoteEnrollee = it;
\r
65 return remoteEnrollee;
\r
69 OC_LOG_V(DEBUG,EASYSETUP_TAG,"Return nullptr for findDeviceInProvisioningList call");
\r
70 return remoteEnrollee;
\r
73 bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee)
\r
75 for (auto it : m_activeEnrolleeList)
\r
77 if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,
\r
78 &remoteEnrollee->getEnrolleeProvisioningInfo().netAddressInfo,
\r
79 sizeof(EnrolleeNWProvInfo)))
\r
85 OC_LOG_V(DEBUG,EASYSETUP_TAG,"Adding new device RemoteEnrollee list");
\r
86 m_activeEnrolleeList.push_back(remoteEnrollee);
\r
90 std::shared_ptr<RemoteEnrollee> EasySetup::createEnrolleeDevice (
\r
91 const EnrolleeNWProvInfo& enrolleeNWProvInfo)
\r
93 if (findDeviceInProvisioningList(enrolleeNWProvInfo) != nullptr)
\r
95 throw ESBadRequestException { "Device already created exception" };
\r
98 RemoteEnrollee::shared_ptr remoteEnrollee;
\r
100 remoteEnrollee = std::make_shared< RemoteEnrollee > (enrolleeNWProvInfo);
\r
103 if (!addDeviceToProvisioningList (remoteEnrollee))
\r
108 return remoteEnrollee;
\r