X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fsrc%2Fsimulator_manager.cpp;h=4b10c1451b703e8feffc23d6eb073918f6bda7cf;hb=b76f9709482b03334b468ab47a295761b3fd6a78;hp=38e5269155e064b8bb3639a3bfc69d74316d66ba;hpb=f2b82967201acb66b8ae20512a38cad405fd9c97;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/src/simulator_manager.cpp b/service/simulator/src/simulator_manager.cpp index 38e5269..4b10c14 100644 --- a/service/simulator/src/simulator_manager.cpp +++ b/service/simulator/src/simulator_manager.cpp @@ -19,8 +19,8 @@ ******************************************************************/ #include "simulator_manager.h" -#include "resource_manager.h" -#include "simulator_client.h" +#include "simulator_resource_factory.h" +#include "simulator_remote_resource_impl.h" #include "simulator_utils.h" SimulatorManager *SimulatorManager::getInstance() @@ -43,54 +43,102 @@ SimulatorManager::SimulatorManager() OC::OCPlatform::Configure(conf); } -std::shared_ptr SimulatorManager::createResource( - const std::string &configPath, - SimulatorResourceServer::ResourceModelChangedCB callback) +std::shared_ptr SimulatorManager::createResource( + const std::string &configPath) { - return ResourceManager::getInstance()->createResource(configPath, callback); -} + VALIDATE_INPUT(configPath.empty(), "Empty path!") -std::vector> SimulatorManager::createResource( - const std::string &configPath, unsigned short count, - SimulatorResourceServer::ResourceModelChangedCB callback) -{ - return ResourceManager::getInstance()->createResource(configPath, count, callback); + std::shared_ptr resource = + SimulatorResourceFactory::getInstance()->createResource(configPath); + if (!resource) + throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!"); + return resource; } -std::vector> SimulatorManager::getResources( - const std::string &resourceType) +std::vector> SimulatorManager::createResource( + const std::string &configPath, unsigned int count) { - return ResourceManager::getInstance()->getResources(resourceType); + VALIDATE_INPUT(configPath.empty(), "Empty path!") + VALIDATE_INPUT(!count, "Count is zero!") + + std::vector> resources = + SimulatorResourceFactory::getInstance()->createResource(configPath, count); + if (!resources.size()) + throw SimulatorException(SIMULATOR_ERROR, "Failed to create resource!"); + return resources; } -void SimulatorManager::deleteResource( - const std::shared_ptr &resource) +std::shared_ptr SimulatorManager::createSingleResource( + const std::string &name, const std::string &uri, const std::string &resourceType) { - ResourceManager::getInstance()->deleteResource(resource); + VALIDATE_INPUT(name.empty(), "Empty resource name!") + VALIDATE_INPUT(resourceType.empty(), "Empty resource type!") + + return SimulatorResourceFactory::getInstance()->createSingleResource(name, uri, resourceType); } -void SimulatorManager::deleteResource(const std::string &resourceType) +std::shared_ptr SimulatorManager::createCollectionResource( + const std::string &name, const std::string &uri, const std::string &resourceType) { - ResourceManager::getInstance()->deleteResources(resourceType); + VALIDATE_INPUT(name.empty(), "Empty resource name!") + VALIDATE_INPUT(resourceType.empty(), "Empty resource type!") + + return SimulatorResourceFactory::getInstance()->createCollectionResource(name, uri, resourceType); } void SimulatorManager::findResource(ResourceFindCallback callback) { - SimulatorClient::getInstance()->findResources(callback); + VALIDATE_CALLBACK(callback) + + OC::FindCallback findCallback = std::bind( + [](std::shared_ptr ocResource, ResourceFindCallback callback) + { + if (!ocResource) + return; + + SimulatorRemoteResourceSP simulatorResource(new SimulatorRemoteResourceImpl(ocResource)); + callback(simulatorResource); + }, std::placeholders::_1, callback); + + typedef OCStackResult (*FindResource)(const std::string &, const std::string &, + OCConnectivityType, OC::FindCallback); + + invokeocplatform(static_cast(OC::OCPlatform::findResource), "", + OC_MULTICAST_DISCOVERY_URI, CT_DEFAULT, findCallback); } void SimulatorManager::findResource(const std::string &resourceType, - ResourceFindCallback callback) + ResourceFindCallback callback) { - SimulatorClient::getInstance()->findResources(resourceType, callback); + VALIDATE_INPUT(resourceType.empty(), "Empty resource type!") + VALIDATE_CALLBACK(callback) + + OC::FindCallback findCallback = std::bind( + [](std::shared_ptr ocResource, ResourceFindCallback callback) + { + if (!ocResource) + return; + + SimulatorRemoteResourceSP simulatorResource(new SimulatorRemoteResourceImpl(ocResource)); + callback(simulatorResource); + }, std::placeholders::_1, callback); + + std::ostringstream query; + query << OC_MULTICAST_DISCOVERY_URI << "?rt=" << resourceType; + + typedef OCStackResult (*FindResource)(const std::string &, const std::string &, + OCConnectivityType, OC::FindCallback); + + invokeocplatform(static_cast(OC::OCPlatform::findResource), "", query.str(), + CT_DEFAULT, findCallback); } -void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback) +void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback callback) { - if (!callback) - throw InvalidArgsException(SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); + VALIDATE_CALLBACK(callback) - OC::FindDeviceCallback deviceCallback = [this, callback](const OC::OCRepresentation & rep) + OC::FindDeviceCallback deviceCallback = std::bind( + [](const OC::OCRepresentation & rep, DeviceInfoCallback callback) { std::string deviceName = rep.getValue("n"); std::string deviceID = rep.getValue("di"); @@ -99,25 +147,18 @@ void SimulatorManager::getDeviceInfo(DeviceInfoCallback callback) DeviceInfo deviceInfo(deviceName, deviceID, deviceSpecVersion, deviceDMV); callback(deviceInfo); - }; - - std::ostringstream uri; - uri << OC_MULTICAST_PREFIX << OC_RSRVD_DEVICE_URI; + }, std::placeholders::_1, callback); typedef OCStackResult (*GetDeviceInfo)(const std::string &, const std::string &, OCConnectivityType, OC::FindDeviceCallback); - invokeocplatform(static_cast(OC::OCPlatform::getDeviceInfo), "", - uri.str(), - CT_DEFAULT, - deviceCallback); + invokeocplatform(static_cast(OC::OCPlatform::getDeviceInfo), host.c_str(), + "/oic/d", CT_DEFAULT, deviceCallback); } void SimulatorManager::setDeviceInfo(const std::string &deviceName) { - if (deviceName.empty()) - throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Device name is empty!"); - + VALIDATE_INPUT(deviceName.empty(), "Empty resource type!") typedef OCStackResult (*RegisterDeviceInfo)(const OCDeviceInfo); @@ -127,12 +168,12 @@ void SimulatorManager::setDeviceInfo(const std::string &deviceName) ocDeviceInfo); } -void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback) +void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCallback callback) { - if (!callback) - throw InvalidArgsException(SIMULATOR_INVALID_CALLBACK, "Invalid callback!"); + VALIDATE_CALLBACK(callback) - OC::FindPlatformCallback platformCallback = [this, callback](const OC::OCRepresentation & rep) + OC::FindPlatformCallback platformCallback = std::bind( + [](const OC::OCRepresentation & rep, PlatformInfoCallback callback) { PlatformInfo platformInfo; platformInfo.setPlatformID(rep.getValue("pi")); @@ -148,18 +189,13 @@ void SimulatorManager::getPlatformInfo(PlatformInfoCallback callback) platformInfo.setSystemTime(rep.getValue("st")); callback(platformInfo); - }; - - std::ostringstream uri; - uri << OC_MULTICAST_PREFIX << OC_RSRVD_PLATFORM_URI; + }, std::placeholders::_1, callback); typedef OCStackResult (*GetPlatformInfo)(const std::string &, const std::string &, OCConnectivityType, OC::FindPlatformCallback); - invokeocplatform(static_cast(OC::OCPlatform::getPlatformInfo), "", - uri.str(), - CT_DEFAULT, - platformCallback); + invokeocplatform(static_cast(OC::OCPlatform::getPlatformInfo), host.c_str(), + "/oic/p", CT_DEFAULT, platformCallback); } void SimulatorManager::setPlatformInfo(PlatformInfo &platformInfo)