nlib
AsyncFileIo.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
17 #define INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 namespace threading {
23 
24 class AsyncFileIoService;
25 template <class R>
26 class Future;
27 
29  public:
30  enum Mode {
31  kAsyncFileIoRead = NLIB_FD_O_RDONLY,
32  kAsyncFileIoWrite = NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC,
33  ASYNCFILEIO_READ = kAsyncFileIoRead,
34  ASYNCFILEIO_WRITE = kAsyncFileIoWrite
35  };
36  static bool HasNativeAsyncFileIo() NLIB_NOEXCEPT;
39  errno_t Init() NLIB_NOEXCEPT;
40  NLIB_CHECK_RESULT errno_t Open(const char* path,
41  int flags, int mode) NLIB_NOEXCEPT;
42  NLIB_CHECK_RESULT errno_t Open(const char* path, int flags) NLIB_NOEXCEPT {
43  return Open(path, flags, 0644);
44  }
46  NLIB_ALWAYS_INLINE nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
47  errno_t Close() NLIB_NOEXCEPT;
48  errno_t Read(Future<size_t>* future, void* buf, size_t nbytes, nlib_offset ofs,
50  errno_t Read(size_t* read_bytes, void* buf, size_t nbytes, nlib_offset ofs,
52  errno_t Write(Future<size_t>* future, const void* buf, size_t nbytes, nlib_offset ofs,
54  errno_t Write(size_t* write_bytes, const void* buf, size_t nbytes, nlib_offset ofs,
56  errno_t Cancel(AsyncFileIoService* ioservice) NLIB_NOEXCEPT;
57 
58  private:
59  nlib_fd fd_;
61 };
62 
63 struct AsyncFileIoServiceData;
65  public:
66  AsyncFileIoService() NLIB_NOEXCEPT : data_(NULL) {}
68  errno_t Init() NLIB_NOEXCEPT;
69 
70  private:
71  AsyncFileIoServiceData* data_;
73  friend class AsyncFileIo;
74 };
75 
76 } // namespace threading
77 NLIB_NAMESPACE_END
78 
79 #endif // INCLUDE_NN_NLIB_THREADING_ASYNCFILEIO_H_
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:97
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:179
#define NLIB_FD_O_CREAT
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1501
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
Class that controls asynchronous file I/O.
Definition: AsyncFileIo.h:64
nlib_fd GetFd() const noexcept
Gets nlib_fd.
Definition: AsyncFileIo.h:46
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
bool Write(BinaryWriter *w, T x)
You can write user-defined class objects by specializing this function template.
Definition: BinaryWriter.h:136
#define NLIB_FD_O_WRONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1480
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1536
#define NLIB_FD_O_TRUNC
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1508
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
A file that contains the configuration information for each development environment.
Class that gets the output of a different thread executing in a thread safe manner. This class is similar to the std::shared_future class of C++11.
Definition: AsyncFileIo.h:26
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.
Definition: BinaryReader.h:172
int64_t nlib_offset
The offset to the file. A 64-bit integer.
Definition: Platform.h:1535
Class that wraps asynchronous file I/O.
Definition: AsyncFileIo.h:28
AsyncFileIoService() noexcept
Instantiates the object.
Definition: AsyncFileIo.h:66
#define NLIB_FD_O_RDONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1473
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37