Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / resource / csdk / stack / include / ocpayload.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OCPAYLOAD_H_
22 #define OCPAYLOAD_H_
23
24 #include <stdbool.h>
25 #include <inttypes.h>
26 #include "octypes.h"
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32
33 typedef struct OCResource OCResource;
34
35 void OCPayloadDestroy(OCPayload* payload);
36
37 // Representation Payload
38 OCRepPayload* OCRepPayloadCreate();
39
40 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
41
42 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
43
44 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
45
46 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
47
48 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
49 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
50
51 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
52 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
53
54 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
55 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
56
57 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
58 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
59
60 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
61 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
62
63 /**
64  * This function allocates memory for the byte string and sets it in the payload.
65  *
66  * @param payload      Pointer to the payload to which byte string needs to be added.
67  * @param name         Name of the byte string.
68  * @param value        Byte string and it's length.
69  *
70  * @return true on success, false upon failure.
71  */
72 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
73
74 /**
75  * This function sets the byte string in the payload.
76  *
77  * @param payload      Pointer to the payload to which byte string needs to be added.
78  * @param name         Name of the byte string.
79  * @param value        Byte string and it's length.
80  *
81  * @return true on success, false upon failure.
82  */
83 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
84         OCByteString* value);
85
86 /**
87  * This function gets the byte string from the payload.
88  *
89  * @param payload      Pointer to the payload from which byte string needs to be retrieved.
90  * @param name         Name of the byte string.
91  * @param value        Byte string and it's length.
92  *
93  * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
94  *
95  * @return true on success, false upon failure.
96  */
97 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
98         OCByteString* value);
99
100 bool OCRepPayloadSetPropString(OCRepPayload* payload, const char* name, const char* value);
101 bool OCRepPayloadSetPropStringAsOwner(OCRepPayload* payload, const char* name, char* value);
102 bool OCRepPayloadGetPropString(const OCRepPayload* payload, const char* name, char** value);
103
104 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
105 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
106
107 bool OCRepPayloadSetPropObject(OCRepPayload* payload, const char* name, const OCRepPayload* value);
108 bool OCRepPayloadSetPropObjectAsOwner(OCRepPayload* payload, const char* name,
109         OCRepPayload* value);
110 bool OCRepPayloadGetPropObject(const OCRepPayload* payload, const char* name, OCRepPayload** value);
111
112 /**
113  * This function allocates memory for the byte string array and sets it in the payload.
114  *
115  * @param payload      Pointer to the payload to which byte string array needs to be added.
116  * @param name         Name of the byte string.
117  * @param array        Byte string array.
118  * @param dimensions   Number of byte strings in above array.
119  *
120  * @return true on success, false upon failure.
121  */
122 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
123         OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
124
125 /**
126  * This function sets the byte string array in the payload.
127  *
128  * @param payload      Pointer to the payload to which byte string array needs to be added.
129  * @param name         Name of the byte string.
130  * @param array        Byte string array.
131  * @param dimensions   Number of byte strings in above array.
132  *
133  * @return true on success, false upon failure.
134  */
135 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
136         const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
137
138 /**
139  * This function gets the byte string array from the payload.
140  *
141  * @param payload      Pointer to the payload from which byte string array needs to be retrieved.
142  * @param name         Name of the byte string array.
143  * @param value        Byte string array.
144  * @param dimensions   Number of byte strings in above array.
145  *
146  * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
147  *        finished using the byte string array.
148  *
149  * @return true on success, false upon failure.
150  */
151 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
152         OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
153
154 bool OCRepPayloadSetIntArrayAsOwner(OCRepPayload* payload, const char* name,
155         int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
156 bool OCRepPayloadSetIntArray(OCRepPayload* payload, const char* name,
157         const int64_t* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
158 bool OCRepPayloadGetIntArray(const OCRepPayload* payload, const char* name,
159         int64_t** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
160
161 bool OCRepPayloadSetDoubleArrayAsOwner(OCRepPayload* payload, const char* name,
162         double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
163 bool OCRepPayloadSetDoubleArray(OCRepPayload* payload, const char* name,
164         const double* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
165 bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name,
166         double** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
167
168 bool OCRepPayloadSetStringArrayAsOwner(OCRepPayload* payload, const char* name,
169         char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
170 bool OCRepPayloadSetStringArray(OCRepPayload* payload, const char* name,
171         const char** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
172 bool OCRepPayloadGetStringArray(const OCRepPayload* payload, const char* name,
173         char*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
174
175 bool OCRepPayloadSetBoolArrayAsOwner(OCRepPayload* payload, const char* name,
176         bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
177 bool OCRepPayloadSetBoolArray(OCRepPayload* payload, const char* name,
178         const bool* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
179 bool OCRepPayloadGetBoolArray(const OCRepPayload* payload, const char* name,
180         bool** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
181
182 bool OCRepPayloadSetPropObjectArrayAsOwner(OCRepPayload* payload, const char* name,
183         OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
184 bool OCRepPayloadSetPropObjectArray(OCRepPayload* payload, const char* name,
185         const OCRepPayload** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
186 bool OCRepPayloadGetPropObjectArray(const OCRepPayload* payload, const char* name,
187         OCRepPayload*** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
188
189 void OCRepPayloadDestroy(OCRepPayload* payload);
190
191 // Discovery Payload
192 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
193
194 OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData);
195 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
196
197 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
198         uint16_t port);
199 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
200 bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType);
201 bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface);
202
203 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
204 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
205
206 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
207
208 // Device Payload
209 OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
210         const char* specVer, const char* dmVer);
211 void OCDevicePayloadDestroy(OCDevicePayload* payload);
212
213 // Platform Payload
214 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
215 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
216
217 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
218
219 // Presence Payload
220 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
221         OCPresenceTrigger trigger, const char* resourceType);
222 void OCPresencePayloadDestroy(OCPresencePayload* payload);
223
224 // Helper API
225 OCStringLL* CloneOCStringLL (OCStringLL* ll);
226 void OCFreeOCStringLL(OCStringLL* ll);
227
228 #ifdef __cplusplus
229 }
230 #endif
231
232 #endif