nlib
jsonrpc.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 #ifndef SAMPLES_SOURCES_MSGPACK_JSONRPC_JSONRPC_H_
16 #define SAMPLES_SOURCES_MSGPACK_JSONRPC_JSONRPC_H_
17 
18 #include <stdlib.h>
19 #include <list>
20 #include <utility>
23 
24 #ifndef NLIB_SOCKET_ENABLED
25 #define DONT_USE_SOCKET
26 #endif
27 
28 class Tunnel {
29  public:
30  ~Tunnel() {
31  using nlib_ns::threading::SimpleCriticalSection;
32  using nlib_ns::threading::ScopedLock;
33  ScopedLock<SimpleCriticalSection> l(lock_);
34  BufType::iterator it = buf_.begin();
35  BufType::iterator end = buf_.end();
36  for (; it != end; ++it) {
37  nlib_free(it->first);
38  }
39  }
40  void Send(nlib_ns::ReallocOutputStream::UniquePtrType* data, size_t n) {
41  using nlib_ns::threading::SimpleCriticalSection;
42  using nlib_ns::threading::ScopedLock;
43  ScopedLock<SimpleCriticalSection> l(lock_);
44  buf_.push_back(BufItem(data->release(), n));
45  }
46  bool Receive(nlib_ns::ReallocOutputStream::UniquePtrType* data, size_t* n) {
47  using nlib_ns::threading::SimpleCriticalSection;
48  using nlib_ns::threading::ScopedLock;
49  ScopedLock<SimpleCriticalSection> l(lock_);
50  if (buf_.empty()) return false;
51  BufItem& item = buf_.front();
52  data->reset(item.first);
53  *n = item.second;
54  buf_.pop_front();
55  return true;
56  }
57 
58  private:
59  typedef std::pair<uint8_t*, size_t> BufItem;
60  typedef std::list<BufItem> BufType;
61  nlib_ns::threading::SimpleCriticalSection lock_;
62  BufType buf_;
63 };
64 
65 extern Tunnel g_c2s;
66 extern Tunnel g_s2c;
67 
68 errno_t InitServer();
69 void ServerThread();
70 extern volatile bool g_shutdown_server;
71 
72 #endif // SAMPLES_SOURCES_MSGPACK_JSONRPC_JSONRPC_H_
ミューテックス, 再入可能ミューテックス, 再入とタイムアウトが可能なミューテックスを実装しています。 ...
UniquePtr< uint8_t[], ReallocDeleter > UniquePtrType
uint8_tの配列へのUniquePtrをtypedefしたものです。
void nlib_free(void *ptr)
C標準関数のfree()を呼び出すweak関数です。nlibはこの関数を経由してfree()を呼び出します。 ...
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37