AGXDynamics  2.31.1.0
CoSimulationServer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 #ifndef AGXNET_COSIMULATIONSERVER_H
18 #define AGXNET_COSIMULATIONSERVER_H
19 
21 #include <agx/agx_vector_types.h>
22 
23 #include <agx/Thread.h>
24 
25 namespace agxSDK
26 {
27  class Simulation;
28 }
29 
30 namespace agxNet
31 {
32 
35  {
36  public:
37 
38  void run();
39 
41  void shutdown();
42 
43 
45  {
46  NO_SCRIPT=0,
47  PYTHON_SCRIPT=1,
48  };
49 
50  void setScriptMode(ScriptMode);
51  ScriptMode getScriptMode() const;
52 
57  CoSimulationServer( uint16_t port );
58 
63  void setEnableCompression( bool flag ) { m_useCompression = flag; }
64 
68  bool getEnableCompression( ) const { return m_useCompression; }
69 
70  const agx::String& getFilename();
71 
72  Header::Mode receiveInstructions( agxSDK::Simulation *simulation );
73  void setInstructionStatus( Header::Mode mode, const agx::String& message );
74 
75  bool applyInitInputs(agxSDK::Simulation *simulation );
76  bool obtainInitOutputs(agxSDK::Simulation* simulation );
77 
78  bool isShutdown();
79 
80  protected:
81 
82  virtual void waitForDataAndTransfer();
83  virtual bool waitForConnection();
84  virtual void dropConnection();
85 
86  virtual ~CoSimulationServer();
87 
88  private:
89  void handlePreloadScript();
90  void handleSetTimeStep();
91  void handleStepInput();
92  void handleInitInput();
93  void handleNop();
94 
95  void sendReplyPacket();
96 
97  TCPServerSocketRef m_serverSocket;
98  uint16_t m_port;
99  bool m_useCompression;
100 
101  agx::Block m_hasInstructions;
102 
103  Header::Mode m_currentInstruction;
104  Header::Mode m_replyInstruction;
105  agx::String m_replyMessage;
106  agx::String m_filename;
107  double m_timeStep;
108 
109  agx::RealVector m_inputs;
110  agx::RealVector m_outputs;
111 
112  agx::RealVector m_initInputs;
113  agx::RealVector m_initOutputs;
114  agx::Timer stepTimer;
115  ScriptMode m_scriptMode;
116 
117  };
118 
119 }
120 #endif
Name space containing classes for sending/reading data over sockets.
Definition: MacUtil.h:22
Basic wrapper class aroud std::thread.
Definition: Thread.h:81
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
bool AGXPHYSICS_EXPORT isShutdown()
#define AGXPHYSICS_EXPORT
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:73
Base class for multi threaded transferring simulation between a server and a client using sockets...
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:113
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: gl.h:5539
Class for sending serialized agxSDK::Simulation over to a client.
void setEnableCompression(bool flag)
Enable/disable compression of transmitted data.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30