• 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 OHOS_FILE_FS_STREAM_IMPL_H
17 #define OHOS_FILE_FS_STREAM_IMPL_H
18 
19 #include "ffi_remote_data.h"
20 #include "cj_common_ffi.h"
21 #include "macro.h"
22 #include "uni_error.h"
23 
24 namespace OHOS {
25 namespace CJSystemapi {
26 namespace FileFs {
27 
28 std::tuple<int, std::unique_ptr<char[]>, size_t, int64_t> GetReadArg(size_t bufLen, int64_t length, int64_t offset);
29 
30 class StreamImpl : public OHOS::FFI::FFIData {
31 public:
StreamImpl(std::unique_ptr<FILE,decltype (& fclose)> fp)32     explicit StreamImpl(std::unique_ptr<FILE, decltype(&fclose)> fp) : fp_(std::move(fp)) {}
33 
34     int Close();
35 
36     int Flush();
37 
38     std::tuple<int, int64_t> ReadCur(uint8_t* buffer, size_t buLen, int64_t length);
39 
40     std::tuple<int, int64_t> Read(uint8_t* buffer, size_t buLen, int64_t length, int64_t offset);
41 
42     std::tuple<int, int64_t> WriteCur(void* buffer, int64_t length, const std::string& encode);
43 
44     std::tuple<int, int64_t> Write(void* buffer, int64_t length, int64_t offset, const std::string& encode);
45 
GetRuntimeType()46     OHOS::FFI::RuntimeType* GetRuntimeType() override { return GetClassType(); }
47 
GetRealFp()48     std::unique_ptr<FILE, decltype(&fclose)> GetRealFp() { return std::move(fp_); }
49 
50 private:
51     std::unique_ptr<FILE, decltype(&fclose)> fp_;
52 
53     friend class OHOS::FFI::RuntimeType;
54     friend class OHOS::FFI::TypeBase;
GetClassType()55     static OHOS::FFI::RuntimeType* GetClassType()
56     {
57         static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("StreamImpl");
58         return &runtimeType;
59     }
60 };
61 
62 }
63 }
64 }
65 #endif // OHOS_FILE_FS_STREAM_IMPL_H