1 // Copyright (C) 2021 The Android Open Source Project
2 //
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 #pragma once
16 
17 #include <random>
18 #include <string>
19 
20 #include <ditto/instruction.h>
21 
22 namespace dittosuite {
23 
24 class OpenFile : public Instruction {
25  public:
26   inline static const std::string kName = "open_file";
27   enum class AccessMode { kReadOnly, kWriteOnly, kReadWrite };
28 
29   explicit OpenFile(const Params& params, const std::string& path_name, bool create, bool direct_io,
30                     int output_fd_key, AccessMode access_mode);
31   explicit OpenFile(const Params& params, int input_key, bool create, bool direct_io,
32                     int output_fd_key, AccessMode access_mode);
33   explicit OpenFile(const Params& params, bool create, bool direct_io, int output_fd_key,
34                     AccessMode access_mode);
35 
36  private:
37   void SetUpSingle() override;
38   void RunSingle() override;
39 
40   bool random_name_;
41   std::string path_name_;
42   bool create_;
43   bool direct_io_;
44   int input_key_;
45   int output_fd_key_;
46   std::mt19937_64 gen_;
47   AccessMode access_mode_;
48 };
49 
50 }  // namespace dittosuite
51