1 +
//
 
2 +
// Copyright (c) 2026 Michael Vandeberg
 
3 +
//
 
4 +
// Distributed under the Boost Software License, Version 1.0. (See accompanying
 
5 +
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
6 +
//
 
7 +
// Official repository: https://github.com/cppalliance/corosio
 
8 +
//
 
9 +

 
10 +
#ifndef BOOST_COROSIO_DETAIL_FILE_SERVICE_HPP
 
11 +
#define BOOST_COROSIO_DETAIL_FILE_SERVICE_HPP
 
12 +

 
13 +
#include <boost/corosio/detail/config.hpp>
 
14 +
#include <boost/corosio/stream_file.hpp>
 
15 +
#include <boost/capy/ex/execution_context.hpp>
 
16 +

 
17 +
#include <filesystem>
 
18 +
#include <system_error>
 
19 +

 
20 +
namespace boost::corosio::detail {
 
21 +

 
22 +
/** Abstract stream file service base class.
 
23 +

 
24 +
    Concrete implementations (posix, IOCP) inherit from
 
25 +
    this class and provide platform-specific file operations.
 
26 +
    The context constructor installs whichever backend via
 
27 +
    `make_service`, and `stream_file.cpp` retrieves it via
 
28 +
    `use_service<file_service>()`.
 
29 +
*/
 
30 +
class BOOST_COROSIO_DECL file_service
 
31 +
    : public capy::execution_context::service
 
32 +
    , public io_object::io_service
 
33 +
{
 
34 +
public:
 
35 +
    /// Identifies this service for `execution_context` lookup.
 
36 +
    using key_type = file_service;
 
37 +

 
38 +
    /** Open a file.
 
39 +

 
40 +
        Opens the file at the given path with the specified flags
 
41 +
        and associates it with the platform I/O mechanism.
 
42 +

 
43 +
        @param impl The file implementation to initialize.
 
44 +
        @param path The filesystem path to open.
 
45 +
        @param mode Bitmask of file_base::flags.
 
46 +
        @return Error code on failure, empty on success.
 
47 +
    */
 
48 +
    virtual std::error_code open_file(
 
49 +
        stream_file::implementation& impl,
 
50 +
        std::filesystem::path const& path,
 
51 +
        file_base::flags mode) = 0;
 
52 +

 
53 +
protected:
 
54 +
    file_service() = default;
 
55 +
    ~file_service() override = default;
 
56 +
};
 
57 +

 
58 +
} // namespace boost::corosio::detail
 
59 +

 
60 +
#endif // BOOST_COROSIO_DETAIL_FILE_SERVICE_HPP