1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #ifndef __STDC_FORMAT_MACROS
25 #define __STDC_FORMAT_MACROS
27 #ifndef __STDC_LIMIT_MACROS
28 #define __STDC_LIMIT_MACROS
40 * Macro to verify the validity of cbor operation.
42 #define VERIFY_CBOR_SUCCESS(log_tag, err, log_message) \
43 if ((CborNoError != (err)) && (CborErrorOutOfMemory != (err))) \
45 if ((log_tag) && (log_message)) \
47 OIC_LOG_V(ERROR, (log_tag), "%s with cbor error: \'%s\'.", \
48 (log_message), (cbor_error_string(err))); \
53 #define VERIFY_PARAM_NON_NULL(log_tag, err, log_message) \
56 OIC_LOG_V(FATAL, (log_tag), "%s", (log_message)); \
61 typedef struct OCResource OCResource;
63 void OCPayloadDestroy(OCPayload* payload);
65 // Representation Payload
66 OCRepPayload* OCRepPayloadCreate();
68 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
70 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
72 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
74 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
76 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
77 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
79 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
80 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
82 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
83 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
85 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
86 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
88 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
89 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
92 * This function allocates memory for the byte string and sets it in the payload.
94 * @param payload Pointer to the payload to which byte string needs to be added.
95 * @param name Name of the byte string.
96 * @param value Byte string and it's length.
98 * @return true on success, false upon failure.
100 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
103 * This function sets the byte string in the payload.
105 * @param payload Pointer to the payload to which byte string needs to be added.
106 * @param name Name of the byte string.
107 * @param value Byte string and it's length.
109 * @return true on success, false upon failure.
111 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
112 OCByteString* value);
115 * This function gets the byte string from the payload.
117 * @param payload Pointer to the payload from which byte string needs to be retrieved.
118 * @param name Name of the byte string.
119 * @param value Byte string and it's length.
121 * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
123 * @return true on success, false upon failure.
125 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
126 OCByteString* value);
128 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
129 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
130 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
132 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
133 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
135 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
136 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name,
137 OCRepPayload* value);
138 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
141 * This function allocates memory for the byte string array and sets it in the payload.
143 * @param payload Pointer to the payload to which byte string array needs to be added.
144 * @param name Name of the byte string.
145 * @param array Byte string array.
146 * @param dimensions Number of byte strings in above array.
148 * @return true on success, false upon failure.
150 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
151 OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
154 * This function sets the byte string array in the payload.
156 * @param payload Pointer to the payload to which byte string array needs to be added.
157 * @param name Name of the byte string.
158 * @param array Byte string array.
159 * @param dimensions Number of byte strings in above array.
161 * @return true on success, false upon failure.
163 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
164 const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
167 * This function gets the byte string array from the payload.
169 * @param payload Pointer to the payload from which byte string array needs to be retrieved.
170 * @param name Name of the byte string array.
171 * @param value Byte string array.
172 * @param dimensions Number of byte strings in above array.
174 * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
175 * finished using the byte string array.
177 * @return true on success, false upon failure.
179 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
180 OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
182 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
183 int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
184 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
185 const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
186 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
187 int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
189 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
190 double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
191 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
192 const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
193 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
194 double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
196 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
197 char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
198 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
199 const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
200 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
201 char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
203 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
204 bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
205 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
206 const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
207 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
208 bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
210 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
211 OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
212 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
213 const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
214 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
215 OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
217 void OCRepPayloadDestroy(OCRepPayload* payload);
220 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
222 OCSecurityPayload* OCSecurityPayloadCreate(const uint8_t* securityData, size_t size);
223 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
225 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
227 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
228 bool OCResourcePayloadAddStringLL(OCStringLL **payload, const char* type);
230 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
231 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
233 void OCDiscoveryResourceDestroy(OCResourcePayload* payload);
234 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
237 OCDevicePayload* OCDevicePayloadCreate(const char* sid, const char* dname,
238 const OCStringLL *types, const char* specVer, const char* dmVer);
239 void OCDevicePayloadDestroy(OCDevicePayload* payload);
242 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
243 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
244 void OCPlatformInfoDestroy(OCPlatformInfo *info);
245 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
248 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
249 OCPresenceTrigger trigger, const char* resourceType);
250 void OCPresencePayloadDestroy(OCPresencePayload* payload);
253 OCStringLL* CloneOCStringLL (OCStringLL* ll);
254 void OCFreeOCStringLL(OCStringLL* ll);