X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fresource-encapsulation%2Finclude%2FRCSRemoteResourceObject.h;h=5a27f0a44a26b4a4db19d5af6b2291987785ff75;hb=390866079e285d2c74918432c0d597d5da52f8a0;hp=bd66a2f57c9dc9809ebd7fc5d11ad6fc4d94cbea;hpb=3e9402ad71cb3e93266a77796f44d17bab9853fd;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/resource-encapsulation/include/RCSRemoteResourceObject.h b/service/resource-encapsulation/include/RCSRemoteResourceObject.h index bd66a2f..5a27f0a 100644 --- a/service/resource-encapsulation/include/RCSRemoteResourceObject.h +++ b/service/resource-encapsulation/include/RCSRemoteResourceObject.h @@ -31,10 +31,25 @@ #include "RCSResourceAttributes.h" +namespace OC +{ + class OCResource; + + namespace HeaderOption + { + class OCHeaderOption; + } +} + namespace OIC { namespace Service { + + class RCSRepresentation; + + typedef std::vector< OC::HeaderOption::OCHeaderOption > HeaderOpts; + /** * The states of caching. * @@ -69,6 +84,74 @@ namespace OIC class PrimitiveResource; /** + * This is to specify query parameters for requests to the server. + * + * @see RCSRemoteResourceObject + */ + class RCSQueryParams + { + public: + typedef std::unordered_map< std::string, std::string > Map; + + public: + + /** + * Sets an interface of the resource to operate on + * + * @param interface interface + */ + RCSQueryParams& setResourceInterface(std::string interface); + + /** + * Sets a resource type of the resource to operate on + * + * @param type resource type + */ + RCSQueryParams& setResourceType(std::string type); + + /** + * Sets a resource type of the resource to operate on + * + * @param key key to be inserted + * @param value value to be inserted + * + * @note "rt" and "if" are reserved, so you should avoid them as a key. + * + */ + RCSQueryParams& put(std::string key, std::string value); + + /** + * Returns the resource interface. + */ + std::string getResourceInterface() const; + + /** + * Returns the resource type. + */ + std::string getResourceType() const; + + /** + * Returns a value. + * + * @param key key of the element whose mapped value is accessed. + * + * @throws InvalidKeyException If @a key doesn't match the key of any value. + */ + std::string get(const std::string& key) const; + + /** + * Returns all params. + */ + const Map& getAll() const; + + private: + std::string m_resourceInterface; + std::string m_resourceType; + + std::unordered_map< std::string, std::string > m_map; + }; + + /** * * This represents a remote resource and provides simple ways to interact with it. * Basically this is a client of a remote resource that runs on other device. @@ -112,6 +195,18 @@ namespace OIC RemoteAttributesGetCallback; /** + * Callback definition to be invoked when the response of get is received. + * + * @param HeaderOpts + * @param rep the result representation + * @param eCode the error code received from the resource + * + * @see get + */ + typedef std::function< void(const HeaderOpts& headerOpts, + const RCSRepresentation& rep, int eCode) > GetCallback; + + /** * Callback definition to be invoked when the response of setRemoteAttributes is * received. * @@ -120,9 +215,21 @@ namespace OIC * * @see setRemoteAttributes */ - typedef std::function< void(const RCSResourceAttributes&, int) > + typedef std::function< void(const RCSResourceAttributes& attrs, int eCode) > RemoteAttributesSetCallback; + /** + * Callback definition to be invoked when the response of set is received. + * + * @param HeaderOpts + * @param rep the result representation + * @param eCode the error code received from the resource + * + * @see set + */ + typedef std::function< void(const HeaderOpts& headerOpts, + const RCSRepresentation& rep, int eCode) > SetCallback; + private: typedef int CacheID; typedef unsigned int BrokerID; @@ -135,6 +242,14 @@ namespace OIC ~RCSRemoteResourceObject(); /** + * Creates an instance from an OCResource instance. + * + * @throw RCSInvalidParameterException If ocResource is nullptr. + */ + static RCSRemoteResourceObject::Ptr fromOCResource( + std::shared_ptr< OC::OCResource > ocResource); + + /** * Returns whether monitoring is enabled. * * @see startMonitoring() @@ -298,18 +413,43 @@ namespace OIC * Gets resource attributes directly from the server. * * This API send a get request to the resource of interest and provides - * the attributes to the caller in the RemoteAttributesReceivedCallback. + * the attributes to the caller in the RemoteAttributesGetCallback. * * @throws PlatformException If the operation failed * @throws InvalidParameterException If cb is an empty function or null. * - * @see RCSResourceAttributes::Value - * * @note The callback will be invoked in an internal thread. */ void getRemoteAttributes(RemoteAttributesGetCallback cb); /** + * Gets resource representation with empty query parameters directly from the server. + * + * @param cb A callback to receive the response. + * + * @throws PlatformException If the operation failed + * @throws InvalidParameterException If cb is an empty function or null. + * + * @note The callback will be invoked in an internal thread. + */ + void get(GetCallback cb); + + /** + * Gets resource representation directly from the server. + * + * The response could be different by the query parameters, it depends on server. + * + * @param queryParams Query parameters + * @param cb A callback to receive the response. + * + * @throws PlatformException If the operation failed + * @throws InvalidParameterException If cb is an empty function or null. + * + * @note The callback will be invoked in an internal thread. + */ + void get(const RCSQueryParams& queryParams, GetCallback cb); + + /** * Sends a set request with resource attributes to the server. * * The SetRequest behavior depends on the server, whether updating its attributes or not. @@ -329,6 +469,44 @@ namespace OIC RemoteAttributesSetCallback cb); /** + * Sends a set request with resource attributes to the server. + * + * The SetRequest behavior depends on query parameters and the server. + * + * @param attributes Attributes 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 RCSResourceAttributes& attributes, SetCallback cb); + + /** + * Sends a set request with resource attributes to the server. + * + * The SetRequest behavior depends on query parameters and the server. + * + * @param queryParams Query parameters + * @param attributes Attributes 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 RCSResourceAttributes& attributes, + SetCallback cb); + + /** * Returns the uri of the resource. * */