ce625842c27a7757fd463e78bf4f25d0226a381e
[platform/core/base/bundle.git] / parcel / stub.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "parcel/api/parcel.h"
18 #include "parcel/common.hh"
19 #include "parcel/log_private.hh"
20 #include "parcel/parcel.hh"
21 #include "parcel/parcelable.hh"
22
23 using namespace tizen_base;
24
25 extern "C" EXPORT int parcel_create(parcel_h *parcel) {
26   if (parcel == nullptr) {
27     _E("Invalid parameter");
28     return PARCEL_ERROR_INVALID_PARAMETER;
29   }
30
31   auto* h = new (std::nothrow) Parcel();
32   if (h == nullptr) {
33     _E("Out of memory");
34     return PARCEL_ERROR_OUT_OF_MEMORY;
35   }
36
37   *parcel = static_cast<parcel_h>(h);
38   return PARCEL_ERROR_NONE;
39 }
40
41 extern "C" EXPORT int parcel_destroy(parcel_h parcel) {
42   if (parcel == nullptr) {
43     _E("Invalid parameter");
44     return PARCEL_ERROR_INVALID_PARAMETER;
45   }
46
47   auto* h = static_cast<Parcel*>(parcel);
48   delete h;
49   return PARCEL_ERROR_NONE;
50 }
51
52 extern "C" EXPORT int parcel_clone(parcel_h parcel, parcel_h* clone) {
53   if (parcel == nullptr || clone == nullptr) {
54     _E("Invalid parameter");
55     return PARCEL_ERROR_INVALID_PARAMETER;
56   }
57
58   auto* h = static_cast<Parcel*>(parcel);
59   auto* c = new (std::nothrow) Parcel(*h);
60   if (c == nullptr) {
61     _E("Out of memory");
62     return PARCEL_ERROR_OUT_OF_MEMORY;
63   }
64
65   *clone = static_cast<parcel_h>(c);
66   return PARCEL_ERROR_NONE;
67 }
68
69 extern "C" EXPORT int parcel_burst_write(parcel_h parcel, const void *buf,
70     uint32_t size) {
71   if (parcel == nullptr || buf == nullptr || size == 0) {
72     _E("Invalid parameter");
73     return PARCEL_ERROR_INVALID_PARAMETER;
74   }
75
76   auto* h = static_cast<Parcel*>(parcel);
77   h->Write(buf, size);
78   return PARCEL_ERROR_NONE;
79 }
80
81 extern "C" EXPORT int parcel_burst_read(parcel_h parcel, void *buf,
82     uint32_t size) {
83   if (parcel == nullptr || buf == nullptr || size == 0) {
84     _E("Invalid parameter");
85     return PARCEL_ERROR_INVALID_PARAMETER;
86   }
87
88   auto* h = static_cast<Parcel*>(parcel);
89   h->Read(buf, size);
90   return PARCEL_ERROR_NONE;
91 }
92
93 extern "C" EXPORT int parcel_write_bool(parcel_h parcel, bool val) {
94   if (parcel == nullptr) {
95     _E("Invalid parameter");
96     return PARCEL_ERROR_INVALID_PARAMETER;
97   }
98
99   auto* h = static_cast<Parcel*>(parcel);
100   h->WriteBool(val);
101   return PARCEL_ERROR_NONE;
102 }
103
104 extern "C" EXPORT int parcel_write_byte(parcel_h parcel, char val) {
105   if (parcel == nullptr) {
106     _E("Invalid parameter");
107     return PARCEL_ERROR_INVALID_PARAMETER;
108   }
109
110   auto* h = static_cast<Parcel*>(parcel);
111   h->WriteByte(val);
112   return PARCEL_ERROR_NONE;
113 }
114
115 extern "C" EXPORT int parcel_write_uint16(parcel_h parcel, uint16_t val) {
116   if (parcel == nullptr) {
117     _E("Invalid parameter");
118     return PARCEL_ERROR_INVALID_PARAMETER;
119   }
120
121   auto* h = static_cast<Parcel*>(parcel);
122   h->WriteUInt16(val);
123   return PARCEL_ERROR_NONE;
124 }
125
126 extern "C" EXPORT int parcel_write_uint32(parcel_h parcel, uint32_t val) {
127   if (parcel == nullptr) {
128     _E("Invalid parameter");
129     return PARCEL_ERROR_INVALID_PARAMETER;
130   }
131
132   auto* h = static_cast<Parcel*>(parcel);
133   h->WriteUInt32(val);
134   return PARCEL_ERROR_NONE;
135 }
136
137 extern "C" EXPORT int parcel_write_uint64(parcel_h parcel, uint64_t val) {
138   if (parcel == nullptr) {
139     _E("Invalid parameter");
140     return PARCEL_ERROR_INVALID_PARAMETER;
141   }
142
143   auto* h = static_cast<Parcel*>(parcel);
144   h->WriteUInt64(val);
145   return PARCEL_ERROR_NONE;
146 }
147
148 extern "C" EXPORT int parcel_write_int16(parcel_h parcel, int16_t val) {
149   if (parcel == nullptr) {
150     _E("Invalid parameter");
151     return PARCEL_ERROR_INVALID_PARAMETER;
152   }
153
154   auto* h = static_cast<Parcel*>(parcel);
155   h->WriteInt16(val);
156   return PARCEL_ERROR_NONE;
157 }
158
159 extern "C" EXPORT int parcel_write_int32(parcel_h parcel, int32_t val) {
160   if (parcel == nullptr) {
161     _E("Invalid parameter");
162     return PARCEL_ERROR_INVALID_PARAMETER;
163   }
164
165   auto* h = static_cast<Parcel*>(parcel);
166   h->WriteInt32(val);
167   return PARCEL_ERROR_NONE;
168 }
169
170 extern "C" EXPORT int parcel_write_int64(parcel_h parcel, int64_t val) {
171   if (parcel == nullptr) {
172     _E("Invalid parameter");
173     return PARCEL_ERROR_INVALID_PARAMETER;
174   }
175
176   auto* h = static_cast<Parcel*>(parcel);
177   h->WriteInt64(val);
178   return PARCEL_ERROR_NONE;
179 }
180
181 extern "C" EXPORT int parcel_write_float(parcel_h parcel, float val) {
182   if (parcel == nullptr) {
183     _E("Invalid parameter");
184     return PARCEL_ERROR_INVALID_PARAMETER;
185   }
186
187   auto* h = static_cast<Parcel*>(parcel);
188   h->WriteFloat(val);
189   return PARCEL_ERROR_NONE;
190 }
191
192 extern "C" EXPORT int parcel_write_double(parcel_h parcel, double val) {
193   if (parcel == nullptr) {
194     _E("Invalid parameter");
195     return PARCEL_ERROR_INVALID_PARAMETER;
196   }
197
198   auto* h = static_cast<Parcel*>(parcel);
199   h->WriteDouble(val);
200   return PARCEL_ERROR_NONE;
201 }
202
203 extern "C" EXPORT int parcel_write_string(parcel_h parcel, const char* str) {
204   if (parcel == nullptr || str == nullptr) {
205     _E("Invalid parameter");
206     return PARCEL_ERROR_INVALID_PARAMETER;
207   }
208
209   auto* h = static_cast<Parcel*>(parcel);
210   h->WriteCString(str);
211   return PARCEL_ERROR_NONE;
212 }
213
214 extern "C" EXPORT int parcel_read_bool(parcel_h parcel, bool* val) {
215   if (parcel == nullptr || val == nullptr) {
216     _E("Invalid parameter");
217     return PARCEL_ERROR_INVALID_PARAMETER;
218   }
219
220   auto* h = static_cast<Parcel*>(parcel);
221   return h->ReadBool(val);
222 }
223
224 extern "C" EXPORT int parcel_read_byte(parcel_h parcel, char* val) {
225   if (parcel == nullptr || val == nullptr) {
226     _E("Invalid parameter");
227     return PARCEL_ERROR_INVALID_PARAMETER;
228   }
229
230   auto* h = static_cast<Parcel*>(parcel);
231   return h->ReadByte(val);
232 }
233
234 extern "C" EXPORT int parcel_read_uint16(parcel_h parcel, uint16_t* val) {
235   if (parcel == nullptr || val == nullptr) {
236     _E("Invalid parameter");
237     return PARCEL_ERROR_INVALID_PARAMETER;
238   }
239
240   auto* h = static_cast<Parcel*>(parcel);
241   return h->ReadUInt16(val);
242 }
243
244 extern "C" EXPORT int parcel_read_uint32(parcel_h parcel, uint32_t* val) {
245   if (parcel == nullptr || val == nullptr) {
246     _E("Invalid parameter");
247     return PARCEL_ERROR_INVALID_PARAMETER;
248   }
249
250   auto* h = static_cast<Parcel*>(parcel);
251   return h->ReadUInt32(val);
252 }
253
254 extern "C" EXPORT int parcel_read_uint64(parcel_h parcel, uint64_t* val) {
255   if (parcel == nullptr || val == nullptr) {
256     _E("Invalid parameter");
257     return PARCEL_ERROR_INVALID_PARAMETER;
258   }
259
260   auto* h = static_cast<Parcel*>(parcel);
261   return h->ReadUInt64(val);
262 }
263
264 extern "C" EXPORT int parcel_read_int16(parcel_h parcel, int16_t* val) {
265   if (parcel == nullptr || val == nullptr) {
266     _E("Invalid parameter");
267     return PARCEL_ERROR_INVALID_PARAMETER;
268   }
269
270   auto* h = static_cast<Parcel*>(parcel);
271   return h->ReadInt16(val);
272 }
273
274 extern "C" EXPORT int parcel_read_int32(parcel_h parcel, int32_t* val) {
275   if (parcel == nullptr || val == nullptr) {
276     _E("Invalid parameter");
277     return PARCEL_ERROR_INVALID_PARAMETER;
278   }
279
280   auto* h = static_cast<Parcel*>(parcel);
281   return h->ReadInt32(val);
282 }
283
284 extern "C" EXPORT int parcel_read_int64(parcel_h parcel, int64_t* val) {
285   if (parcel == nullptr || val == nullptr) {
286     _E("Invalid parameter");
287     return PARCEL_ERROR_INVALID_PARAMETER;
288   }
289
290   auto* h = static_cast<Parcel*>(parcel);
291   return h->ReadInt64(val);
292 }
293
294 extern "C" EXPORT int parcel_read_float(parcel_h parcel, float* val) {
295   if (parcel == nullptr || val == nullptr) {
296     _E("Invalid parameter");
297     return PARCEL_ERROR_INVALID_PARAMETER;
298   }
299
300   auto* h = static_cast<Parcel*>(parcel);
301   return h->ReadFloat(val);
302 }
303
304 extern "C" EXPORT int parcel_read_double(parcel_h parcel, double* val) {
305   if (parcel == nullptr || val == nullptr) {
306     _E("Invalid parameter");
307     return PARCEL_ERROR_INVALID_PARAMETER;
308   }
309
310   auto* h = static_cast<Parcel*>(parcel);
311   return h->ReadDouble(val);
312 }
313
314 extern "C" EXPORT int parcel_read_string(parcel_h parcel, char** str) {
315   if (parcel == nullptr || str == nullptr) {
316     _E("Invalid parameter");
317     return PARCEL_ERROR_INVALID_PARAMETER;
318   }
319
320   auto* h = static_cast<Parcel*>(parcel);
321   return h->ReadCString(str);
322 }
323
324 extern "C" EXPORT int parcel_reset_reader(parcel_h parcel) {
325   if (parcel == nullptr) {
326     _E("Invalid parameter");
327     return PARCEL_ERROR_INVALID_PARAMETER;
328   }
329
330   auto* h = static_cast<Parcel*>(parcel);
331   h->ResetReader();
332   return PARCEL_ERROR_NONE;
333 }
334
335 extern "C" EXPORT int parcel_clear(parcel_h parcel) {
336   if (parcel == nullptr) {
337     _E("Invalid parameter");
338     return PARCEL_ERROR_INVALID_PARAMETER;
339   }
340
341   auto* h = static_cast<Parcel*>(parcel);
342   h->Clear();
343   return PARCEL_ERROR_NONE;
344 }
345
346 extern "C" EXPORT int parcel_reset(parcel_h parcel, const void* buf,
347     uint32_t size) {
348   if (parcel == nullptr || buf == nullptr || size == 0) {
349     _E("Invalid parameter");
350     return PARCEL_ERROR_INVALID_PARAMETER;
351   }
352
353   auto* h = static_cast<Parcel*>(parcel);
354   h->Reset(buf, size);
355   return PARCEL_ERROR_NONE;
356 }
357
358 extern "C" EXPORT int parcel_write(parcel_h parcel, parcelable_t* parcelable,
359     void* data) {
360   if (parcel == nullptr || parcelable == nullptr || parcelable->to == nullptr) {
361     _E("Invalid parameter");
362     return PARCEL_ERROR_INVALID_PARAMETER;
363   }
364
365   parcelable->to(parcel, data);
366   return PARCEL_ERROR_NONE;
367 }
368
369 extern "C" EXPORT int parcel_read(parcel_h parcel, parcelable_t* parcelable,
370     void* data) {
371   if (parcel == nullptr || parcelable == nullptr ||
372       parcelable->from == nullptr) {
373     _E("Invalid parameter");
374     return PARCEL_ERROR_INVALID_PARAMETER;
375   }
376
377   parcelable->from(parcel, data);
378   return PARCEL_ERROR_NONE;
379 }
380
381 extern "C" EXPORT int parcel_get_raw(parcel_h parcel, void** raw,
382     uint32_t* size) {
383   if (parcel == nullptr || raw == nullptr || size == nullptr) {
384     _E("Invalid parameter");
385     return PARCEL_ERROR_INVALID_PARAMETER;
386   }
387
388   auto* h = static_cast<Parcel*>(parcel);
389   auto& raw_data = h->GetRaw();
390   *raw = reinterpret_cast<void*>(const_cast<uint8_t*>(&raw_data[0]));
391   *size = raw_data.size();
392   return PARCEL_ERROR_NONE;
393 }
394
395 extern "C" EXPORT int parcel_set_byte_order(parcel_h parcel,
396     bool big_endian) {
397   if (parcel == nullptr) {
398     _E("Invalid parameter");
399     return PARCEL_ERROR_INVALID_PARAMETER;
400   }
401
402   auto* h = static_cast<Parcel*>(parcel);
403   h->SetByteOrder(big_endian);
404   return PARCEL_ERROR_NONE;
405 }