AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
CoSimulationBase.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
25#include <agx/Thread.h>
26#include <agxNet/Compress.h>
27#include <agxNet/Socket.h>
28#include <agx/Referenced.h>
29
30namespace agxNet
31{
32
35 {
36 public:
37
39 struct Header
40 {
41 Header() : numBytes(0), mode(0), compressed(false) {}
60
61 uint32_t numBytes;
62 uint8_t mode;
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
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}
#define AGXPHYSICS_EXPORT
Base class for multi threaded transferring simulation between a server and a client using sockets.
size_t receiveData(uint8_t *data, size_t numBytes)
Receive data from remote party.
virtual bool waitForConnection()=0
size_t sendData(const uint8_t *data, size_t numBytes)
Transmit data to remote party.
virtual void dropConnection(bool shouldShutdown=false)
Drop the connection to the remote host and wait for a new one.
void sendPacket(Header &header)
virtual bool isConnected()
CoSimulationBase()
Default constructor.
virtual void handleConnectionDrop()
void receivePacket(Header &header)
agx::Vector< char > m_buffer
Templated vector class.
Definition agx/Vector.h:53
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition MacUtil.h:23
void insertBytes(agx::Vector< char > &container, size_t startIndex, const T &value)
T extractBytes(const agx::Vector< char > &container, size_t startIndex)
std::mutex Mutex
Definition Referenced.h:99
Header used for sending data over sockets.