nlib
JsonRpcClient.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_MSGPACK_JSONRPC_JSONRPCCLIENT_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_JSONRPC_JSONRPCCLIENT_H_
18 
19 #include "nn/nlib/Config.h"
20 #include "nn/nlib/Swap.h"
21 #include "nn/nlib/UniquePtr.h"
23 
24 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
25 #undef NLIB_VIS_PUBLIC
26 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
27 #endif
28 
29 NLIB_NAMESPACE_BEGIN
30 namespace msgpack {
31 namespace jsonrpc {
32 typedef uint32_t reqid_t;
33 
34 class JsonRpcResponseHandler;
35 class JsonRpcResponse;
36 
38  public:
39  static JsonRpcClient OpenClient(const char* name);
40  static JsonRpcClient SearchClient(const char* name);
41  static void CloseClient(const JsonRpcClient& client);
42  static void Shutdown();
43 
44  public:
45  typedef void (*NoTargetResponseHandler)(UniquePtr<JsonRpcResponse>& rhs) NLIB_NOEXCEPT_FUNCPTR; // NOLINT
47  JsonRpcClient(JsonRpcClient& rhs, move_tag) NLIB_NOEXCEPT : handle_(rhs.handle_) {}
49  handle_ = rhs.handle_;
50  return *this;
51  }
52  NLIB_DEPRECATED void swap(JsonRpcClient& rhs) { // NOLINT
53  using std::swap;
54  swap(handle_, rhs.handle_);
55  }
56 
57  public:
58  reqid_t GenerateId();
59 
60  // future becomes valid after response or timeout
61  typedef ::nlib_ns::threading::Future<UniquePtr<JsonRpcResponse> > FutureType;
62  errno_t GetFutureForId(FutureType* future, reqid_t reqid);
63  errno_t ResolveResponse(const void* buf, size_t nbytes);
64  errno_t Abort(reqid_t reqid);
65  errno_t SetNoTargetResponseHandler(NoTargetResponseHandler handler);
66 
67  bool operator==(const JsonRpcClient& rhs) const { return handle_ == rhs.handle_; }
68  bool operator!=(const JsonRpcClient& rhs) const { return handle_ != rhs.handle_; }
69  NLIB_SAFE_BOOL(JsonRpcClient, handle_ != 0);
70 
71  private:
72  explicit NLIB_VIS_HIDDEN JsonRpcClient(uint32_t handle) : handle_(handle) {}
73 
74  private:
75  uint32_t handle_;
76  friend class JsonRpcClientImpl;
77 };
78 
79 } // namespace jsonrpc
80 } // namespace msgpack
81 NLIB_NAMESPACE_END
82 
83 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::jsonrpc::JsonRpcClient)
84 
85 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
86 #undef NLIB_VIS_PUBLIC
87 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
88 #endif
89 
90 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONRPC_JSONRPCCLIENT_H_
void swap(JsonRpcClient &rhs)
スワップです。
Definition: JsonRpcClient.h:52
JSON-RPCのレスポンスを表すクラスです。
bool operator==(const JsonRpcClient &rhs) const
クライアントが同一の場合にtrueを返します。
Definition: JsonRpcClient.h:67
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:194
bool operator!=(const JsonRpcClient &rhs) const
クライアントが同一の場合にfalseを返します。
Definition: JsonRpcClient.h:68
UniquePtrはポインタの所有権を保持し、UniquePtrがスコープから出るときにデストラクタでポインタをDELで指...
Definition: UniquePtr.h:109
std::unique_ptrに相当するクラスが定義されています。
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:88
#define NLIB_DEPRECATED
関数等がdeprecatedになったことを示します。
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
::nlib_ns::threading::Future< UniquePtr< JsonRpcResponse > > FutureType
それぞれにリクエストに対して割り当てられる、レスポンス(又はタイムアウト)があるとセットされるfutureの...
Definition: JsonRpcClient.h:61
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:265
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
開発環境別の設定が書かれるファイルです。
uint32_t reqid_t
JSON-RPCのリクエストに付与されるidの型です。
Definition: JsonRpcClient.h:32
JSON-RPCのクライアント側の管理を行うクラスです。
Definition: JsonRpcClient.h:37
マルチスレッドプログラミングのためのFutureパターンを実装しています。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
constexpr JsonRpcClient() noexcept
デフォルトコンストラクタです。
Definition: JsonRpcClient.h:46
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37