AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
RemoteJournalConnector.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//#include <signal.h>
18#pragma once
19
20#include <agx/config/AGX_USE_WEBSOCKETS.h>
21
22#if AGX_USE_WEBSOCKETS()
23
24#include <agxNet/Socket.h>
25#include <agxNet/WebSocket.h>
26#include <agxNet/FramePacket.h>
27#include <agxData/Track.h>
30#include <agx/Thread.h>
31
32//#include <agx/Interrupt.h>
33//#include <agxIO/ArgumentParser.h>
34
35#include <agxSDK/Simulation.h>
36
37using namespace agx;
38using namespace agxSDK;
39
40namespace agxNet{
41 AGX_DECLARE_POINTER_TYPES(RemoteJournalConnector);
42 AGX_DECLARE_VECTOR_TYPES(RemoteJournalConnector);
43
47 class AGXPHYSICS_EXPORT RemoteJournalConnector {
48 public:
49 /*
50 * Initialize a RemoteJournalConnector entity that expects a
51 * control channel server at host:port
52 */
53 RemoteJournalConnector(String host, UInt16 port);
54 virtual ~RemoteJournalConnector();
55
56 /*
57 * Attempts to connect to a control channel at host:port
58 */
59 void connectToControlChannel();
60 agxSDK::Simulation* getSimulation();
61
62 /*
63 * Sends a "Simulation.Play" message to the control server
64 */
65 void sendPlayMessage();
66
67 /*
68 * Mutex that gets locked during manipulation of the Simulation
69 */
70 virtual agx::Mutex& getFrameMutex()
71 {
72 static agx::Mutex s_defaultMutex;
73 return s_defaultMutex;
74 };
75
76 /*
77 \return True as long as the connection should be kept
78 */
79 virtual bool isRunning() = 0;
80
81 /*
82 * Called after the control channel have recieved and parsed a "Simulation.LoadScene" message
83 */
84 virtual void onLoadSimulation(Simulation*) {};
85
86 /*
87 * Called after the connection to the Journal Socket is established
88 */
89 virtual void onRemoteViewerAttached() {};
90
91 /*
92 * Called when the control channel receives a "Simulation.Exit" message
93 */
94 virtual void onSimulationExit() {};
95
96 private:
97 void connectToJournalSocket();
98 void handleSimulationLoadScene(agxNet::StructuredMessage* message);
99 void onControlChannelMessage(agxNet::WebSocket *, UInt8 *data, size_t numBytes);
100 void onDisconnected(agxNet::WebSocket* disconnectedSocket);
101 std::stringstream readAgxSceneDataFromLoadSceneMessage(agxNet::StructuredMessage* message);
102 void runServerSocketThread();
103 bool service();
104
105 agxSDK::SimulationRef m_simulation;
106 agxNet::WebSocketServerRef m_serverSocket;
107 agxNet::WebSocketRef m_controlChannelSocket;
108 agxNet::WebSocketRef m_journalTrackSocket;
109 agxNet::WebSocketFrameReaderRef m_journalTrackReader;
110 agxSDK::SimulationFrameWriterRef m_simulationWriter;
111 agxData::TrackRef m_socketToSimulationTrack;
112 String m_host;
113 UInt16 m_controlChannelPort;
114 UInt16 m_journalSocketPort;
115 std::atomic<bool> m_serverSocketShouldStop;
116 std::thread m_serverSocketThread;
117 };
118}
119
120#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition MacUtil.h:23
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition Integer.h:31
std::mutex Mutex
Definition Referenced.h:99
uint8_t UInt8
Definition Integer.h:30