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
39 typedef struct OCResource OCResource;
41 void OCPayloadDestroy(OCPayload* payload);
43 // Representation Payload
44 OCRepPayload* OCRepPayloadCreate();
46 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
48 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
50 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
52 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
54 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
55 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
57 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
58 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
60 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
61 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
63 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
64 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
66 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
67 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
70 * This function allocates memory for the byte string and sets it in the payload.
72 * @param payload Pointer to the payload to which byte string needs to be added.
73 * @param name Name of the byte string.
74 * @param value Byte string and it's length.
76 * @return true on success, false upon failure.
78 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
81 * This function sets the byte string in the payload.
83 * @param payload Pointer to the payload to which byte string needs to be added.
84 * @param name Name of the byte string.
85 * @param value Byte string and it's length.
87 * @return true on success, false upon failure.
89 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
93 * This function gets the byte string from the payload.
95 * @param payload Pointer to the payload from which byte string needs to be retrieved.
96 * @param name Name of the byte string.
97 * @param value Byte string and it's length.
99 * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
101 * @return true on success, false upon failure.
103 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
104 OCByteString* value);
106 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
107 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
108 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
110 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
111 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
113 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
114 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name,
115 OCRepPayload* value);
116 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
119 * This function allocates memory for the byte string array and sets it in the payload.
121 * @param payload Pointer to the payload to which byte string array needs to be added.
122 * @param name Name of the byte string.
123 * @param array Byte string array.
124 * @param dimensions Number of byte strings in above array.
126 * @return true on success, false upon failure.
128 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
129 OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
132 * This function sets the byte string array in the payload.
134 * @param payload Pointer to the payload to which byte string array needs to be added.
135 * @param name Name of the byte string.
136 * @param array Byte string array.
137 * @param dimensions Number of byte strings in above array.
139 * @return true on success, false upon failure.
141 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
142 const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
145 * This function gets the byte string array from the payload.
147 * @param payload Pointer to the payload from which byte string array needs to be retrieved.
148 * @param name Name of the byte string array.
149 * @param value Byte string array.
150 * @param dimensions Number of byte strings in above array.
152 * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
153 * finished using the byte string array.
155 * @return true on success, false upon failure.
157 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
158 OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
160 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
161 int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
162 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
163 const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
164 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
165 int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
167 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
168 double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
169 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
170 const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
171 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
172 double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
174 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
175 char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
176 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
177 const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
178 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
179 char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
181 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
182 bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
183 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
184 const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
185 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
186 bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
188 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
189 OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
190 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
191 const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
192 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
193 OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
195 void OCRepPayloadDestroy(OCRepPayload* payload);
198 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
200 OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData);
201 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
203 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
205 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
206 bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType);
207 bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface);
209 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
210 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
212 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
215 OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
216 const char* specVer, const char* dmVer);
217 void OCDevicePayloadDestroy(OCDevicePayload* payload);
220 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
221 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
223 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
226 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
227 OCPresenceTrigger trigger, const char* resourceType);
228 void OCPresencePayloadDestroy(OCPresencePayload* payload);
231 OCStringLL* CloneOCStringLL (OCStringLL* ll);
232 void OCFreeOCStringLL(OCStringLL* ll);