1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef OC_RDPAYLOAD_H_
22 #define OC_RDPAYLOAD_H_
32 #define OIC_RD_PUBLISH_TTL 86400
34 #define OIC_RD_DEFAULT_RESOURCE 2
36 #define DEFAULT_MESSAGE_TYPE "application/json"
39 * Converts RD payload from structure to CBOR format. It creates the outPayload
40 * which is then transmitted over the wire.
42 * @param rdPayload Contains structure holding values of OCRDPayload.
43 * @param outPayload The payload in the CBOR format converting OCRDPayload
45 * @param size Length of the payload.
47 * @return ::CborNoError returns if successful and other Cbor error in case of error.
48 * failed in creating CBOR.
50 int64_t OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t *outPayload, size_t *size);
53 * Converts CBOR to OCRDPayload.
55 * @param rdCBORPayload Payload received from other end in CBOR format.
56 * @param outPayload Parsing the values from CBOR into OCRDPayload structure.
58 * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
59 * failed in parsing CBOR.
61 OCStackResult OCRDCborToPayload(const CborValue *cborPayload, OCPayload **outPayload);
64 * Initializes RD payload structure.
66 * @param payloadType Defines whether payload is RD_PAYLOAD_TYPE_DISCOVERY or
67 * RD_PAYLOAD_TYPE_PUBLISH.
69 * @return Allocated memory for the OCRDPayload and NULL in case if failed to
72 OCRDPayload *OCRDPayloadCreate();
76 * Initializes RD Publish payload structure.
78 * @param resourceHandles The handle of registered resource.
79 * @param nHandles The number of registered resource handles.
80 * @param ttl Time to live of the published resource.
82 * @return Allocated memory for the OCRDPayload and NULL in case if
83 * failed to allocate memory.
85 OCRDPayload *OCRDPublishPayloadCreate(OCResourceHandle resourceHandles[], uint8_t nHandles,
90 * Initializes RD Discovery payload structure and sets the bias factor.
92 * @param name Name of the discovery device payload.
93 * @param identity Device identity of the discovery device.
94 * @param biasFactor Value specifies the selection factor. It is weigthage of
95 * CPU, Memory, Network, Load and Power capability of the RD server.
97 * @return Allocated memory for the OCRDDiscoveryPayload and NULL in case if
98 * failed to allocate memory.
100 OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *name, const char *identity, int biasFactor);
103 * Free memory allocation of the RDPayload and its internal structure.
105 * @param payload Pointer to already allocated memory for OCRDPayload.
107 void OCRDPayloadDestroy(OCRDPayload *payload);
110 * Copies tag paramter to creates OCTagsPayload.
112 * @param deviceName The device name as set during enrollment.
113 * @param id The device UUID.
114 * @param ttl Time to leave for the . Used only in resource directory.
116 * @retun Allocated memory for OCTagsPayload or else NULL in case of error.
118 OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, uint64_t ttl);
121 * Copies link resource to create LinksPayload.
123 * @param href URI of the resource
124 * @param rel Relation
125 * @param rt Array of String pointing to resource types.
126 * @param itf Array of String pointing to interface
127 * @param p Whether to observe or not.
130 * @param ins Unique value per link.
131 * @param ttl Time to live for this link.
132 * @param mt Media Type
134 * @retun Allocated memory for OCLinksResource or else NULL in case of error.
136 OCLinksPayload* OCCopyLinksResources(const char *href, const char *rel, OCStringLL *rt,
137 OCStringLL *itf, uint8_t p, const char *title,
138 const char *anchor, uint8_t ins, uint64_t ttl,
142 * Creates a resource collection object.
144 * @param tags Pointer pointing to tags payload.
145 * @param links Pointer pointing to links payload.
147 * @return Memory allocation for OCResourceCollectionPayload, else NULL.
149 OCResourceCollectionPayload* OCCopyCollectionResource(OCTagsPayload *tags, OCLinksPayload *links);
152 * Destroys tags payload including internal structure allocated
154 * @param tags - Allocated memory of the tags payload.
156 void OCFreeTagsResource(OCTagsPayload *tags);
159 * Destroys allocated links payload including internal structure allocated.
161 * @param links - Allocated memory to the links payload.
163 void OCFreeLinksResource(OCLinksPayload *links);
166 * ResourceCollection payload destroy. Includes free up tags and links structure.
168 * @param payload Pointer pointing to allocated memroy of ResourceCollection.
170 void OCFreeCollectionResource(OCResourceCollectionPayload *payload);
173 * Discovery collection payload destroy includes internal structure OCResourceCollectionPayload.
175 * @param payload Pointer pointing to allocated memory of OCDiscoveryPayload.
177 void OCDiscoveryCollectionPayloadDestroy(OCDiscoveryPayload* payload);
181 #endif // __cplusplus
183 #endif /* OC_RDPAYLOAD_H_ */