1 /*
2  * Copyright (c) 2024 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 DUMP_BUFFER_WRAP_H
17 #define DUMP_BUFFER_WRAP_H
18 
19 #include "dump_buffer_manager.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace MediaMonitor {
24 
25 using BufferNewFunc = DumpBuffer *(*)();
26 using BufferCreateFunc = DumpBuffer *(*)(int32_t capacity);
27 using BufferDestroyFunc = void (*)(DumpBuffer *buffer);
28 using BufferGetAddrFunc = uint8_t *(*)(DumpBuffer *buffer);
29 using BufferGetCapacityFunc = int32_t (*)(DumpBuffer *buffer);
30 using BufferGetSizeFunc = int32_t (*)(DumpBuffer *buffer);
31 using BufferSetSizeFunc = bool (*)(DumpBuffer *buffer, int32_t size);
32 using BufferGetUniIdFunc = uint64_t (*)(DumpBuffer *buffer);
33 using BufferWriteFunc = int32_t (*)(DumpBuffer *buffer, const uint8_t *in, int32_t writeSize);
34 using BufferReadFromParcelFunc = bool (*)(DumpBuffer *buffer, void *parcel);
35 using BufferWriteToParcelFunc = bool (*)(DumpBuffer *buffer, void *parcel);
36 
37 class DumpBufferWrap {
38 public:
39     DumpBufferWrap();
40     ~DumpBufferWrap();
41     bool Open();
42     void Close();
43     DumpBuffer *NewDumpBuffer();
44     DumpBuffer *CreateDumpBuffer(int32_t capacity);
45     void DestroyDumpBuffer(DumpBuffer *buffer);
46     uint8_t *GetAddr(DumpBuffer *buffer);
47     int32_t GetCapacity(DumpBuffer *buffer);
48     int32_t GetSize(DumpBuffer *buffer);
49     int32_t Write(DumpBuffer *buffer, const uint8_t *in, int32_t writeSize);
50     uint64_t GetUniqueId(DumpBuffer *buffer);
51     bool SetSize(DumpBuffer *buffer, int32_t size);
52     bool ReadFromParcel(DumpBuffer *buffer, void *parcel);
53     bool WriteToParcel(DumpBuffer *buffer, void *parcel);
54 private:
55     void *handler = nullptr;
56     BufferNewFunc newFunc = nullptr;
57     BufferCreateFunc createFunc = nullptr;
58     BufferDestroyFunc destroyFunc = nullptr;
59     BufferGetAddrFunc getAddrFunc = nullptr;
60     BufferSetSizeFunc setSizeFunc = nullptr;
61     BufferGetSizeFunc getSizeFunc = nullptr;
62     BufferGetUniIdFunc getIdFunc = nullptr;
63     BufferWriteFunc writeFunc = nullptr;
64     BufferGetCapacityFunc getCapacityFunc = nullptr;
65     BufferReadFromParcelFunc readFromParcel = nullptr;
66     BufferWriteToParcelFunc writeToParcel = nullptr;
67 };
68 } // namespace MediaMonitor
69 } // namespace Media
70 } // namespace OHOS
71 #endif // DUMP_BUFFER_WRAP_H