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 #define __STDC_FORMAT_MACROS
25 #define __STDC_LIMIT_MACROS
35 typedef struct OCResource OCResource;
37 void OCPayloadDestroy(OCPayload* payload);
39 // Representation Payload
40 OCRepPayload* OCRepPayloadCreate();
42 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
44 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
46 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
48 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
50 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
51 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
53 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
54 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
56 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
57 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
59 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
60 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
62 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
63 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
66 * This function allocates memory for the byte string and sets it in the payload.
68 * @param payload Pointer to the payload to which byte string needs to be added.
69 * @param name Name of the byte string.
70 * @param value Byte string and it's length.
72 * @return true on success, false upon failure.
74 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
77 * This function sets the byte string in the payload.
79 * @param payload Pointer to the payload to which byte string needs to be added.
80 * @param name Name of the byte string.
81 * @param value Byte string and it's length.
83 * @return true on success, false upon failure.
85 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
89 * This function gets the byte string from the payload.
91 * @param payload Pointer to the payload from which byte string needs to be retrieved.
92 * @param name Name of the byte string.
93 * @param value Byte string and it's length.
95 * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
97 * @return true on success, false upon failure.
99 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
100 OCByteString* value);
102 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
103 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
104 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
106 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
107 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
109 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
110 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name,
111 OCRepPayload* value);
112 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
115 * This function allocates memory for the byte string array and sets it in the payload.
117 * @param payload Pointer to the payload to which byte string array needs to be added.
118 * @param name Name of the byte string.
119 * @param array Byte string array.
120 * @param dimensions Number of byte strings in above array.
122 * @return true on success, false upon failure.
124 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
125 OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
128 * This function sets the byte string array in the payload.
130 * @param payload Pointer to the payload to which byte string array needs to be added.
131 * @param name Name of the byte string.
132 * @param array Byte string array.
133 * @param dimensions Number of byte strings in above array.
135 * @return true on success, false upon failure.
137 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
138 const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
141 * This function gets the byte string array from the payload.
143 * @param payload Pointer to the payload from which byte string array needs to be retrieved.
144 * @param name Name of the byte string array.
145 * @param value Byte string array.
146 * @param dimensions Number of byte strings in above array.
148 * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
149 * finished using the byte string array.
151 * @return true on success, false upon failure.
153 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
154 OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
156 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
157 int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
158 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
159 const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
160 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
161 int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
163 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
164 double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
165 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
166 const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
167 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
168 double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
170 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
171 char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
172 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
173 const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
174 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
175 char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
177 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
178 bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
179 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
180 const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
181 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
182 bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
184 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
185 OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
186 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
187 const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
188 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
189 OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
191 void OCRepPayloadDestroy(OCRepPayload* payload);
194 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
196 OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData);
197 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
199 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
201 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
202 bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType);
203 bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface);
205 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
206 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
208 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
211 OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
212 const char* specVer, const char* dmVer);
213 void OCDevicePayloadDestroy(OCDevicePayload* payload);
216 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
217 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
219 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
222 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
223 OCPresenceTrigger trigger, const char* resourceType);
224 void OCPresencePayloadDestroy(OCPresencePayload* payload);
227 OCStringLL* CloneOCStringLL (OCStringLL* ll);
228 void OCFreeOCStringLL(OCStringLL* ll);