• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 MESSAGE_PARCEL_WARP_H
17 #define MESSAGE_PARCEL_WARP_H
18 
19 #include "api/visibility.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace MiscServices {
24 
25 constexpr int64_t DEFAULT_MAX_RAW_DATA_SIZE = 128 * 1024 * 1024; // 128M
26 
27 class API_EXPORT MessageParcelWarp {
28 public:
29     MessageParcelWarp();
30     ~MessageParcelWarp();
31 
32     bool WriteRawData(MessageParcel &parcelPata, const void *data, size_t size);
33     const void *ReadRawData(MessageParcel &parcelData, size_t size);
GetRawDataSize()34     inline int64_t GetRawDataSize()
35     {
36         return maxRawDataSize_;
37     }
38     int CreateTmpFd();
39     int GetWriteDataFd();
40     bool MemcpyData(void *ptr, size_t size, const void *data, size_t count);
41 
42 private:
43     std::shared_ptr<char> rawData_ = nullptr;
44     int writeRawDataFd_ = -1;
45     int readRawDataFd_ = -1;
46     void *kernelMappedWrite_ = nullptr;
47     void *kernelMappedRead_ = nullptr;
48     size_t rawDataSize_ = 0;
49     bool canWrite_ = true;
50     bool canRead_ = true;
51     int64_t maxRawDataSize_ = DEFAULT_MAX_RAW_DATA_SIZE;
52 };
53 } // namespace MiscServices
54 } // namespace OHOS
55 #endif // MESSAGE_PARCEL_WARP_H