• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef IPC_C_PARCEL_H
17 #define IPC_C_PARCEL_H
18 
19 #include <stdbool.h>
20 #include <stddef.h>
21 #include <stdint.h>
22 #include "c_ashmem.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct MessageParcelHolder;
29 typedef struct MessageParcelHolder CParcel;
30 
31 struct CRemoteObjectHolder;
32 typedef struct CRemoteObjectHolder CRemoteObject;
33 
34 typedef bool (*OnCParcelBytesAllocator)(void *stringData, char **buffer, int32_t len);
35 typedef bool (*OnCParcelBytesAllocator16)(void *stringData, int16_t **buffer, int32_t len);
36 typedef bool (*OnCParcelBoolAllocator)(void *value, bool **buffer, int32_t len);
37 typedef bool (*OnCParcelInt8Allocator)(void *value, int8_t **buffer, int32_t len);
38 typedef bool (*OnCParcelInt16Allocator)(void *value, int16_t **buffer, int32_t len);
39 typedef bool (*OnCParcelInt32Allocator)(void *value, int32_t **buffer, int32_t len);
40 typedef bool (*OnCParcelInt64Allocator)(void *value, int64_t **buffer, int32_t len);
41 typedef bool (*OnCParcelFloatAllocator)(void *value, float **buffer, int32_t len);
42 typedef bool (*OnCParcelDoubleAllocator)(void *value, double **buffer, int32_t len);
43 typedef bool (*OnCParcelAllocator)(void *value, int32_t len);
44 typedef bool (*OnStringArrayWrite)(const void *array, const void *value, uint32_t len);
45 typedef bool (*OnString16ArrayWrite)(const void *array, const void *value, uint32_t len);
46 typedef bool (*OnStringArrayRead)(const void *array, const void *value, uint32_t len);
47 typedef bool (*OnString16ArrayRead)(const void *array, const void *value, uint32_t len);
48 typedef bool (*OnCParcelWriteElement)(CParcel *value, const void *arr, unsigned long index);
49 typedef bool (*OnCParcelReadElement)(const CParcel *value, void *arr, unsigned long index);
50 
51 CParcel *CParcelObtain(void);
52 void CParcelIncStrongRef(CParcel *parcel);
53 void CParcelDecStrongRef(CParcel *parcel);
54 
55 bool CParcelWriteBool(CParcel *parcel, bool value);
56 bool CParcelReadBool(const CParcel *parcel, bool *value);
57 bool CParcelWriteInt8(CParcel *parcel, int8_t value);
58 bool CParcelReadInt8(const CParcel *parcel, int8_t *value);
59 bool CParcelWriteInt16(CParcel *parcel, int16_t value);
60 bool CParcelReadInt16(const CParcel *parcel, int16_t *value);
61 bool CParcelWriteInt32(CParcel *parcel, int32_t value);
62 bool CParcelReadInt32(const CParcel *parcel, int32_t *value);
63 bool CParcelWriteInt64(CParcel *parcel, int64_t value);
64 bool CParcelReadInt64(const CParcel *parcel, int64_t *value);
65 bool CParcelWriteFloat(CParcel *parcel, float value);
66 bool CParcelReadFloat(const CParcel *parcel, float *value);
67 bool CParcelWriteDouble(CParcel *parcel, double value);
68 bool CParcelReadDouble(const CParcel *parcel, double *value);
69 bool CParcelWriteString(CParcel *parcel, const char *stringData, int32_t length);
70 bool CParcelReadString(const CParcel *parcel, void *stringData, OnCParcelBytesAllocator allocator);
71 bool CParcelWriteString16(CParcel *parcel, const char *str, int32_t strLen);
72 bool CParcelReadString16(const CParcel *parcel, void *stringData, OnCParcelBytesAllocator allocator);
73 bool CParcelWriteInterfaceToken(CParcel *parcel, const char *token, int32_t tokenLen);
74 bool CParcelReadInterfaceToken(const CParcel *parcel, void *token, OnCParcelBytesAllocator allocator);
75 bool CParcelWriteRemoteObject(CParcel *parcel, const CRemoteObject *object);
76 CRemoteObject *CParcelReadRemoteObject(const CParcel *parcel);
77 bool CParcelWriteFileDescriptor(CParcel *parcel, int32_t fd);
78 bool CParcelReadFileDescriptor(const CParcel *parcel, int32_t *fd);
79 bool CParcelWriteBuffer(CParcel *parcel, const uint8_t *buffer, uint32_t len);
80 bool CParcelReadBuffer(const CParcel *parcel, uint8_t *value, uint32_t len);
81 bool CParcelWriteRawData(CParcel *parcel, const uint8_t *buffer, uint32_t len);
82 const uint8_t *CParcelReadRawData(const CParcel *parcel, uint32_t len);
83 
84 bool CParcelWriteBoolArray(CParcel *parcel, const bool *array, int32_t len);
85 bool CParcelReadBoolArray(const CParcel *parcel, void *value, OnCParcelBoolAllocator allocator);
86 bool CParcelWriteInt8Array(CParcel *parcel, const int8_t *array, int32_t len);
87 bool CParcelReadInt8Array(const CParcel *parcel, void *value, OnCParcelInt8Allocator allocator);
88 bool CParcelWriteInt16Array(CParcel *parcel, const int16_t *array, int32_t len);
89 bool CParcelReadInt16Array(const CParcel *parcel, void *value, OnCParcelInt16Allocator allocator);
90 bool CParcelWriteInt32Array(CParcel *parcel, const int32_t *array, int32_t len);
91 bool CParcelReadInt32Array(const CParcel *parcel, void *value, OnCParcelInt32Allocator allocator);
92 bool CParcelWriteInt64Array(CParcel *parcel, const int64_t *array, int32_t len);
93 bool CParcelReadInt64Array(const CParcel *parcel, void *value, OnCParcelInt64Allocator allocator);
94 bool CParcelWriteFloatArray(CParcel *parcel, const float *array, int32_t len);
95 bool CParcelReadFloatArray(const CParcel *parcel, void *value, OnCParcelFloatAllocator allocator);
96 bool CParcelWriteDoubleArray(CParcel *parcel, const double *array, int32_t len);
97 bool CParcelReadDoubleArray(const CParcel *parcel, void *value, OnCParcelDoubleAllocator allocator);
98 bool CParcelWriteStringArray(CParcel *parcel, const void *value,
99     int32_t len, OnStringArrayWrite writer);
100 bool CParcelWriteString16Array(CParcel *parcel, const void *value,
101     int32_t len, OnString16ArrayWrite writer);
102 bool CParcelWriteStringElement(void *data, const char *value, int32_t len);
103 bool CParcelWritU16stringElement(void *data, const char *value, int32_t len);
104 
105 bool CParcelReadStringArray(const CParcel *parcel, void *value, OnStringArrayRead reader);
106 bool CParcelReadString16Array(const CParcel *parcel, void *value, OnString16ArrayRead reader);
107 bool CParcelReadStringElement(uint32_t index, const void *data, void *value,
108     OnCParcelBytesAllocator allocator);
109 bool CParcelReadString16Element(uint32_t index, const void *data, void *value,
110     OnCParcelBytesAllocator16 allocator);
111 
112 bool CParcelWriteParcelableArray(CParcel *parcel, const void *value, int32_t len,
113     OnCParcelWriteElement elementWriter);
114 bool CParcelReadParcelableArray(const CParcel *parcel, void *value,
115     OnCParcelAllocator allocator, OnCParcelReadElement elementReader);
116 
117 uint32_t CParcelGetDataSize(const CParcel *parcel);
118 bool CParcelSetDataSize(CParcel *parcel, uint32_t new_size);
119 uint32_t CParcelGetDataCapacity(const CParcel *parcel);
120 bool CParcelSetDataCapacity(CParcel *parcel, uint32_t new_size);
121 uint32_t CParcelGetMaxCapacity(const CParcel *parcel);
122 bool CParcelSetMaxCapacity(CParcel *parcel, uint32_t new_size);
123 uint32_t CParcelGetWritableBytes(const CParcel *parcel);
124 uint32_t CParcelGetReadableBytes(const CParcel *parcel);
125 uint32_t CParcelGetReadPosition(const CParcel *parcel);
126 uint32_t CParcelGetWritePosition(const CParcel *parcel);
127 bool CParcelRewindRead(CParcel *parcel, uint32_t new_pos);
128 bool CParcelRewindWrite(CParcel *parcel, uint32_t new_pos);
129 bool CParcelWriteAshmem(CParcel *parcel, CAshmem *ashmem);
130 CAshmem *CParcelReadAshmem(const CParcel *parcel);
131 
132 bool CParcelContainFileDescriptors(const CParcel *parcel);
133 size_t CParcelGetRawDataSize(const CParcel *parcel);
134 size_t CParcelGetRawDataCapacity(const CParcel *parcel);
135 void CParcelClearFileDescriptor(CParcel *parcel);
136 void CParcelSetClearFdFlag(CParcel *parcel);
137 bool CParcelAppend(CParcel *parcel, CParcel *data);
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 #endif /* IPC_C_PARCEL_H */
143