//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "EasySetup.h"
+#include "EasySetup.hpp"
+#include "OCPlatform.h"
#include "logger.h"
#include "ESException.h"
#include "RemoteEnrollee.h"
+using namespace OC;
+
namespace OIC
{
namespace Service
{
- #define EASYSETUP_TAG "EASY_SETUP"
+ #define EASYSETUP_TAG "ES_EASY_SETUP"
EasySetup * EasySetup::s_instance = nullptr;
EasySetup::EasySetup()
{
-
}
EasySetup* EasySetup::getInstance ()
return s_instance;
}
- RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList (
- const EnrolleeNWProvInfo& enrolleeNWProvInfo)
+ std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (std::shared_ptr< OC::OCResource > resource)
{
- OC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()");
-
- std::vector< std::shared_ptr< RemoteEnrollee > >::iterator it;
+ OIC_LOG(INFO, EASYSETUP_TAG, "createRemoteEnrollee IN");
- std::shared_ptr< RemoteEnrollee > remoteEnrollee = nullptr;
- for(auto it : m_activeEnrolleeList)
+ if(resource)
{
- OC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator");
-
- if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,
- &enrolleeNWProvInfo.netAddressInfo, sizeof(EnrolleeNWProvInfo)))
+ if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_EASYSETUP ||
+ resource->connectivityType() & CT_ADAPTER_TCP)
{
- remoteEnrollee = it;
- return remoteEnrollee;
+ OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is not valid due to wrong rt or conntype");
+ return nullptr;
}
- }
-
- OC_LOG_V(DEBUG,EASYSETUP_TAG,"Return nullptr for findDeviceInProvisioningList call");
- return remoteEnrollee;
- }
- bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee)
- {
- for (auto it : m_activeEnrolleeList)
- {
- if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,
- &remoteEnrollee->getEnrolleeProvisioningInfo().netAddressInfo,
- sizeof(EnrolleeNWProvInfo)))
+ auto interfaces = resource->getResourceInterfaces();
+ for(auto interface : interfaces)
{
- return false;
+ if(interface.compare(BATCH_INTERFACE) == 0)
+ {
+ OIC_LOG (INFO, EASYSETUP_TAG, "RemoteEnrollee object is succeessfully created");
+ OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "HOST: %s", resource->host().c_str());
+ OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "URI: %s", resource->uri().c_str());
+ OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "SID: %s", resource->sid().c_str());
+ OIC_LOG_V (INFO_PRIVATE, EASYSETUP_TAG, "CONNECTIVITY: %d", resource->connectivityType());
+ return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource));
+ }
}
}
- OC_LOG_V(DEBUG,EASYSETUP_TAG,"Adding new device RemoteEnrollee list");
- m_activeEnrolleeList.push_back(remoteEnrollee);
- return true;
+ OIC_LOG (ERROR, EASYSETUP_TAG, "Given resource is NULL");
+ return nullptr;
}
-
- std::shared_ptr<RemoteEnrollee> EasySetup::createEnrolleeDevice (
- const EnrolleeNWProvInfo& enrolleeNWProvInfo)
- {
- if (findDeviceInProvisioningList(enrolleeNWProvInfo) != nullptr)
- {
- throw ESBadRequestException { "Device already created exception" };
- }
-
- RemoteEnrollee::shared_ptr remoteEnrollee;
-
- remoteEnrollee = std::make_shared< RemoteEnrollee > (enrolleeNWProvInfo);
-
-
- if (!addDeviceToProvisioningList (remoteEnrollee))
- {
- return nullptr;
- }
-
- return remoteEnrollee;
- }
-
-
}
}