#include "RCSDiscoveryManagerImpl.h"
-namespace
-{
- constexpr char ALL_RESOURCE_TYPES[] = "";
-}
-
namespace OIC
{
namespace Service
{
RCSDiscoveryManager::DiscoveryTask::DiscoveryTask(unsigned int id) :
- m_id{ id }
- {
- }
+ m_id { id } {}
bool RCSDiscoveryManager::DiscoveryTask::isCanceled()
{
void RCSDiscoveryManager::DiscoveryTask::cancel()
{
- if (isCanceled()) return;
+ if (isCanceled())
+ return;
RCSDiscoveryManagerImpl::getInstance()->cancel(m_id);
m_id = RCSDiscoveryManagerImpl::INVALID_ID;
RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResource(
const RCSAddress& address, ResourceDiscoveredCallback cb)
{
- return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, ALL_RESOURCE_TYPES,
- std::move(cb));
+ return discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI,
+ RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE, std::move(cb));
}
RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResource(
const RCSAddress& address, const std::string& relativeUri,
ResourceDiscoveredCallback cb)
{
- return discoverResourceByType(address, relativeUri, ALL_RESOURCE_TYPES, std::move(cb));
+ return discoverResourceByType(address, relativeUri,
+ RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE, std::move(cb));
}
RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResourceByType(
namespace
{
- constexpr char ALL_RESOURCE_TYPE[] = "";
constexpr unsigned int POLLING_INTERVAL_TIME = 60000;
std::string makeResourceId(const std::shared_ptr< OIC::Service::PrimitiveResource >& resource)
namespace Service
{
constexpr RCSDiscoveryManagerImpl::ID RCSDiscoveryManagerImpl::INVALID_ID;
+ constexpr char const* RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE;
RCSDiscoveryManagerImpl::RCSDiscoveryManagerImpl()
{
throw RCSInvalidParameterException{ "Callback is empty" };
}
- for(const auto& it : resourceTypes)
+ for(auto it = resourceTypes.begin()+1; it < resourceTypes.end(); it++)
{
- if (it.compare(ALL_RESOURCE_TYPE) == 0)
+ if ((*it).compare(ALL_RESOURCE_TYPE) == 0)
{
- throw RCSInvalidParameterException{ "ResourceType is duplicated!" };
+ throw RCSInvalidParameterException{ "ResourceType is duplicated!" };
}
}
{
if (m_resourceTypes.empty())
{
- m_resourceTypes.push_back(ALL_RESOURCE_TYPE);
+ m_resourceTypes.push_back(RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE);
}
}
constexpr char RESOURCEINTERFACE[]{ "oic.if.baseline" };
constexpr int DEFAULT_DISCOVERYTASK_DELAYTIME = 3000;
-int callTimes = 0;
-
-void resourceDiscoveredForTwoTimesCall(RCSRemoteResourceObject::Ptr)
-{
- callTimes++;
-}
+void resourceDiscoveredForTwoTimesCall(RCSRemoteResourceObject::Ptr) {}
void resourceDiscoveredForCall(RCSRemoteResourceObject::Ptr) {}
void resourceDiscoveredForNeverCall(RCSRemoteResourceObject::Ptr) {}
cond.notify_all();
}
- void proceed_on_condition()
- {
- cond.notify_all();
- if(callTimes != 2)
- {
- waitForDiscoveryTask();
- }
- }
-
void waitForDiscoveryTask(int waitingTime = DEFAULT_DISCOVERYTASK_DELAYTIME)
{
std::unique_lock< std::mutex > lock{ mutex };
stopPresence();
}
-TEST_F(DiscoveryManagerTest, discoveryRequestByMultipleResourceTypesAndFindResourcesOfTwoResourceTypes)
+TEST_F(DiscoveryManagerTest, discoveryRequestByMultipleResourceTypesAndFindResourceOfOneResourceType)
{
std::vector<std::string> resourceTypes{RESOURCETYPE, SECOND_RESOURCETYPE};
const std::string uri = "/oic/res";
- callTimes = 0;
- createResource();
createSecondResource();
- mocks.ExpectCallFunc(resourceDiscoveredForTwoTimesCall).Do(
- [this](RCSRemoteResourceObject::Ptr){ proceed_on_condition(); });
+ mocks.ExpectCallFunc(resourceDiscoveredForCall).Do(
+ [this](RCSRemoteResourceObject::Ptr){ proceed();});
RCSDiscoveryManager::getInstance()->discoverResourceByTypes(RCSAddress::multicast(),
- uri, resourceTypes, resourceDiscoveredForTwoTimesCall);
+ uri, resourceTypes, resourceDiscoveredForCall);
waitForDiscoveryTask();
}
-TEST_F(DiscoveryManagerTest, discoveryRequestByMultipleResourceTypesAndFindResourceOfOneResourceType)
+TEST_F(DiscoveryManagerTest, discoveryRequestByMultipleResourceTypesAndFindResourcesOfTwoResourceTypes)
{
std::vector<std::string> resourceTypes{RESOURCETYPE, SECOND_RESOURCETYPE};
const std::string uri = "/oic/res";
+ unsigned int callTimes = 0;
+ createResource();
createSecondResource();
- mocks.ExpectCallFunc(resourceDiscoveredForCall).Do(
- [this](RCSRemoteResourceObject::Ptr){ proceed();});
+ mocks.OnCallFunc(resourceDiscoveredForTwoTimesCall).Do(
+ [this, &callTimes](RCSRemoteResourceObject::Ptr){
+ callTimes++;
+ if (callTimes == 2) proceed();
+ }
+ );
RCSDiscoveryManager::getInstance()->discoverResourceByTypes(RCSAddress::multicast(),
- uri, resourceTypes, resourceDiscoveredForCall);
+ uri, resourceTypes, resourceDiscoveredForTwoTimesCall);
waitForDiscoveryTask();
+
+ EXPECT_EQ(resourceTypes.size(), callTimes);
}
TEST_F(DiscoveryManagerTest, cancelDiscoveryTaskAfterDiscoveryResource)