1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "RCSDiscoveryManager.h"
23 #include "RCSRemoteResourceObject.h"
24 #include "PrimitiveResource.h"
26 #include "ScopeLogger.h"
28 #define TAG PCF("RCSDiscoveryManager")
30 using namespace OIC::Service;
34 void findCallback(std::shared_ptr< PrimitiveResource > primitiveResource,
35 RCSDiscoveryManager::ResourceDiscoveredCallback cb)
37 SCOPE_LOG_F(DEBUG, TAG);
39 if (!primitiveResource)
41 OC_LOG(ERROR, TAG, "findCallback : primitiveResource is null.");
45 cb(std::make_shared< RCSRemoteResourceObject >(primitiveResource));
53 RCSDiscoveryManager* RCSDiscoveryManager::getInstance()
55 static RCSDiscoveryManager instance;
59 void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
60 ResourceDiscoveredCallback cb)
62 discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, "", std::move(cb));
65 void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
66 const std::string& relativeURI, ResourceDiscoveredCallback cb)
68 discoverResourceByType(address, relativeURI, "", std::move(cb));
71 void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
72 const std::string& resourceType,
73 ResourceDiscoveredCallback cb)
75 discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, resourceType, std::move(cb));
78 void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
79 const std::string& relativeURI, const std::string& resourceType,
80 ResourceDiscoveredCallback cb)
84 OC_LOG(ERROR, TAG, "discoverResourceByType NULL Callback");
85 throw InvalidParameterException { "discoverResourceByType NULL Callback'" };
89 std::string resourceURI = relativeURI + "?rt=" + resourceType;
90 OIC::Service::discoverResource(address, resourceURI,
91 std::bind(findCallback, std::placeholders::_1, std::move(cb)));