HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_Performance.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_Performance.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __NET_PERFORMANCE_H__
14 #define __NET_PERFORMANCE_H__
15 
16 #include "NET_API.h"
17 
19 #include "NET_SocketListener.h"
20 
21 #include <UT/UT_Performance.h>
22 #include <UT/UT_SharedPtr.h>
23 #include <UT/UT_WorkBuffer.h>
24 #include <UT/UT_Lock.h>
25 
27 {
28 public:
30  {
31  public:
34  ASIO_TCPSocket socket)
35  : NET_IPacketConnectionHandler(mgr, std::move(socket))
36  , myFrameNum(0)
37  , myValue(0)
38  {
39  }
40 
41  void onPacket(UT_WorkBuffer&& data) override;
42 
43  private:
44  void registerRemoteEvent(
45  const UT_StringHolder& type,
46  const UT_StringHolder& category_name,
47  int frame_num,
48  const UT_StringHolder& object,
49  const UT_StringHolder& object_type,
50  fpreal value);
51 
52  enum eventReadState
53  {
54  needEventType,
55  needEventCategory,
56  needEventFrame,
57  needEventObject,
58  needEventObjectType,
59  needEventValue
60  };
61 
62  eventReadState myReadState;
63  UT_StringHolder myEventType;
64  UT_StringHolder myCategory;
65  UT_StringHolder myObject;
66  UT_StringHolder myObjectType;
67  int myFrameNum;
68  fpreal myValue;
69  };
70 
71  class net_PacketListener : public NET_SocketListener<ASIO_TCPAcceptor>
72  {
73  public:
74  net_PacketListener(ASIO_IOContext::executor_type& exc) :
76  {}
77 
78  private:
79  void onAccept_(
80  const hboost::system::error_code& ec,
81  ASIO_TCPSocket socket) override
82  {
83  if (!ec && socket.is_open())
84  {
85  auto handler = UTmakeShared<net_PacketConnectionHandler>(
86  myConnectionManager, std::move(socket));
87  myConnectionManager.start(handler);
88  }
89  }
90  };
91 
93 
94  void closeListener();
95 
96  int getEventListenPort() const override
97  {
98  return myPacketListener ? myPacketListener->port() : 0;
99  }
100 
101 protected:
102  void startListener_(ASIO_IOContext::executor_type exc);
103 
104 private:
105  UT_Lock myInitLock;
106  UT_SharedPtr<net_PacketListener> myPacketListener;
107 };
108 
109 #endif // __NET_PERFORMANCE_H__
110 
hboost::asio::ip::tcp::socket ASIO_TCPSocket
Definition: UT_BoostAsio.h:44
void start(int initial_port, int max_port_range=-1, bool use_system_port=false, const ASIO_IPAddress &address=ASIO_IPAddressV4())
net_PacketListener(ASIO_IOContext::executor_type &exc)
#define NET_API
Definition: NET_API.h:9
int getEventListenPort() const override
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
hboost::asio::ip::tcp::acceptor ASIO_TCPAcceptor
Definition: UT_BoostAsio.h:46
fpreal64 fpreal
Definition: SYS_Types.h:277
Definition: core.h:1131
net_PacketConnectionHandler(NET_ConnectionManager &mgr, ASIO_TCPSocket socket)
type
Definition: core.h:1059
Definition: format.h:895