// Create QueryParameters Map and add query params (if any)
QueryParamsMap qp;
- qp["if"] = BATCH_INTERFACE;
-
rep.setAttributeMap(attributeMap);
// Invoke resource's pit API with attribute map, query map and the callback parameter
- resource->put(rep, qp, &onPut);
+ resource->put("core.room", BATCH_INTERFACE, rep, qp, &onPut);
}
}
// Invoke resource's get API with the callback parameter
QueryParamsMap qp;
- qp["if"] = BATCH_INTERFACE; // LINK_INTERFACE;
- resource->get(qp, &onGet);
+ resource->get("core.room", BATCH_INTERFACE, qp, &onGet);
}
}
std::function<void(std::shared_ptr<OCResource>)>& callback) = 0;
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- std::function<void(const OCRepresentation, const int)>& callback)=0;
+ GetCallback& callback)=0;
virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback) = 0;
+ const QueryParamsMap& queryParams, PutCallback& callback) = 0;
virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
virtual OCStackResult ListenForResource(const std::string& serviceUrl, const std::string& resourceType,
std::function<void(std::shared_ptr<OCResource>)>& callback);
-
+
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- std::function<void(const OCRepresentation, const int)>& callback);
-
- virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback);
-
+ GetCallback& callback);
+
+ virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri,
+ const OCRepresentation& attributes, const QueryParamsMap& queryParams, PutCallback& 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);
-
+
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);
#include <sstream>
#include <vector>
#include <map>
-
+#include <memory>
#include "ocstack.h"
namespace OC {
m_resourceInterfaces = resourceInterfaces;
}
};
+ typedef std::function<void(const OCRepresentation&, const int)> GetCallback;
+ typedef std::function<void(const OCRepresentation&, const int)> PutCallback;
} // namespace OC
#endif
friend class InProcClientWrapper;
public:
typedef std::shared_ptr<OCResource> Ptr;
-
/**
* Virtual destructor
*/
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
* NOTE: OCStackResult is defined in ocstack.h.
*/
- OCStackResult get(const QueryParamsMap& queryParametersMap, std::function<void(const OCRepresentation, const int)> attributeHandler);
+ OCStackResult get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
/**
* Function to get the attributes of a resource.
* Currently, single GET request is allowed to do operate on single resource type or resource interface. In future, a single GET <br>
* can operate on multiple resource types and interfaces. <br>
* NOTE: A client can traverse a tree or graph by doing successive GETs on the returned resources at a node.<br>
- * TODO: Implementation
*/
- OCStackResult get(const std::string& resourceType, const std::string& resourceInterface, const QueryParamsMap& queryParametersMap,
- std::function<void(const OCRepresentation& rep, const std::vector<std::string>& resourceUriList, const int& errorCode)> attributeHandler)
- { return OC_STACK_OK; }
+ OCStackResult get(const std::string& resourceType, const std::string& resourceInterface, const QueryParamsMap& queryParametersMap, GetCallback attributeHandler);
/**
* Function to set the attributes of a resource (via PUT)
* NOTE: OCStackResult is defined in ocstack.h.
*/
OCStackResult put(const OCRepresentation& attributeMap, const QueryParamsMap& queryParametersMap,
- std::function< void(const OCRepresentation,const int)> attributeHandler);
+ PutCallback attributeHandler);
/**
* Function to set the attributes of a resource (via PUT)
* set of attribute names and values which needs to be modified
* @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
* NOTE: OCStackResult is defined in ocstack.h. <br>
- * TODO: consider to input hrefs for resource collection
- * TODO: Implementation
*/
OCStackResult put(const std::string& resourceType, const std::string& resourceInterface,
const OCRepresentation& attributeMap, const QueryParamsMap& queryParametersMap,
- std::function< void(const OCRepresentation&,const int&)> attributeHandler) { return OC_STACK_OK; }
+ PutCallback attributeHandler);
/**
* Function to set observation on the resource
std::function<void(std::shared_ptr<OCResource>)>& callback) {return OC_STACK_NOTIMPL;}
virtual OCStackResult GetResourceAttributes(const std::string& host, const std::string& uri,
- const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback){return OC_STACK_NOTIMPL;}
-/*
- virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri,
- const AttributeMap& attributes, const QueryParamsMap& queryParams, std::function<void(const AttributeMap,const int)>& callback){return OC_STACK_NOTIMPL;}
- */
+ const QueryParamsMap& queryParams, GetCallback& callback){return OC_STACK_NOTIMPL;}
+
virtual OCStackResult SetResourceAttributes(const std::string& host, const std::string& uri,
- const OCRepresentation& attributes, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation,const int)>& callback){return OC_STACK_NOTIMPL;}
+ const OCRepresentation& attributes, const QueryParamsMap& queryParams, PutCallback& callback){return OC_STACK_NOTIMPL;}
virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle, const std::string& host,
const std::string& uri, const QueryParamsMap& queryParams,
return result;
}
- struct GetSetContext
+ struct GetContext
{
- std::function<void(const OCRepresentation&, const int&)> callback;
+ GetCallback callback;
+ };
+
+ struct SetContext
+ {
+ PutCallback callback;
};
OCStackApplicationResult getResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
{
- GetSetContext* context = static_cast<GetSetContext*>(ctx);
+ GetContext* context = static_cast<GetContext*>(ctx);
std::cout << "GET JSON: " << (char*) clientResponse->resJSONPayload << endl;
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult InProcClientWrapper::GetResourceAttributes(const std::string& host, const std::string& uri,
- const QueryParamsMap& queryParams, std::function<void(const OCRepresentation, const int)>& callback)
+ const QueryParamsMap& queryParams, GetCallback& callback)
{
OCStackResult result;
OCCallbackData* cbdata = new OCCallbackData();
- GetSetContext* ctx = new GetSetContext();
+ GetContext* ctx = new GetContext();
ctx->callback = callback;
cbdata->context = static_cast<void*>(ctx);
cbdata->cb = &getResourceCallback;
OCStackApplicationResult setResourceCallback(void* ctx, OCDoHandle handle, OCClientResponse* clientResponse)
{
- GetSetContext* context = static_cast<GetSetContext*>(ctx);
+ SetContext* context = static_cast<SetContext*>(ctx);
OCRepresentation attrs;
if(clientResponse->result == OC_STACK_OK)
return payload.str();
}
- OCStackResult InProcClientWrapper::SetResourceAttributes(const std::string& host, const std::string& uri, const OCRepresentation& attributes, const QueryParamsMap& queryParams, std::function<void(const OCRepresentation,const int)>& callback)
+ OCStackResult InProcClientWrapper::SetResourceAttributes(const std::string& host, const std::string& uri,
+ const OCRepresentation& attributes, const QueryParamsMap& queryParams, PutCallback& callback)
{
OCStackResult result;
OCCallbackData* cbdata = new OCCallbackData();
- GetSetContext* ctx = new GetSetContext();
+ SetContext* ctx = new SetContext();
ctx->callback = callback;
cbdata->cb = &setResourceCallback;
{
}
- OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, std::function<void(const OCRepresentation, const int)> attributeHandler)
+ OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler)
{
auto cw = m_clientWrapper.lock();
}
}
+ OCStackResult OCResource::get(const std::string& resourceType, const std::string& resourceInterface,
+ const QueryParamsMap& queryParametersMap, GetCallback attributeHandler)
+ {
+ auto cw = m_clientWrapper.lock();
+
+ if(cw)
+ {
+ QueryParamsMap mapCpy(queryParametersMap);
+
+ if(!resourceType.empty())
+ {
+ mapCpy["rt"]=resourceType;
+ }
+ if(!resourceInterface.empty())
+ {
+ mapCpy["if"]= resourceInterface;
+ }
+
+ return get(mapCpy, attributeHandler);
+ }
+ else
+ {
+ return OC_STACK_ERROR;
+ }
+ }
+
OCStackResult OCResource::put(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap,
- std::function<void(const OCRepresentation, const int)> attributeHandler)
+ PutCallback attributeHandler)
{
auto cw = m_clientWrapper.lock();
}
}
+ OCStackResult OCResource::put(const std::string& resourceType, const std::string& resourceInterface,
+ const OCRepresentation& rep, const QueryParamsMap& queryParametersMap,
+ PutCallback attributeHandler)
+ {
+ auto cw = m_clientWrapper.lock();
+
+ if(cw)
+ {
+ QueryParamsMap mapCpy(queryParametersMap);
+
+ if(!resourceType.empty())
+ {
+ mapCpy["rt"]=resourceType;
+ }
+ if(!resourceInterface.empty())
+ {
+ mapCpy["if"]=resourceInterface;
+ }
+
+ return put(rep, mapCpy, attributeHandler);
+ }
+ else
+ {
+ return OC_STACK_ERROR;
+ }
+ }
+
OCStackResult OCResource::observe(ObserveType observeType, const QueryParamsMap& queryParametersMap,
std::function<void(const OCRepresentation&, const int&, const int&)> observeHandler)
{