As part of Gerrit review #101,(
83fed5a6c6b01d32de3e47c669652a1aa79ebb49)
there were changes required in other samples to prevent a crash in the
findResource callback.
Additionally, made minor correction in groupclient by changing
printf to cout in one of the function
Change-Id: I524f5d862c82011e5d008e686cc1d6e41ac3f170
Signed-Off-by:Sudarshan Prasad<sudarshan.prasad@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/126
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
const int SUCCESS_RESPONSE = 0;
std::shared_ptr<OCResource> curResource;
+std::mutex curResourceLock;
class Garage
{
// Callback to found resources
void foundResource(std::shared_ptr<OCResource> resource)
{
+ std::lock_guard<std::mutex> lock(curResourceLock);
if(curResource)
{
std::cout << "Found another resource, ignoring"<<std::endl;
+ return;
}
std::string resourceURI;
#include <mutex>
#include <condition_variable>
#include <iostream>
+#include <mutex>
using namespace std;
using namespace OC;
namespace PH = std::placeholders;
+std::mutex resourceLock;
OCResourceHandle resourceHandle;
shared_ptr< OCResource > g_resource;
void foundResource(std::shared_ptr< OCResource > resource)
{
+ std::lock_guard<std::mutex> lock(resourceLock);
+ if(g_resource)
+ {
+ std::cout << "Found another resource, ignoring"<<std::endl;
+ return;
+ }
+
std::string resourceURI;
std::string hostAddress;
{
string resourceURI = resource->uri();
cout << resourceURI << endl;
+ cout << "HOST :: " << resource->host() << endl;
if (resourceURI == "/core/a/collection")
{
g_resource = resource;
+ resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), onGet);
}
-
- g_resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), onGet);
- printf("HOST :: %s\n", resource->host().c_str());
}
}
catch (std::exception& e)
using namespace OC;
std::shared_ptr<OCResource> curResource;
-
+std::mutex curResourceLock;
static int TEST_CASE = 0;
/**
// Callback to found resources
void foundResource(std::shared_ptr<OCResource> resource)
{
+ std::lock_guard<std::mutex> lock(curResourceLock);
if(curResource)
{
std::cout << "Found another resource, ignoring"<<std::endl;
+ return;
}
std::string resourceURI;
const int SUCCESS_RESPONSE = 0;
std::shared_ptr<OCResource> curResource;
+std::mutex curResourceLock;
int observe_count()
{
// Callback to found resources
void foundResource(std::shared_ptr<OCResource> resource)
{
+ std::lock_guard<std::mutex> lock(curResourceLock);
if(curResource)
{
std::cout << "Found another resource, ignoring"<<std::endl;
const int SUCCESS_RESPONSE = 0;
std::shared_ptr<OCResource> curResource;
+std::mutex curResourceLock;
static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
class Light
// Callback to found resources
void foundResource(std::shared_ptr<OCResource> resource)
{
+ std::lock_guard<std::mutex> lock(curResourceLock);
if(curResource)
{
std::cout << "Found another resource, ignoring"<<std::endl;
+ return;
}
std::string resourceURI;
#include <condition_variable>
#include <map>
#include <vector>
+
#include "OCPlatform.h"
#include "OCApi.h"
-using namespace OC;
+using namespace OC;
struct FooResource
{