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 OHOS_FILE_FS_RANDOMACCESSFILE_IMPL_H
17 #define OHOS_FILE_FS_RANDOMACCESSFILE_IMPL_H
18 
19 #include "utils.h"
20 #include "uni_error.h"
21 #include "ffi_remote_data.h"
22 #include "cj_common_ffi.h"
23 #include "randomaccessfile_entity.h"
24 
25 #include <cstdint>
26 #include <string>
27 
28 namespace OHOS {
29 namespace CJSystemapi {
30 class RandomAccessFileImpl : public OHOS::FFI::FFIData {
31 public:
32     explicit RandomAccessFileImpl(std::shared_ptr<OHOS::FileManagement::ModuleFileIO::RandomAccessFileEntity> entity);
33     int32_t GetFd();
34     int64_t GetFPointer();
35     void SetFilePointerSync(int64_t fp);
36     void CloseSync();
37     std::tuple<int32_t, int64_t> WriteSync(char* buf, size_t len, int64_t offset);
38     std::tuple<int32_t, int64_t> ReadSync(char* buf, size_t len, int64_t offset);
39 
GetRuntimeType()40     OHOS::FFI::RuntimeType* GetRuntimeType() override { return GetClassType(); }
41 private:
42     std::shared_ptr<OHOS::FileManagement::ModuleFileIO::RandomAccessFileEntity> entity_;
43 
44     friend class OHOS::FFI::RuntimeType;
45     friend class OHOS::FFI::TypeBase;
GetClassType()46     static OHOS::FFI::RuntimeType* GetClassType()
47     {
48         static OHOS::FFI::RuntimeType runtimeType =
49             OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("RandomAccessFileImpl");
50         return &runtimeType;
51     }
52 };
53 } // OHOS::FileManagement::ModuleFileIO
54 }
55 
56 #endif // OHOS_FILE_FS_IMPL_H