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;
47  JsonRpcClient(JsonRpcClient& rhs, move_tag) NLIB_NOEXCEPT : handle_(rhs.handle_) {}
48  JsonRpcClient& assign(JsonRpcClient& rhs, move_tag) NLIB_NOEXCEPT {
49  handle_ = rhs.handle_;
50  return *this;
51  }
52 
53  public:
54  reqid_t GenerateId();
55 
56  // future becomes valid after response or timeout
57  typedef ::nlib_ns::threading::Future<UniquePtr<JsonRpcResponse> > FutureType;
58  errno_t GetFutureForId(FutureType* future, reqid_t reqid);
59  errno_t ResolveResponse(const void* buf, size_t nbytes);
60  errno_t Abort(reqid_t reqid);
61  errno_t SetNoTargetResponseHandler(NoTargetResponseHandler handler);
62 
63  bool operator==(const JsonRpcClient& rhs) const { return handle_ == rhs.handle_; }
64  bool operator!=(const JsonRpcClient& rhs) const { return handle_ != rhs.handle_; }
65  NLIB_SAFE_BOOL(JsonRpcClient, handle_ != 0);
66 
67  private:
68  explicit NLIB_VIS_HIDDEN JsonRpcClient(uint32_t handle) : handle_(handle) {}
69 
70  private:
71  uint32_t handle_;
72  friend class JsonRpcClientImpl;
73 };
74 
75 } // namespace jsonrpc
76 } // namespace msgpack
77 NLIB_NAMESPACE_END
78 
79 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::jsonrpc::JsonRpcClient)
80 
81 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
82 #undef NLIB_VIS_PUBLIC
83 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
84 #endif
85 
86 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONRPC_JSONRPCCLIENT_H_
JSON-RPCのレスポンスを表すクラスです。
bool operator==(const JsonRpcClient &rhs) const
クライアントが同一の場合にtrueを返します。
Definition: JsonRpcClient.h:63
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:199
bool operator!=(const JsonRpcClient &rhs) const
クライアントが同一の場合にfalseを返します。
Definition: JsonRpcClient.h:64
C++11環境(エイリアステンプレートが可能な環境)においてはstd::unique_ptrにエイリアステンプレートされま...
Definition: UniquePtr.h:108
std::unique_ptrに相当するクラスが定義されています。
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:86
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
::nlib_ns::threading::Future< UniquePtr< JsonRpcResponse > > FutureType
それぞれにリクエストに対して割り当てられる、レスポンス(又はタイムアウト)があるとセットされるfutureの...
Definition: JsonRpcClient.h:57
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:270
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
開発環境別の設定が書かれるファイルです。
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:250
constexpr JsonRpcClient() noexcept
デフォルトコンストラクタです。
Definition: JsonRpcClient.h:46
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37