nlib
JsonRpcClient.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_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
46  JsonRpcClient() : handle_(0) {}
47  JsonRpcClient(const JsonRpcClient& rhs) : handle_(rhs.handle_) {}
49  handle_ = rhs.handle_;
50  return *this;
51  }
52  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_
JsonRpcClient(const JsonRpcClient &rhs)
Copy constructor.
Definition: JsonRpcClient.h:47
void swap(JsonRpcClient &rhs)
A swap.
Definition: JsonRpcClient.h:52
Class for representing the JSON-RPC response.
bool operator==(const JsonRpcClient &rhs) const
Returns true if the client is the same.
Definition: JsonRpcClient.h:67
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:178
bool operator!=(const JsonRpcClient &rhs) const
Returns false if the client is the same.
Definition: JsonRpcClient.h:68
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Definition: UniquePtr.h:109
Defines that class that is corresponding to std::unique_ptr.
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:88
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
::nlib_ns::threading::Future< UniquePtr< JsonRpcResponse > > FutureType
A future type set when a response (or timeout) is assigned to each request.
Definition: JsonRpcClient.h:61
JsonRpcClient()
Instantiates the object with default parameters (default constructor).
Definition: JsonRpcClient.h:46
JsonRpcClient & operator=(const JsonRpcClient &rhs)
Assignment operator.
Definition: JsonRpcClient.h:48
A file that contains the configuration information for each development environment.
uint32_t reqid_t
id type for the JSON-RPC request.
Definition: JsonRpcClient.h:32
Class to manage client side JSON-RPC.
Definition: JsonRpcClient.h:37
Implements the Future pattern for multithread programming.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37