Simulated Reality SDK 7500c78d v1.30.2.51085 2024-04-26T11:23:03Z
Stable
srcontext.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <string>
13#include <map>
14
15#include "sr/sense/core/sense.h"
19
20#ifdef WIN32
21# ifdef COMPILING_DLL_SimulatedRealityCore
22# define DIMENCOSR_API __declspec(dllexport)
23# else
24# define DIMENCOSR_API __declspec(dllimport)
25# endif
26#else
27# define DIMENCOSR_API
28#endif
29
35enum SR_contextMessageType : uint64_t {
37};
38
46typedef struct {
49
70namespace SR {
71
72//Forward declaration
73class Configuration;
74
81private:
82 uint64_t other = 0; // Remote Receiver*
88#pragma warning(push)
89#pragma warning(disable: 4251)
90 std::map<std::string, std::vector<WorldObject*>> worldObjects;
91 std::map<std::string, std::vector<Sense*>> senses;
92 std::unique_ptr<Configuration> configuration;
93#pragma warning(pop)
94
95 void calibrateAllSenses();
96 void startAllSenses();
97 void stopAllSenses();
98 void deleteAllSenses();
99
100public:
108 };
109
110private:
111 void construct(NetworkMode mode, std::string address, std::string port, bool lensPreference);
112
113public:
118
127 NetworkInterface* connectionToServer = nullptr;
128
138 NetworkInterface* client = nullptr;
139
146 SRContext(NetworkMode mode = NetworkMode::NonBlockingClientMode);
147
155 SRContext(std::string serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
156
164 SRContext(bool lensPreference, NetworkMode mode = NetworkMode::NonBlockingClientMode);
165
174 SRContext(bool lensPreference, std::string serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
175
183 static SRContext* create(NetworkMode mode = NetworkMode::NonBlockingClientMode);
184
193 static SRContext* create(const char* serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
194
203 static SRContext* create(bool lensPreference, NetworkMode mode = NetworkMode::NonBlockingClientMode);
204
214 static SRContext* create(bool lensPreference, const char* serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
215
221 static void deleteSRContext(SRContext* context);
222
228 void setOther(uint64_t srContext);
229
234
241
248 void addObject(std::string interfaceIdentifier, WorldObject* worldObject);
249
256 const std::vector<WorldObject*>& getObjects(std::string interfaceIdentifier);
257
264 void addSense(std::string interfaceIdentifier, Sense* sense);
265
272 void removeSense(std::string interfaceIdentifier, Sense* sense);
273
280 const std::vector<Sense*>& getSenses(std::string interfaceIdentifier);
281
290
299 virtual void receive(SR_packet& packet) override;
300
309 virtual void print(SR_packet& packet) override;
310};
311
312}
313
314#undef DIMENCOSR_API
Class representing the configuration of the SRContext.
Definition: srconfiguration.h:47
Interface defining how to send messages between SR applications.
Definition: networkinterface.h:29
Interface to be used to enable receiving SR_packet from other SR applications.
Definition: receiver.h:30
Maintains WorldObject and Sense objects during the application lifetime.
Definition: srcontext.h:80
const NetworkMode mode
Affects which implementation of a certain interface will be constructed when the associated create fu...
Definition: srcontext.h:117
SRContext(bool lensPreference, std::string serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
Construct the SRContext.
virtual void receive(SR_packet &packet) override
Receives SR_packet sent over network to control remote instances of SRContext.
const std::vector< Sense * > & getSenses(std::string interfaceIdentifier)
Get all registered senses of the given interface.
const Configuration & getConfiguration()
Get configuration information.
void addObject(std::string interfaceIdentifier, WorldObject *worldObject)
Register a world object of the given interface with the context.
void initialize()
Initialize all senses.
~SRContext()
Clean up the SRContext and associated world.
static SRContext * create(bool lensPreference, NetworkMode mode=NetworkMode::NonBlockingClientMode)
create new SRContext instance
static SRContext * create(bool lensPreference, const char *serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
create new SRContext instance
const std::vector< WorldObject * > & getObjects(std::string interfaceIdentifier)
Get all registered world objects of the given interface.
static SRContext * create(const char *serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
create new SRContext instance
SRContext(NetworkMode mode=NetworkMode::NonBlockingClientMode)
Construct the SRContext.
void removeSense(std::string interfaceIdentifier, Sense *sense)
Unregister a sense of the given interface from the context.
void setOther(uint64_t srContext)
set remote SRContext to communicate with
virtual void print(SR_packet &packet) override
Prints text representation of SR_packet containing eye position updates sent over network.
static void deleteSRContext(SRContext *context)
delete SRContext instance
SRContext(bool lensPreference, NetworkMode mode=NetworkMode::NonBlockingClientMode)
Construct the SRContext.
NetworkMode
Definition: srcontext.h:101
@ StandaloneMode
ClientMode if server is reachable, ServerMode behaviour otherwise.
Definition: srcontext.h:106
@ ClientMode
Receive data from server, keep connecting to server until available.
Definition: srcontext.h:104
@ ServerMode
Send data to client.
Definition: srcontext.h:103
@ EdgeMode
Identical to ServerMode.
Definition: srcontext.h:102
@ HybridMode
Same as StandAlone mode.
Definition: srcontext.h:105
@ NonBlockingClientMode
Try to connect to server once, throw exception otherwise.
Definition: srcontext.h:107
static SRContext * create(NetworkMode mode=NetworkMode::NonBlockingClientMode)
create new SRContext instance
SRContext(std::string serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
Construct the SRContext.
void addSense(std::string interfaceIdentifier, Sense *sense)
Register a sense of the given interface with the context.
Class of objects dealing with Streams of data.
Definition: sense.h:42
Class representing both real and virtual objects as nodes in the World tree.
Definition: worldobject.h:35
SR_contextMessageType
Enumeration of SR_contextMessage types.
Definition: srcontext.h:35
@ Initialize
Definition: srcontext.h:36
Namespace containing all C++ Simulated Reality classes.
Definition: srconfiguration.h:25
#define DIMENCOSR_API
Definition: srcontext.h:27
C-compatible struct to signal the SR context.
Definition: srcontext.h:46
SR_contextMessageType type
Definition: srcontext.h:47
C-compatible struct for communication between SR applications.
Definition: packet.h:25