AGX Dynamics  2.37.3.2
CoSimulationBase.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 
17 #pragma once
18 
19 #ifdef _MSC_VER
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 
30 namespace agxNet
31 {
32 
35  {
36  public:
37 
39  struct Header
40  {
41  Header() : numBytes(0), mode(0), compressed(false) {}
42  enum Mode
43  {
44  NOP = 0,
45 
53 
57 
58  SHUTDOWN
59  };
60 
61  uint32_t numBytes;
62  uint8_t mode;
63  bool compressed;
64  char md5[32];
65  };
66 
67  public:
68 
71 
73  virtual bool isConnected();
74 
75  virtual bool waitForConnection()=0;
76 
81  virtual void dropConnection(bool shouldShutdown=false);
82 
83  protected:
84 
91  size_t sendData( const uint8_t* data, size_t numBytes );
92 
99  size_t receiveData( uint8_t* data, size_t numBytes );
100 
101  virtual ~CoSimulationBase();
102 
103  protected:
104 
105  virtual void handleConnectionDrop();
106  void sendPacket(Header &header);
107  void receivePacket(Header &header);
108 
110 
114 
115 
116  private:
117 
118  };
119 
120 
121  template<typename T>
122  void insertBytes(agx::Vector<char>& container, size_t startIndex, const T& value)
123  {
124  ::memcpy(&container[startIndex], &value, sizeof(value));
125  }
126 
127 
128  template<typename T>
129  T extractBytes(const agx::Vector<char>& container, size_t startIndex)
130  {
131  T value;
132  ::memcpy(&value, &container[startIndex], sizeof(T));
133  return value;
134  }
135 
136 }
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:22
#define AGXPHYSICS_EXPORT
Base class for multi threaded transferring simulation between a server and a client using sockets...
agx::Vector< char > m_buffer
T extractBytes(const agx::Vector< char > &container, size_t startIndex)
void insertBytes(agx::Vector< char > &container, size_t startIndex, const T &value)
std::mutex Mutex
Definition: Referenced.h:99
Header used for sending data over sockets.