#include <vector>
#include "RCSResourceAttributes.h"
+#include "RCSRepresentation.h"
namespace OC
{
SetCallback cb);
/**
+ * Sends a set request with resource representation to the server.
+ *
+ * The SetRequest behavior depends on query parameters and the server.
+ *
+ * @param queryParams Query parameters
+ * @param rep Representation to set
+ * @param cb A callback to receive the response.
+ *
+ * @throws PlatformException If the operation failed
+ * @throws InvalidParameterException If cb is an empty function or null.
+ *
+ * @see RCSResourceObject
+ * @see RCSResourceObject::SetRequestHandlerPolicy
+ *
+ * @note The callback will be invoked in an internal thread.
+ */
+ void set(const RCSQueryParams& queryParams, const RCSRepresentation &rep,
+ SetCallback cb);
+
+ /**
* Returns the uri of the resource.
*
*/
const OC::QueryParamsMap& queryParametersMap,
const RCSResourceAttributes&, GetCallback) = 0;
+ virtual void requestSetWith(const std::string& resourceType,
+ const std::string& resourceInterface,
+ const OC::QueryParamsMap& queryParametersMap,
+ const RCSRepresentation&, SetCallback) = 0;
+
virtual void requestPut(const RCSResourceAttributes&, PutCallback) = 0;
virtual void requestObserve(ObserveCallback) = 0;
virtual void cancelObserve() = 0;
_1, _2, _3));
}
+ void requestSetWith(const std::string& resourceType,
+ const std::string& resourceInterface,
+ const OC::QueryParamsMap& queryParametersMap,
+ const RCSRepresentation & rep, SetCallback callback)
+ {
+ using namespace std::placeholders;
+
+ typedef OCStackResult (BaseResource::*PostFunc)(const std::string&,
+ const std::string&, const OC::OCRepresentation&, const OC::QueryParamsMap&,
+ OC::GetCallback);
+
+ invokeOC(m_baseResource, static_cast< PostFunc >(&BaseResource::post),
+ resourceType, resourceInterface,
+ RCSRepresentation::toOCRepresentation(rep), queryParametersMap,
+ std::bind(safeCallback< SetCallback >, WeakFromThis(), std::move(callback),
+ _1, _2, _3));
+ }
void requestPut(const RCSResourceAttributes& attrs, PutCallback callback)
{
std::move(cb));
}
+ void RCSRemoteResourceObject::set(const RCSQueryParams& queryParams,
+ const RCSRepresentation& rep, SetCallback cb)
+ {
+ SCOPE_LOG_F(DEBUG, TAG);
+
+ if (!cb)
+ {
+ throw RCSInvalidParameterException{ "set : Callback is empty" };
+ }
+
+ const auto& paramMap = queryParams.getAll();
+
+ m_primitiveResource->requestSetWith(
+ queryParams.getResourceType(), queryParams.getResourceInterface(),
+ OC::QueryParamsMap{ paramMap.begin(), paramMap.end() }, rep,
+ std::move(cb));
+ }
+
}
}
void getRemoteAttributesCallback(const RCSResourceAttributes&, int) {}
void setRemoteAttributesCallback(const RCSResourceAttributes&, int) {}
+void setRemoteRepresentationCallback(const HeaderOpts&, const RCSRepresentation&, int) {}
void resourceStateChanged(ResourceState) { }
void cacheUpdatedCallback(const RCSResourceAttributes&) {}
ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY));
}
+TEST_F(RemoteResourceObjectTest, SetRemoteRepresentationDoesNotAllowEmptyFunction)
+{
+ RCSQueryParams queryParams;
+ RCSRepresentation rcsRep;
+ ASSERT_THROW(object->set(queryParams, rcsRep, {}), RCSInvalidParameterException);
+}
+
+TEST_F(RemoteResourceObjectTest, SetRemoteRepresentationSetsRepresentationOfServer)
+{
+ RCSRepresentation rcsRep;
+ RCSQueryParams queryParams;
+ constexpr int newValue = ATTR_VALUE + 1;
+ RCSResourceAttributes newAttrs;
+ newAttrs[ATTR_KEY] = newValue;
+
+ rcsRep.setAttributes(newAttrs);
+
+ mocks.ExpectCallFunc(setRemoteRepresentationCallback).
+ Do([this](const HeaderOpts&, const RCSRepresentation&, int){ Proceed(); });
+
+ object->set(queryParams, rcsRep, setRemoteRepresentationCallback);
+ Wait();
+
+ ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY));
+}
+
TEST_F(RemoteResourceObjectTest, QueryParamsForGetWillBePassedToBase)
{
class CustomHandler