b42d61f48ace88ea9c86a9313eaace4d6bb173ad
[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 #define __STDC_FORMAT_MACROS
25 #define __STDC_LIMIT_MACROS
26 #include <stdbool.h>
27 #include <inttypes.h>
28 #include "octypes.h"
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34
35 typedef struct OCResource OCResource;
36
37 void OCPayloadDestroy(OCPayload* payload);
38
39 // Representation Payload
40 OCRepPayload* OCRepPayloadCreate();
41
42 size_t calcDimTotal(const size_t dimensions[MAX_REP_ARRAY_DEPTH]);
43
44 OCRepPayload* OCRepPayloadClone(const OCRepPayload* payload);
45
46 void OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);
47
48 bool OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);
49
50 bool OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
51 bool OCRepPayloadAddInterface(OCRepPayload* payload, const char* interface);
52
53 bool OCRepPayloadAddResourceTypeAsOwner(OCRepPayload* payload, char* resourceType);
54 bool OCRepPayloadAddInterfaceAsOwner(OCRepPayload* payload, char* interface);
55
56 bool OCRepPayloadIsNull(const OCRepPayload* payload, const char* name);
57 bool OCRepPayloadSetNull(OCRepPayload* payload, const char* name);
58
59 bool OCRepPayloadSetPropInt(OCRepPayload* payload, const char* name, int64_t value);
60 bool OCRepPayloadGetPropInt(const OCRepPayload* payload, const char* name, int64_t* value);
61
62 bool OCRepPayloadSetPropDouble(OCRepPayload* payload, const char* name, double value);
63 bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, double* value);
64
65 /**
66  * This function allocates memory for the byte string and sets it in the payload.
67  *
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.
71  *
72  * @return true on success, false upon failure.
73  */
74 bool OCRepPayloadSetPropByteString(OCRepPayload* payload, const char* name, OCByteString value);
75
76 /**
77  * This function sets the byte string in the payload.
78  *
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.
82  *
83  * @return true on success, false upon failure.
84  */
85 bool OCRepPayloadSetPropByteStringAsOwner(OCRepPayload* payload, const char* name,
86         OCByteString* value);
87
88 /**
89  * This function gets the byte string from the payload.
90  *
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.
94  *
95  * @note: Caller needs to invoke OCFree on value.bytes after it is finished using the byte string.
96  *
97  * @return true on success, false upon failure.
98  */
99 bool OCRepPayloadGetPropByteString(const OCRepPayload* payload, const char* name,
100         OCByteString* value);
101
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);
105
106 bool OCRepPayloadSetPropBool(OCRepPayload* payload, const char* name, bool value);
107 bool OCRepPayloadGetPropBool(const OCRepPayload* payload, const char* name, bool* value);
108
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);
113
114 /**
115  * This function allocates memory for the byte string array and sets it in the payload.
116  *
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.
121  *
122  * @return true on success, false upon failure.
123  */
124 bool OCRepPayloadSetByteStringArrayAsOwner(OCRepPayload* payload, const char* name,
125         OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
126
127 /**
128  * This function sets the byte string array in the payload.
129  *
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.
134  *
135  * @return true on success, false upon failure.
136  */
137 bool OCRepPayloadSetByteStringArray(OCRepPayload* payload, const char* name,
138         const OCByteString* array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
139
140 /**
141  * This function gets the byte string array from the payload.
142  *
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.
147  *
148  * @note: Caller needs to invoke OICFree on 'bytes' field of all array elements after it is
149  *        finished using the byte string array.
150  *
151  * @return true on success, false upon failure.
152  */
153 bool OCRepPayloadGetByteStringArray(const OCRepPayload* payload, const char* name,
154         OCByteString** array, size_t dimensions[MAX_REP_ARRAY_DEPTH]);
155
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]);
162
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]);
169
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]);
176
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]);
183
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]);
190
191 void OCRepPayloadDestroy(OCRepPayload* payload);
192
193 // Discovery Payload
194 OCDiscoveryPayload* OCDiscoveryPayloadCreate();
195
196 OCSecurityPayload* OCSecurityPayloadCreate(const char* securityData);
197 void OCSecurityPayloadDestroy(OCSecurityPayload* payload);
198
199 void OCDiscoveryPayloadAddResource(OCDiscoveryPayload* payload, const OCResource* res,
200         uint16_t port);
201 void OCDiscoveryPayloadAddNewResource(OCDiscoveryPayload* payload, OCResourcePayload* res);
202 bool OCResourcePayloadAddResourceType(OCResourcePayload* payload, const char* resourceType);
203 bool OCResourcePayloadAddInterface(OCResourcePayload* payload, const char* interface);
204
205 size_t OCDiscoveryPayloadGetResourceCount(OCDiscoveryPayload* payload);
206 OCResourcePayload* OCDiscoveryPayloadGetResource(OCDiscoveryPayload* payload, size_t index);
207
208 void OCDiscoveryPayloadDestroy(OCDiscoveryPayload* payload);
209
210 // Device Payload
211 OCDevicePayload* OCDevicePayloadCreate(const uint8_t* sid, const char* dname,
212         const char* specVer, const char* dmVer);
213 void OCDevicePayloadDestroy(OCDevicePayload* payload);
214
215 // Platform Payload
216 OCPlatformPayload* OCPlatformPayloadCreate(const OCPlatformInfo* platformInfo);
217 OCPlatformPayload* OCPlatformPayloadCreateAsOwner(OCPlatformInfo* platformInfo);
218
219 void OCPlatformPayloadDestroy(OCPlatformPayload* payload);
220
221 // Presence Payload
222 OCPresencePayload* OCPresencePayloadCreate(uint32_t seqNum, uint32_t maxAge,
223         OCPresenceTrigger trigger, const char* resourceType);
224 void OCPresencePayloadDestroy(OCPresencePayload* payload);
225
226 // Helper API
227 OCStringLL* CloneOCStringLL (OCStringLL* ll);
228 void OCFreeOCStringLL(OCStringLL* ll);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif