rep2.setAttributeMap(attrMap2);
- m_resource->put(rep2, QueryParamsMap(), std::function<void(const OCRepresentation, const int)>(std::bind(&ClientWorker::putResourceInfo, this, rep2, std::placeholders::_1, std::placeholders::_2)));
+ m_resource->put(rep2, QueryParamsMap(), PutCallback(std::bind(&ClientWorker::putResourceInfo, this, rep2, std::placeholders::_1, std::placeholders::_2)));
}
}
std::cout<<"Doing a get on q/foo."<<std::endl;
QueryParamsMap test;
- resource->get(test, std::function<void(const OCRepresentation, const int)>(std::bind(&ClientWorker::getResourceInfo, this, std::placeholders::_1, std::placeholders::_2)));
+ resource->get(test, GetCallback(std::bind(&ClientWorker::getResourceInfo, this, std::placeholders::_1, std::placeholders::_2)));
}
}
void start(OCPlatform& platform)
{
std::cout<<"Starting Client find:"<<std::endl;
- std::function<void(std::shared_ptr<OCResource>)> f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
+ FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
std::cout<<"result:" << platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)<< std::endl;
std::cout<<"Finding Resource..."<<std::endl;
uint8_t resourceProperty = OC_DISCOVERABLE;
- std::function<void(std::shared_ptr<OCResourceRequest>, std::shared_ptr<OCResourceResponse>)> eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
+ RegisterCallback eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
OCStackResult result = platform.registerResource(m_resourceHandle, resourceURI, resourceTypeName,
resourceInterface,
eh, resourceProperty);
typedef std::shared_ptr<IClientWrapper> Ptr;
virtual OCStackResult ListenForResource(const std::string& serviceUrl, const std::string& resourceType,
- std::function<void(std::shared_ptr<OCResource>)>& callback) = 0;
+ FindCallback& callback) = 0;
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
GetCallback& callback)=0;
virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- std::function<void(const OCRepresentation&, const int&, const int&)>& callback)=0;
+ ObserveCallback& callback)=0;
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri)=0;
- virtual OCStackResult subscribePresence(OCDoHandle* handle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler)=0;
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ SubscribeCallback& presenceHandler)=0;
- virtual OCStackResult unsubscribePresence(OCDoHandle handle) =0;
+ virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
virtual ~IClientWrapper(){}
std::string& resourceURI,
const std::string& resourceTypeName,
const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+ RegisterCallback& entityHandler,
uint8_t resourceProperty) = 0;
virtual OCStackResult unregisterResource(
const OCResourceHandle& resourceHandle) = 0;
virtual ~InProcClientWrapper();
virtual OCStackResult ListenForResource(const std::string& serviceUrl, const std::string& resourceType,
- std::function<void(std::shared_ptr<OCResource>)>& callback);
+ FindCallback& callback);
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
GetCallback& callback);
virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- std::function<void(const OCRepresentation&, const int&, const int&)>& callback);
+ ObserveCallback& callback);
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri);
- virtual OCStackResult subscribePresence(OCDoHandle* handle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler);
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ SubscribeCallback& presenceHandler);
- virtual OCStackResult unsubscribePresence(OCDoHandle handle);
+ virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
// Note: this should never be called by anyone but the handler for the listen command. It is public becuase that needs to be a non-instance callback
virtual std::shared_ptr<OCResource> parseOCResource(IClientWrapper::Ptr clientWrapper, const std::string& host, const boost::property_tree::ptree resourceNode);
private:
std::thread m_listeningThread;
bool m_threadRun;
std::weak_ptr<std::mutex> m_csdkLock;
- std::vector<std::function<void(OCClientResponse*)>> callbackList;
private:
PlatformConfig m_cfg;
std::string& resourceURI,
const std::string& resourceTypeName,
const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+ RegisterCallback& entityHandler,
uint8_t resourceProperty);
virtual OCStackResult unregisterResource(
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifndef __INTEL_OCAPI_H_2014_07_10
- #define __INTEL_OCAPI_H_2014_07_10
+#define __INTEL_OCAPI_H_2014_07_10
#include <string>
#include <sstream>
#include <memory>
#include "ocstack.h"
-namespace OC {
+namespace OC
+{
+ class OCResource;
+ class OCResourceRequest;
+ class OCResourceResponse;
+} // namespace OC
+namespace OC { namespace OCReflect {
+ struct entity;
+}} // namespace OC::OCReflect
-class OCResource;
+namespace OC
+{
+ enum class OCPlatformStatus
+ {
+ PlatformUp,
+ PlatformDown
+ };
-} // namespace OC
+ enum class OCAdvertisementStatus
+ {
+ None
+ };
-namespace OC { namespace OCReflect {
+ typedef std::string URI;
-struct entity;
+ enum class ServiceType
+ {
+ InProc,
+ OutOfProc
+ };
-}} // namespace OC::OCReflect
+ enum class ModeType
+ {
+ Server,
+ Client,
+ Both
+ };
+
+ enum class QualityOfService : uint8_t
+ {
+ Confirmable = OC_CONFIRMABLE,
+ NonConfirmable = OC_NON_CONFIRMABLE
+ };
-namespace OC {
-
- enum class OCPlatformStatus {
- PlatformUp,
- PlatformDown
- };
-
- enum class OCAdvertisementStatus{
- None
- };
-
- typedef std::string URI;
-
- enum class ServiceType
- {
- InProc,
- OutOfProc
- };
-
- enum class ModeType
- {
- Server,
- Client,
- Both
- };
-
- enum class QualityOfService : uint8_t
- {
- Confirmable = OC_CONFIRMABLE,
- NonConfirmable = OC_NON_CONFIRMABLE
- };
-
- struct PlatformConfig
- {
- ServiceType serviceType; // This will indicate whether it is InProc or OutOfProc
- ModeType mode; // This will indicate whether we want to do server, client or both
- std::string ipAddress; // This is the ipAddress of the server to connect to
- uint16_t port; // Port of the server
-
- QualityOfService QoS;
-
- public:
- PlatformConfig(const ServiceType serviceType_,
- const ModeType mode_,
- const std::string& ipAddress_,
- const uint16_t port_,
- const QualityOfService QoS_)
- : serviceType(serviceType_),
- mode(mode_),
- ipAddress(ipAddress_),
- port(port_),
- QoS(QoS_)
- {}
- };
-
- enum class RequestHandlerFlag
- {
- InitFlag,
- RequestFlag,
- ObserverFlag
- };
-
- enum class ObserveType
- {
- Observe,
- ObserveAll
- };
-
- // TODO: To find the complete JSon data structure and modify map value type
- // Typedef for attribute values and attribute map.
- typedef std::vector<std::string> AttributeValues;
- typedef std::map<std::string, AttributeValues> AttributeMap;
-
- // Typedef for query parameter map
- typedef std::map<std::string, std::string> QueryParamsMap;
-
- // const strings for different interfaces
-
- // Default interface
- const std::string DEFAULT_INTERFACE = "oc.mi.def";
-
- // Used in discovering (GET) links to other resources of a collection.
- const std::string LINK_INTERFACE = "oc.mi.ll";
-
- // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
- const std::string BATCH_INTERFACE = "oc.mi.b";
-
- // Helper function to escape character in a string.
- std::string escapeString(const std::string& value);
-
- class OCRepresentation
+ struct PlatformConfig
{
+ ServiceType serviceType; // This will indicate whether it is InProc or OutOfProc
+ ModeType mode; // This will indicate whether we want to do server, client or both
+ std::string ipAddress; // This is the ipAddress of the server to connect to
+ uint16_t port; // Port of the server
+
+ QualityOfService QoS;
+
+ public:
+ PlatformConfig(const ServiceType serviceType_,
+ const ModeType mode_,
+ const std::string& ipAddress_,
+ const uint16_t port_,
+ const QualityOfService QoS_)
+ : serviceType(serviceType_),
+ mode(mode_),
+ ipAddress(ipAddress_),
+ port(port_),
+ QoS(QoS_)
+ {}
+ };
+
+ enum class RequestHandlerFlag
+ {
+ InitFlag,
+ RequestFlag,
+ ObserverFlag
+ };
+
+ enum class ObserveType
+ {
+ Observe,
+ ObserveAll
+ };
+
+ // TODO: To find the complete JSon data structure and modify map value type
+ // Typedef for attribute values and attribute map.
+ typedef std::vector<std::string> AttributeValues;
+ typedef std::map<std::string, AttributeValues> AttributeMap;
+
+ // Typedef for query parameter map
+ typedef std::map<std::string, std::string> QueryParamsMap;
- private:
+ // const strings for different interfaces
+ // Default interface
+ const std::string DEFAULT_INTERFACE = "oc.mi.def";
+
+ // Used in discovering (GET) links to other resources of a collection.
+ const std::string LINK_INTERFACE = "oc.mi.ll";
+
+ // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
+ const std::string BATCH_INTERFACE = "oc.mi.b";
+
+ // Helper function to escape character in a string.
+ std::string escapeString(const std::string& value);
+
+ class OCRepresentation
+ {
+
+ private:
std::string m_uri;
AttributeMap m_attributeMap;
std::vector<std::string> m_resourceTypes;
std::vector<OCRepresentation> m_children;
- public:
-
+ public:
OCRepresentation() {}
std::string getUri(void) const
void setChildren(std::vector<OCRepresentation> children)
{
- m_children = children;
+ m_children = children;
}
OCResource* getResource() const
return res;
}
- AttributeMap getAttributeMap() const
+ AttributeMap getAttributeMap() const
{
return m_attributeMap;
}
m_resourceInterfaces = resourceInterfaces;
}
};
- typedef std::function<void(const OCRepresentation&, const int)> GetCallback;
- typedef std::function<void(const OCRepresentation&, const int)> PutCallback;
+
+ typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
+ typedef std::function<void(const std::shared_ptr<OCResourceRequest>, const std::shared_ptr<OCResourceResponse>)> RegisterCallback;
+ typedef std::function<void(OCStackResult, const int)> SubscribeCallback;
+ typedef std::function<void(const OCRepresentation&, const int)> GetCallback;
+ typedef std::function<void(const OCRepresentation&, const int)> PutCallback;
+ typedef std::function<void(const OCRepresentation&, const int, const int)> ObserveCallback;
} // namespace OC
-#endif
+#endif
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
- std::function<void(OCResource::Ptr)> resourceHandler);
+ FindCallback resourceHandler);
/**
* This API registers a resource with the server
std::string& resourceURI,
const std::string& resourceTypeName,
const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+ RegisterCallback entityHandler,
uint8_t resourceProperty);
/**
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler);
+ SubscribeCallback presenceHandler);
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
- std::function<void(const OCRepresentation&, const int&, const int&)> observeHandler);
+ ObserveCallback observeHandler);
/**
* Function to cancel the observation on the resource
OutOfProcClientWrapper(std::weak_ptr<std::mutex> csdkLock, PlatformConfig cfg) { }
virtual OCStackResult ListenForResource(const std::string& serviceUrl, const std::string& resourceType,
- std::function<void(std::shared_ptr<OCResource>)>& callback) {return OC_STACK_NOTIMPL;}
+ FindCallback& callback) {return OC_STACK_NOTIMPL;}
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri,
const QueryParamsMap& queryParams, GetCallback& callback){return OC_STACK_NOTIMPL;}
virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle, const std::string& host,
const std::string& uri, const QueryParamsMap& queryParams,
- std::function<void(const OCRepresentation&, const int&, const int&)>& callback){return OC_STACK_NOTIMPL;}
+ ObserveCallback& callback){return OC_STACK_NOTIMPL;}
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri){return OC_STACK_NOTIMPL;}
virtual std::shared_ptr<OCResource> parseOCResource(IClientWrapper::Ptr clientWrapper, const std::string& host,
const boost::property_tree::ptree resourceNode) {return nullptr;}
- virtual OCStackResult subscribePresence(OCDoHandle* handle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler){return OC_STACK_NOTIMPL;}
+ virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
+ SubscribeCallback& presenceHandler){return OC_STACK_NOTIMPL;}
- virtual OCStackResult unsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
+ virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
};
}
std::string& resourceURI,
const std::string& resourceTypeName,
const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
+ RegisterCallback& entityHandler,
uint8_t resourceProperty)
{
struct ListenContext
{
- std::function<void(std::shared_ptr<OCResource>)> callback;
+ FindCallback callback;
IClientWrapper::Ptr clientWrapper;
};
}
}
- OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl, const std::string& resourceType, std::function<void (std::shared_ptr<OCResource>)>& callback)
+ OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl, const std::string& resourceType, FindCallback& callback)
{
OCStackResult result;
struct ObserveContext
{
- std::function<void(const OCRepresentation&, const int&, const int&)> callback;
+ ObserveCallback callback;
};
OCStackApplicationResult observeResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
}
OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle, const std::string& host,
- const std::string& uri, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation&, const int&, const int&)>& callback)
+ const std::string& uri, const QueryParamsMap& queryParams, ObserveCallback& callback)
{
OCStackResult result;
OCCallbackData* cbdata = new OCCallbackData();
return result;
}
- struct UnobserveContext
- {
- std::function<void(const int&)> callback;
- };
-
- OCStackApplicationResult unobserveResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
- {
- UnobserveContext* context = static_cast<UnobserveContext*>(ctx);
- std::thread exec(context->callback, clientResponse->result);
- exec.detach();
- return OC_STACK_DELETE_TRANSACTION;
- }
-
OCStackResult InProcClientWrapper::CancelObserveResource(OCDoHandle handle, const std::string& host, const std::string& uri)
{
OCStackResult result;
struct SubscribePresenceContext
{
- std::function<void(OCStackResult, const int&)> callback;
+ SubscribeCallback callback;
};
OCStackApplicationResult subscribePresenceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
return OC_STACK_KEEP_TRANSACTION;
}
- OCStackResult InProcClientWrapper::subscribePresence(OCDoHandle* handle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler)
+ OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle, const std::string& host,
+ SubscribeCallback& presenceHandler)
{
OCStackResult result;
OCCallbackData* cbdata = new OCCallbackData();
return result;
}
- OCStackResult InProcClientWrapper::unsubscribePresence(OCDoHandle handle)
+ OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
{
OCStackResult result;
auto cLock = m_csdkLock.lock();
using namespace std;
-std::map <OCResourceHandle, std::function<void(const OC::OCResourceRequest::Ptr, const OC::OCResourceResponse::Ptr)>> entityHandlerMap;
+std::map <OCResourceHandle, OC::RegisterCallback> entityHandlerMap;
void defaultEntityHandler(const OC::OCResourceRequest::Ptr request, const OC::OCResourceResponse::Ptr response)
{
std::string& resourceURI,
const std::string& resourceTypeName,
const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> eHandler,
+ RegisterCallback& eHandler,
uint8_t resourceProperties)
{
}
OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri,
- bool isObservable, const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces)
+ bool isObservable, const std::vector<std::string>& resourceTypes,
+ const std::vector<std::string>& interfaces)
{
if(m_client)
{
}
OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
- std::function<void(OCResource::Ptr)> resourceHandler)
+ FindCallback resourceHandler)
{
if(m_client)
{
OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
- std::string& resourceURI,
- const std::string& resourceTypeName,
- const std::string& resourceInterface,
- std::function<void(const OCResourceRequest::Ptr, const OCResourceResponse::Ptr)> entityHandler,
- uint8_t resourceProperty)
+ std::string& resourceURI,
+ const std::string& resourceTypeName,
+ const std::string& resourceInterface,
+ RegisterCallback entityHandler,
+ uint8_t resourceProperty)
{
OCStackResult result = OC_STACK_OK;
}
OCStackResult OCPlatform::bindTypeToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceTypeName) const
+ const std::string& resourceTypeName) const
{
OCStackResult result = OC_STACK_ERROR;
if(m_server)
}
OCStackResult OCPlatform::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
- const std::string& resourceInterfaceName) const
+ const std::string& resourceInterfaceName) const
{
OCStackResult result = OC_STACK_ERROR;
if(m_server)
}
OCStackResult OCPlatform::subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- std::function<void(OCStackResult, const int&)> presenceHandler)
+ SubscribeCallback presenceHandler)
{
if(m_client)
{
- return m_client->subscribePresence(&presenceHandle, host, presenceHandler);
+ return m_client->SubscribePresence(&presenceHandle, host, presenceHandler);
}
else
{
{
if(m_client)
{
- return m_client->unsubscribePresence(presenceHandle);
+ return m_client->UnsubscribePresence(presenceHandle);
}
else
{
}
OCStackResult OCResource::observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
- std::function<void(const OCRepresentation&, const int&, const int&)> observeHandler)
+ ObserveCallback observeHandler)
{
if(m_observeHandle != nullptr)
{