X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fsrc%2FOCPlatform_impl.cpp;h=7060a095b2f1cc9871a550ed22502100d0107fa3;hb=a80fcca32c01536df59510e850c03773b8856da6;hp=3039fe53d8a13a23e8939a7128c18d1d9113675e;hpb=d216075b26515b3912baa0f8b762281c8e9e68a3;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/src/OCPlatform_impl.cpp b/resource/src/OCPlatform_impl.cpp index 3039fe5..7060a09 100644 --- a/resource/src/OCPlatform_impl.cpp +++ b/resource/src/OCPlatform_impl.cpp @@ -30,6 +30,8 @@ // //********************************************************************* +#include "OCPlatform_impl.h" + #include #include #include @@ -40,6 +42,7 @@ #include "OCApi.h" #include "OCException.h" #include "OCUtilities.h" +#include "ocpayload.h" #include "oc_logger.hpp" @@ -54,6 +57,7 @@ namespace OC void OCPlatform_impl::Configure(const PlatformConfig& config) { + OCRegisterPersistentStorageHandler(config.ps); globalConfig() = config; } @@ -76,6 +80,7 @@ namespace OC break; case ModeType::Both: + case ModeType::Gateway: m_server = m_WrapperInstance->CreateServerWrapper(m_csdkLock, config); m_client = m_WrapperInstance->CreateClientWrapper(m_csdkLock, config); break; @@ -85,7 +90,7 @@ namespace OC OCPlatform_impl::OCPlatform_impl(const PlatformConfig& config) : m_cfg { config }, m_WrapperInstance { make_unique() }, - m_csdkLock { make_shared() } + m_csdkLock { std::make_shared() } { init(m_cfg); } @@ -129,16 +134,16 @@ namespace OC return result_guard(OC_STACK_ERROR); } - std::string payload(pResponse->getResourceRepresentation().getJSONRepresentation()); - - return result_guard( + OCRepPayload* pl = pResponse->getResourceRepresentation().getPayload(); + OCStackResult result = OCNotifyListOfObservers(resourceHandle, &observationIds[0], observationIds.size(), - reinterpret_cast(const_cast(payload.c_str())), - static_cast(QoS))); + pl, + static_cast(QoS)); + OCRepPayloadDestroy(pl); + return result_guard(result); } -#ifdef CA_INT OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host, const std::string& uri, OCConnectivityType connectivityType, @@ -151,10 +156,15 @@ namespace OC return std::shared_ptr(); } + uint8_t resourceProperty = 0; + if (isObservable) + { + resourceProperty = (resourceProperty | OC_OBSERVABLE); + } return std::shared_ptr(new OCResource(m_client, host, uri, "", connectivityType, - isObservable, + resourceProperty, resourceTypes, interfaces)); } @@ -170,87 +180,82 @@ namespace OC OCStackResult OCPlatform_impl::findResource(const std::string& host, const std::string& resourceName, OCConnectivityType connectivityType, - FindCallback resourceHandler, QualityOfService QoS) + FindCallback resourceHandler, + QualityOfService QoS) { - return checked_guard(m_client, &IClientWrapper::ListenForResource, host, resourceName, connectivityType, resourceHandler, QoS); } - OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host, - const std::string& deviceURI, - OCConnectivityType connectivityType, - FindDeviceCallback deviceInfoHandler) - { - return result_guard(getDeviceInfo(host, deviceURI, connectivityType, - deviceInfoHandler, m_cfg.QoS)); - } - - OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host, - const std::string& deviceURI, + OCStackResult OCPlatform_impl::findResource(const std::string& host, + const std::string& resourceName, OCConnectivityType connectivityType, - FindDeviceCallback deviceInfoHandler, - QualityOfService QoS) + FindCallback resourceHandler, + FindErrorCallback errorHandler) { - return checked_guard(m_client, &IClientWrapper::ListenForDevice, - host, deviceURI, connectivityType, deviceInfoHandler, QoS); - } - -#else - OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host, - const std::string& uri, - bool isObservable, - const std::vector& resourceTypes, - const std::vector& interfaces) - { - if(!m_client) - { - return std::shared_ptr(); - } - - return std::shared_ptr(new OCResource(m_client, - host, - uri, - "", // 'created' Resources have no way of knowing their - // server ID, so this has to be blank initially. - isObservable, - resourceTypes, - interfaces)); + return findResource(host, resourceName, connectivityType, resourceHandler, + errorHandler, m_cfg.QoS); } OCStackResult OCPlatform_impl::findResource(const std::string& host, const std::string& resourceName, - FindCallback resourceHandler) + OCConnectivityType connectivityType, + FindCallback resourceHandler, + FindErrorCallback errorHandler, + QualityOfService QoS) { - return findResource(host, resourceName, resourceHandler, m_cfg.QoS); + return checked_guard(m_client, &IClientWrapper::ListenErrorForResource, + host, resourceName, connectivityType, resourceHandler, + errorHandler, QoS); } - OCStackResult OCPlatform_impl::findResource(const std::string& host, + OCStackResult OCPlatform_impl::findResourceList(const std::string& host, const std::string& resourceName, - FindCallback resourceHandler, QualityOfService QoS) + OCConnectivityType connectivityType, + FindResListCallback resourceHandler, + QualityOfService QoS) { - - return checked_guard(m_client, &IClientWrapper::ListenForResource, - host, resourceName, resourceHandler, QoS); + return checked_guard(m_client, &IClientWrapper::ListenForResource2, + host, resourceName, connectivityType, resourceHandler, QoS); } OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host, const std::string& deviceURI, + OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler) { - return result_guard(getDeviceInfo(host, deviceURI, deviceInfoHandler, m_cfg.QoS)); + return result_guard(getDeviceInfo(host, deviceURI, connectivityType, + deviceInfoHandler, m_cfg.QoS)); } OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host, const std::string& deviceURI, + OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler, QualityOfService QoS) { return checked_guard(m_client, &IClientWrapper::ListenForDevice, - host, deviceURI, deviceInfoHandler, QoS); + host, deviceURI, connectivityType, deviceInfoHandler, QoS); } -#endif + OCStackResult OCPlatform_impl::getPlatformInfo(const std::string& host, + const std::string& platformURI, + OCConnectivityType connectivityType, + FindPlatformCallback platformInfoHandler) + { + return result_guard(getPlatformInfo(host, platformURI, connectivityType, + platformInfoHandler, m_cfg.QoS)); + } + + OCStackResult OCPlatform_impl::getPlatformInfo(const std::string& host, + const std::string& platformURI, + OCConnectivityType connectivityType, + FindPlatformCallback platformInfoHandler, + QualityOfService QoS) + { + return checked_guard(m_client, &IClientWrapper::ListenForDevice, + host, platformURI, connectivityType, platformInfoHandler, QoS); + } OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle, std::string& resourceURI, @@ -260,7 +265,7 @@ namespace OC uint8_t resourceProperty) { return checked_guard(m_server, &IServerWrapper::registerResource, - ref(resourceHandle), resourceURI, resourceTypeName, + std::ref(resourceHandle), resourceURI, resourceTypeName, resourceInterface, entityHandler, resourceProperty); } @@ -269,14 +274,20 @@ namespace OC return checked_guard(m_server, &IServerWrapper::registerDeviceInfo, deviceInfo); } + OCStackResult OCPlatform_impl::registerPlatformInfo(const OCPlatformInfo platformInfo) + { + return checked_guard(m_server, &IServerWrapper::registerPlatformInfo, platformInfo); + } + OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle, const std::shared_ptr< OCResource > resource) { uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE; std::vector resourceTypes = resource->getResourceTypes(); - return checked_guard(m_server, &IServerWrapper::registerResourceWithHost, - ref(resourceHandle), resource->host(), resource->uri(), resourceTypes[0]/*"core.remote"*/, "oc.mi.def", + return checked_guard(m_server, &IServerWrapper::registerResource, + std::ref(resourceHandle), resource->host() + resource->uri(), + resourceTypes[0]/*"core.remote"*/, DEFAULT_INTERFACE, (EntityHandler) nullptr, resourceProperty); } @@ -289,7 +300,7 @@ namespace OC OCStackResult OCPlatform_impl::unbindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle) { - return result_guard(OCUnBindResource(ref(collectionHandle), ref(resourceHandle))); + return result_guard(OCUnBindResource(std::ref(collectionHandle), std::ref(resourceHandle))); } OCStackResult OCPlatform_impl::unbindResources(const OCResourceHandle collectionHandle, @@ -355,7 +366,6 @@ namespace OC return checked_guard(m_server, &IServerWrapper::stopPresence); } -#ifdef CA_INT OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host, OCConnectivityType connectivityType, @@ -375,34 +385,123 @@ namespace OC &presenceHandle, host, resourceType, connectivityType, presenceHandler); } -#else - OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle, - const std::string& host, - SubscribeCallback presenceHandler) - { - return subscribePresence(presenceHandle, host, "", presenceHandler); - } - OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle, - const std::string& host, - const std::string& resourceType, - SubscribeCallback presenceHandler) + OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle) { - return checked_guard(m_client, &IClientWrapper::SubscribePresence, - &presenceHandle, host, resourceType, - presenceHandler); + return checked_guard(m_client, &IClientWrapper::UnsubscribePresence, + std::ref(presenceHandle)); } -#endif - OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle) +#ifdef WITH_CLOUD + OCStackResult OCPlatform_impl::subscribeDevicePresence(OCPresenceHandle& presenceHandle, + const std::string& host, + const std::vector& di, + OCConnectivityType connectivityType, + ObserveCallback callback) { - return checked_guard(m_client, &IClientWrapper::UnsubscribePresence, - ref(presenceHandle)); + return checked_guard(m_client, &IClientWrapper::SubscribeDevicePresence, + &presenceHandle, host, di, connectivityType, callback); } +#endif OCStackResult OCPlatform_impl::sendResponse(const std::shared_ptr pResponse) { return checked_guard(m_server, &IServerWrapper::sendResponse, pResponse); } +#ifdef RD_CLIENT + OCStackResult OCPlatform_impl::publishResourceToRD(const std::string& host, + OCConnectivityType connectivityType, + ResourceHandles& resourceHandles, + PublishResourceCallback callback) + { + return publishResourceToRD(host, connectivityType, resourceHandles, + callback, m_cfg.QoS); + } + + OCStackResult OCPlatform_impl::publishResourceToRD(const std::string& host, + OCConnectivityType connectivityType, + ResourceHandles& resourceHandles, + PublishResourceCallback callback, + QualityOfService qos) + { + return checked_guard(m_server, &IServerWrapper::publishResourceToRD, + host, connectivityType, resourceHandles, callback, + static_cast(qos)); + } + + OCStackResult OCPlatform_impl::deleteResourceFromRD(const std::string& host, + OCConnectivityType connectivityType, + ResourceHandles& resourceHandles, + DeleteResourceCallback callback) + { + return deleteResourceFromRD(host, connectivityType, resourceHandles, callback, + m_cfg.QoS); + } + + OCStackResult OCPlatform_impl::deleteResourceFromRD(const std::string& host, + OCConnectivityType connectivityType, + ResourceHandles& resourceHandles, + DeleteResourceCallback callback, + QualityOfService qos) + { + return checked_guard(m_server, &IServerWrapper::deleteResourceFromRD, + host, connectivityType, resourceHandles, callback, + static_cast(qos)); + } +#endif + std::weak_ptr OCPlatform_impl::csdkLock() + { + return m_csdkLock; + } + + OCStackResult OCPlatform_impl::findDirectPairingDevices(unsigned short waittime, + GetDirectPairedCallback directPairingHandler) + { + return checked_guard(m_client, &IClientWrapper::FindDirectPairingDevices, + waittime, directPairingHandler); + + } + + OCStackResult OCPlatform_impl::getDirectPairedDevices( + GetDirectPairedCallback directPairingHandler) + { + + return checked_guard(m_client, &IClientWrapper::GetDirectPairedDevices, + directPairingHandler); + } + + OCStackResult OCPlatform_impl::doDirectPairing(std::shared_ptr peer, + OCPrm_t pmSel, + const std::string& pinNumber, + DirectPairingCallback resultCallback) + { + return checked_guard(m_client, &IClientWrapper::DoDirectPairing, + peer, pmSel, pinNumber, resultCallback); + } +#ifdef WITH_CLOUD + OCAccountManager::Ptr OCPlatform_impl::constructAccountManagerObject(const std::string& host, + OCConnectivityType connectivityType) + { + if (!m_client) + { + return std::shared_ptr(); + } + + return std::shared_ptr(new OCAccountManager(m_client, + host, + connectivityType)); + } +#endif // WITH_CLOUD + + OCStackResult OCPlatform_impl::getDeviceId(OCUUIdentity *myUuid) + { + return OCGetDeviceId(myUuid); + } + + OCStackResult OCPlatform_impl::setDeviceId(const OCUUIdentity *myUuid) + { + return OCSetDeviceId(myUuid); + } } //namespace OC +