Merge branch 'resource-container'
[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 #ifndef __STDC_FORMAT_MACROS
25 #define __STDC_FORMAT_MACROS
26 #endif
27 #ifndef __STDC_LIMIT_MACROS
28 #define __STDC_LIMIT_MACROS
29 #endif
30 #include <stdbool.h>
31 #include <inttypes.h>
32 #include "octypes.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 typedef struct OCResource OCResource;
40
41 void OCPayloadDestroy(OCPayload* payload);
42
43 // Representation Payload
44 OCRepPayload* OCRepPayloadCreate();
45
46 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
47
48 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
49
50 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
51
52 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
53
54 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
55 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
56
57 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
58 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
59
60 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
61 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
62
63 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
64 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
65
66 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
67 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
68
69 /**
70  * This function allocates memory for the byte string and sets it in the payload.
71  *
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.
75  *
76  * @return true on success, false upon failure.
77  */
78 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
79
80 /**
81  * This function sets the byte string in the payload.
82  *
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.
86  *
87  * @return true on success, false upon failure.
88  */
89 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
90         OCByteString* value);
91
92 /**
93  * This function gets the byte string from the payload.
94  *
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.
98  *
99  * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
100  *
101  * @return true on success, false upon failure.
102  */
103 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
104         OCByteString* value);
105
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);
109
110 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
111 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
112
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);
117
118 /**
119  * This function allocates memory for the byte string array and sets it in the payload.
120  *
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.
125  *
126  * @return true on success, false upon failure.
127  */
128 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
129         OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
130
131 /**
132  * This function sets the byte string array in the payload.
133  *
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.
138  *
139  * @return true on success, false upon failure.
140  */
141 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
142         const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
143
144 /**
145  * This function gets the byte string array from the payload.
146  *
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.
151  *
152  * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
153  *        finished using the byte string array.
154  *
155  * @return true on success, false upon failure.
156  */
157 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
158         OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
159
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]);
166
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]);
173
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]);
180
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]);
187
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]);
194
195 void OCRepPayloadDestroy(OCRepPayload* payload);
196
197 // Discovery Payload
198 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
199
200 OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData);
201 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
202
203 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
204         uint16_t port);
205 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
206 bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType);
207 bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface);
208
209 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
210 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
211
212 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
213
214 // Device Payload
215 OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
216         const char* specVer, const char* dmVer);
217 void OCDevicePayloadDestroy(OCDevicePayload* payload);
218
219 // Platform Payload
220 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
221 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
222
223 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
224
225 // Presence Payload
226 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
227         OCPresenceTrigger trigger, const char* resourceType);
228 void OCPresencePayloadDestroy(OCPresencePayload* payload);
229
230 // Helper API
231 OCStringLL* CloneOCStringLL (OCStringLL* ll);
232 void OCFreeOCStringLL(OCStringLL* ll);
233
234 #ifdef __cplusplus
235 }
236 #endif
237
238 #endif