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 _RESOURCE_DIRECTORY_PAYLOAD_H_
22 #define _RESOURCE_DIRECTORY_PAYLOAD_H_
34 * Converts RD payload from structure to CBOR format. It creates the outPayload
35 * which is then transmitted over the wire.
37 * @param rdPayload Contains structure holding values of OCRDPayload.
38 * @param outPayload The payload in the CBOR format converting OCRDPayload
40 * @param size Length of the payload.
42 * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
43 * failed in creating CBOR.
45 OCStackResult OCRDPayloadToCbor(const OCRDPayload *rdPayload,
46 uint8_t *outPayload, size_t *size);
49 * Converts CBOR to OCRDPayload.
51 * @param rdCBORPayload Payload received from other end in CBOR format.
52 * @param outPayload Parsing the values from CBOR into OCRDPayload structure.
54 * @return ::OC_STACK_OK returns if successful and OC_STACK_ERROR returns if
55 * failed in parsing CBOR.
57 OCStackResult OCRDCborToPayload(const CborValue *rdCBORPayload, OCPayload **outPayload);
60 * Initializes RD payload structure.
62 * @param payloadType Defines whether payload is RD_PAYLOAD_TYPE_DISCOVERY or
63 * RD_PAYLOAD_TYPE_PUBLISH.
65 * @return Allocated memory for the OCRDPayload and NULL in case if failed to
68 OCRDPayload *OCRDPayloadCreate(OCRDPayloadType payloadType);
71 * Initializes RD Discovery payload structure and sets the bias factor.
73 * @param biasFactor Value specifies the selection factor. It is weigthage of
74 * CPU, Memory, Network, Load and Power capability of the RD server.
76 * @return Allocated memory for the OCRDDiscoveryPayload and NULL in case if
77 * failed to allocate memory.
79 OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(int biasFactor);
82 * Creates the links payload, which is then embedded inside OCRDPublishPayload.
84 * @param uri The Web Link Address of the resource.
85 * @param rt The resource type of the published resource.
86 * @param itf The interface type of the published resource.
87 * @param linkPayload The address of the allocated memory or NULL in case if failed
90 void OCRDLinksPayloadCreate(const char *uri, const char *rt, const char *itf,
91 OCRDLinksPayload **linkPayload);
94 * Creates the links payload, which is then embedded inside OCRDPublishPayload.
96 * @param ttl Time to live of the published resource..
97 * @param linkPayload The link payload with uri, rt and itf.
99 * @return Allocated memory of OCRDPublishPayload or NULL in case if failed
100 * to allocate memory.
102 OCRDPublishPayload *OCRDPublishPayloadCreate(const int ttl,
103 OCRDLinksPayload *linkPayload);
106 * Free memory allocation of the RDPayload and its internal structure.
108 * @param payload Pointer to already allocated memory for OCRDPayload.
110 void OCRDPayloadDestroy(OCRDPayload *payload);
113 * Logs the content of the OCRDPayload.
115 * @param level Log level DEBUG or INFO or ERROR.
116 * @param tag File specific tag to use.
117 * @param payload Pointer to already allocated memory for OCRDPayload.
119 void OCRDPayloadLog(LogLevel level, const char *tag, const OCRDPayload *payload);
122 * Logs the subset of the OCRDPayload, prints separately OCRDPublish.
124 * @param level Log level DEBUG or INFO or ERROR.
125 * @param tag File specific tag to use.
126 * @param payload Pointer to already allocated memory for OCRDPublish.
128 void OCRDPublishPayloadLog(LogLevel level, const char *tag,
129 const OCRDPublishPayload *payload);
133 #endif // __cplusplus