FindCallback& callback,
QualityOfService QoS) = 0;
- virtual OCStackResult ListenForResource2(const std::string& serviceUrl,
+ virtual OCStackResult ListenForResourceList(const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
FindResListCallback& callback,
QualityOfService QoS) = 0;
+ virtual OCStackResult ListenForResourceListWithError(const std::string& serviceUrl,
+ const std::string& resourceType,
+ OCConnectivityType connectivityType,
+ FindResListCallback& callback,
+ FindErrorCallback& errorCallback,
+ QualityOfService QoS) = 0;
+
virtual OCStackResult ListenErrorForResource(const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
: callback(cb), clientWrapper(cw){}
};
- struct ListenContext2
+ struct ListenErrorContext
+ {
+ FindCallback callback;
+ FindErrorCallback errorCallback;
+ std::weak_ptr<IClientWrapper> clientWrapper;
+
+ ListenErrorContext(FindCallback cb1, FindErrorCallback cb2,
+ std::weak_ptr<IClientWrapper> cw)
+ : callback(cb1), errorCallback(cb2), clientWrapper(cw){}
+ };
+
+ struct ListenResListContext
{
FindResListCallback callback;
std::weak_ptr<IClientWrapper> clientWrapper;
- ListenContext2(FindResListCallback cb, std::weak_ptr<IClientWrapper> cw)
+ ListenResListContext(FindResListCallback cb, std::weak_ptr<IClientWrapper> cw)
: callback(cb), clientWrapper(cw){}
};
- struct ListenErrorContext
+ struct ListenResListWithErrorContext
{
- FindCallback callback;
+ FindResListCallback callback;
FindErrorCallback errorCallback;
std::weak_ptr<IClientWrapper> clientWrapper;
- ListenErrorContext(FindCallback cb1, FindErrorCallback cb2,
+ ListenResListWithErrorContext(FindResListCallback cb1, FindErrorCallback cb2,
std::weak_ptr<IClientWrapper> cw)
: callback(cb1), errorCallback(cb2), clientWrapper(cw){}
};
const std::string& resourceType, OCConnectivityType transportFlags,
FindCallback& callback, QualityOfService QoS);
- virtual OCStackResult ListenForResource2(const std::string& serviceUrl,
+ virtual OCStackResult ListenForResourceList(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType transportFlags,
FindResListCallback& callback, QualityOfService QoS);
+ virtual OCStackResult ListenForResourceListWithError(const std::string& serviceUrl,
+ const std::string& resourceType, OCConnectivityType connectivityType,
+ FindResListCallback& callback, FindErrorCallback& errorCallback,
+ QualityOfService QoS);
+
virtual OCStackResult ListenErrorForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType transportFlags,
FindCallback& callback, FindErrorCallback& errorCallback, QualityOfService QoS);
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
QualityOfService QoS = QualityOfService::LowQos);
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService QoS = QualityOfService::LowQos);
+
OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
QualityOfService QoS);
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService Qos);
+
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
QualityOfService /*QoS*/)
{return OC_STACK_NOTIMPL;}
- virtual OCStackResult ListenForResource2(const std::string& /*servUrl*/,
+ virtual OCStackResult ListenForResourceList(const std::string& /*servUrl*/,
const std::string& /*rsrcType*/,
OCConnectivityType /*connType*/,
FindResListCallback& /*callback*/,
QualityOfService /*QoS*/)
{return OC_STACK_NOTIMPL;}
+ virtual OCStackResult ListenForResourceListWithError(const std::string& /*servUrl*/,
+ const std::string& /*rsrcType*/,
+ OCConnectivityType /*connType*/,
+ FindResListCallback& /*callback*/,
+ FindErrorCallback& /*errorCallback*/,
+ QualityOfService /*QoS*/)
+ {return OC_STACK_NOTIMPL;}
+
virtual OCStackResult ListenErrorForResource(const std::string& /*servUrl*/,
const std::string& /*rsrcType*/,
OCConnectivityType /*connType*/,
OCStackApplicationResult listenCallback(void* ctx, OCDoHandle /*handle*/,
OCClientResponse* clientResponse)
{
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
ClientCallbackContext::ListenContext* context =
static_cast<ClientCallbackContext::ListenContext*>(ctx);
ClientCallbackContext::ListenErrorContext* context =
static_cast<ClientCallbackContext::ListenErrorContext*>(ctx);
- if (!context)
- {
- return OC_STACK_KEEP_TRANSACTION;
- }
OCStackResult result = clientResponse->result;
if (result == OC_STACK_OK)
return result;
}
- OCStackApplicationResult listenCallback2(void* ctx, OCDoHandle /*handle*/,
+ OCStackApplicationResult listenResListCallback(void* ctx, OCDoHandle /*handle*/,
OCClientResponse* clientResponse)
{
- ClientCallbackContext::ListenContext2* context =
- static_cast<ClientCallbackContext::ListenContext2*>(ctx);
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ ClientCallbackContext::ListenResListContext* context =
+ static_cast<ClientCallbackContext::ListenResListContext*>(ctx);
if (clientResponse->result != OC_STACK_OK)
{
- oclog() << "listenCallback2(): failed to create resource. clientResponse: "
+ oclog() << "listenResListCallback(): failed to create resource. clientResponse: "
<< clientResponse->result
<< std::flush;
if (!clientResponse->payload || clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY)
{
- oclog() << "listenCallback2(): clientResponse payload was null or the wrong type"
+ oclog() << "listenResListCallback(): clientResponse payload was null or the wrong type"
<< std::flush;
return OC_STACK_KEEP_TRANSACTION;
}
if (!clientWrapper)
{
- oclog() << "listenCallback2(): failed to get a shared_ptr to the client wrapper"
+ oclog() << "listenResListCallback(): failed to get a shared_ptr to the client wrapper"
<< std::flush;
return OC_STACK_KEEP_TRANSACTION;
}
}
catch (std::exception &e)
{
- oclog() << "Exception in listCallback2, ignoring response: "
+ oclog() << "Exception in listenResListCallback(), ignoring response: "
<< e.what() << std::flush;
}
-
return OC_STACK_KEEP_TRANSACTION;
}
- OCStackResult InProcClientWrapper::ListenForResource2(
+ OCStackResult InProcClientWrapper::ListenForResourceList(
const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
ostringstream resourceUri;
resourceUri << serviceUrl << resourceType;
- ClientCallbackContext::ListenContext2* context =
- new ClientCallbackContext::ListenContext2(callback, shared_from_this());
+ ClientCallbackContext::ListenResListContext* context =
+ new ClientCallbackContext::ListenResListContext(callback, shared_from_this());
+ OCCallbackData cbdata;
+ cbdata.context = static_cast<void*>(context),
+ cbdata.cb = listenResListCallback;
+ cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenResListContext*)c;};
+
+ auto cLock = m_csdkLock.lock();
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCDoResource(nullptr, OC_REST_DISCOVER,
+ resourceUri.str().c_str(),
+ nullptr, nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ nullptr, 0);
+ }
+ else
+ {
+ delete context;
+ result = OC_STACK_ERROR;
+ }
+ return result;
+ }
+
+ OCStackApplicationResult listenResListWithErrorCallback(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse* clientResponse)
+ {
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ ClientCallbackContext::ListenResListWithErrorContext* context =
+ static_cast<ClientCallbackContext::ListenResListWithErrorContext*>(ctx);
+
+ OCStackResult result = clientResponse->result;
+ if (result != OC_STACK_OK)
+ {
+ oclog() << "listenResListWithErrorCallback(): failed to create resource. clientResponse: "
+ << result << std::flush;
+
+ //send the error callback
+ std::thread exec(context->errorCallback, clientResponse->resourceUri, result);
+ exec.detach();
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ if (!clientResponse->payload || clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY)
+ {
+ oclog() << "listenResListWithErrorCallback(): clientResponse payload was null or the wrong type"
+ << std::flush;
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ auto clientWrapper = context->clientWrapper.lock();
+
+ if (!clientWrapper)
+ {
+ oclog() << "listenResListWithErrorCallback(): failed to get a shared_ptr to the client wrapper"
+ << std::flush;
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ try
+ {
+ ListenOCContainer container(clientWrapper, clientResponse->devAddr,
+ reinterpret_cast<OCDiscoveryPayload*>(clientResponse->payload));
+
+ std::thread exec(context->callback, container.Resources());
+ exec.detach();
+ }
+ catch (std::exception &e)
+ {
+ oclog() << "Exception in listenResListWithErrorCallback(), ignoring response: "
+ << e.what() << std::flush;
+ }
+
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ OCStackResult InProcClientWrapper::ListenForResourceListWithError(
+ const std::string& serviceUrl,
+ const std::string& resourceType,
+ OCConnectivityType connectivityType,
+ FindResListCallback& callback,
+ FindErrorCallback& errorCallback, QualityOfService QoS)
+ {
+ if (!callback)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ OCStackResult result;
+ ostringstream resourceUri;
+ resourceUri << serviceUrl << resourceType;
+
+ ClientCallbackContext::ListenResListWithErrorContext* context =
+ new ClientCallbackContext::ListenResListWithErrorContext(callback, errorCallback,
+ shared_from_this());
+ if (!context)
+ {
+ return OC_STACK_ERROR;
+ }
+
OCCallbackData cbdata;
cbdata.context = static_cast<void*>(context),
- cbdata.cb = listenCallback2;
- cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenContext2*)c;};
+ cbdata.cb = listenResListWithErrorCallback;
+ cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenResListWithErrorContext*)c;};
auto cLock = m_csdkLock.lock();
if (cLock)
connectivityType, resourceHandler, QoS);
}
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
+ connectivityType, resourceHandler, errorHandler, QoS);
+ }
+
OCStackResult getDeviceInfo(const std::string& host,
const std::string& deviceURI,
OCConnectivityType connectivityType,
FindResListCallback resourceHandler,
QualityOfService QoS)
{
- return checked_guard(m_client, &IClientWrapper::ListenForResource2,
+ return checked_guard(m_client, &IClientWrapper::ListenForResourceList,
host, resourceName, connectivityType, resourceHandler, QoS);
}
+ OCStackResult OCPlatform_impl::findResourceList(const std::string& host,
+ const std::string& resourceName,
+ OCConnectivityType connectivityType,
+ FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler,
+ QualityOfService Qos)
+ {
+ return checked_guard(m_client, &IClientWrapper::ListenForResourceListWithError,
+ host, resourceName, connectivityType, resourceHandler,
+ errorHandler, Qos);
+ }
+
OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
const std::string& deviceURI,
OCConnectivityType connectivityType,