nlib
AsyncFileIo.h
[詳解]
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
コンパイラに関数をインライン展開するように強く示します。
Definition: Platform_unix.h:97
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
#define NLIB_FD_O_CREAT
nlib_fd_open()のflags 引数で使われます。
Definition: Platform.h:1501
#define NLIB_CHECK_RESULT
関数の呼び出し元が戻り値をチェックする必要があることを示します。
非同期ファイルI/Oを管理するためのクラスです。
Definition: AsyncFileIo.h:64
nlib_fd GetFd() const noexcept
nlib_fdを取得します。
Definition: AsyncFileIo.h:46
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
bool Write(BinaryWriter *w, T x)
この関数テンプレートを特殊化することで、ユーザー定義クラスを書きこむことができます。 ...
Definition: BinaryWriter.h:136
#define NLIB_FD_O_WRONLY
nlib_fd_open()のflags 引数で使われます。
Definition: Platform.h:1480
int nlib_fd
(nlib独自の)ファイルディスクリプタで、32bit整数です。
Definition: Platform.h:1536
#define NLIB_FD_O_TRUNC
nlib_fd_open()のflags 引数で使われます。
Definition: Platform.h:1508
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
開発環境別の設定が書かれるファイルです。
別のスレッド実行の出力をスレッドセーフに取得するためのクラスです。C++11のstd::shared_futureに似ていま...
Definition: AsyncFileIo.h:26
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
bool Read(BinaryReader *r, T *x)
この関数テンプレートを特殊化することで、ユーザー定義クラスに読み込むことができます。 ...
Definition: BinaryReader.h:172
int64_t nlib_offset
ファイルへのオフセットです。64bit整数です。
Definition: Platform.h:1535
非同期ファイルI/Oをラップしたクラスです。
Definition: AsyncFileIo.h:28
AsyncFileIoService() noexcept
コンストラクタです。
Definition: AsyncFileIo.h:66
#define NLIB_FD_O_RDONLY
nlib_fd_open()のflags 引数で使われます。
Definition: Platform.h:1473
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37