AGX Dynamics  2.35.0.1
RemoteDebugBase.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 #pragma once
17 
18 #ifdef _MSC_VER
19 # pragma warning(push)
20 # pragma warning( disable : 4290)
21 # pragma warning( disable: 4275 ) // warning C4275: non dll-interface class
22 #endif
23 
24 #include <agx/agxPhysics_export.h>
25 #include <agx/Thread.h>
26 #include <agxNet/Compress.h>
27 #include <agxNet/Socket.h>
28 #include <agx/Referenced.h>
29 #include <agx/Thread.h>
30 #include <agx/List.h>
31 
32 namespace agxNet
33 {
34 
37  {
38  public:
39 
41  struct Header
42  {
43  Header() : numBytes(0), mode(0), compressed(false) {}
44  enum Mode
45  {
46  READY_TO_RECEIVE=121,
47  NEW_FRAME=111
48  };
49 
50  uint32_t numBytes;
51  uint8_t mode;
52  bool compressed;
53  char md5[32];
54  };
55 
56 #ifdef _MSC_VER
57 # pragma warning(push)
58 # pragma warning( disable : 4250) // 'agxNet::RemoteDebugBase::DataBlock' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance
59 #endif
60 
61 
62  struct DataBlock : public agx::Referenced, public std::stringstream
63  {
64  };
66 
67 #ifdef _MSC_VER
68 # pragma warning(pop)
69 #endif
70 
71  public:
72 
75 
80  void pushBlock( DataBlock *data );
81 
86  void run();
87 
89  virtual bool isConnected();
90 
92  bool hasData();
93 
95  void setMaxQueueSize( size_t numElements ) { m_queueSize = numElements; }
96 
98  size_t getMaxQueueSize( ) const { return m_queueSize; }
99 
101  size_t getQueueSize();
102 
104  void shutdown();
105 
106  protected:
107 
108 
109  bool isShutdown();
110 
111  virtual void waitForDataAndTransfer()=0;
112  virtual bool waitForConnection()=0;
113 
120  size_t sendData( const uint8_t* data, size_t numBytes );
121 
128  size_t receiveData( uint8_t* data, size_t numBytes );
129 
130  virtual ~RemoteDebugBase();
131 
135  virtual void dropConnection();
136 
137  protected:
138 
139  void waitForData();
140  void releaseData();
141  virtual void handleConnectionDrop();
142 
145 
148  size_t m_queueSize;
150 
151 
152  private:
154  DataQueue m_queue;
155 
156  };
157 
158 }
159 
160 #ifdef _MSC_VER
161 # pragma warning(pop)
162 #endif
163 
#define AGXPHYSICS_EXPORT
Base class for multi threaded transferring simulation between a server and a client using sockets.
virtual bool waitForConnection()=0
size_t sendData(const uint8_t *data, size_t numBytes)
Transmit data to remote party.
virtual void waitForDataAndTransfer()=0
virtual void dropConnection()
Drop the connection to the remote host and wait for a new one.
void setMaxQueueSize(size_t numElements)
void pushBlock(DataBlock *data)
Push a block of data for access either by client (simulation) or to be transmitted over socket.
void shutdown()
Shutdown the communication threads, will cause this client to be non-usable any more.
RemoteDebugBase()
Default constructor.
size_t getMaxQueueSize() const
size_t receiveData(uint8_t *data, size_t numBytes)
Receive data from remote party.
virtual void handleConnectionDrop()
DataBlockRef getBlock()
virtual bool isConnected()
void run()
This method is invoked by start.
agx::ref_ptr< DataBlock > DataBlockRef
Basic wrapper class aroud std::thread.
Definition: Thread.h:82
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:114
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:23
std::mutex Mutex
Definition: Referenced.h:93
Header used for sending data over sockets.