LeiaSR SDK 720218b2 v1.32.7.6322 2025-02-13T14:55:38Z
Stable
srcontext.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <string>
8#include <map>
9
10#include "sr/sense/core/sense.h"
14
15#ifdef WIN32
16# ifdef COMPILING_DLL_SimulatedRealityCore
17# define DIMENCOSR_API __declspec(dllexport)
18# else
19# define DIMENCOSR_API __declspec(dllimport)
20# endif
21#else
22# define DIMENCOSR_API
23#endif
24
30enum SR_contextMessageType : uint64_t {
32};
33
41typedef struct {
44
65namespace SR {
66
67//Forward declaration
68class Configuration;
69
76private:
77 uint64_t other = 0; // Remote Receiver*
83#pragma warning(push)
84#pragma warning(disable: 4251)
85 std::map<std::string, std::vector<WorldObject*>> worldObjects;
86 std::map<std::string, std::vector<Sense*>> senses;
87 std::unique_ptr<Configuration> configuration;
88#pragma warning(pop)
89
90 void calibrateAllSenses();
91 void startAllSenses();
92 void stopAllSenses();
93 void deleteAllSenses();
94
95public:
103 };
104
105private:
106 void construct(NetworkMode mode, std::string address, std::string port, bool lensPreference);
107
108public:
113
122 NetworkInterface* connectionToServer = nullptr;
123
133 NetworkInterface* client = nullptr;
134
141 SRContext(NetworkMode mode = NetworkMode::NonBlockingClientMode);
142
150 SRContext(std::string serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
151
159 SRContext(bool lensPreference, NetworkMode mode = NetworkMode::NonBlockingClientMode);
160
169 SRContext(bool lensPreference, std::string serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
170
178 static SRContext* create(NetworkMode mode = NetworkMode::NonBlockingClientMode);
179
188 static SRContext* create(const char* serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
189
198 static SRContext* create(bool lensPreference, NetworkMode mode = NetworkMode::NonBlockingClientMode);
199
209 static SRContext* create(bool lensPreference, const char* serverAddress, NetworkMode mode = NetworkMode::NonBlockingClientMode);
210
216 static void deleteSRContext(SRContext* context);
217
223 void setOther(uint64_t srContext);
224
229
236
243 void addObject(std::string interfaceIdentifier, WorldObject* worldObject);
244
251 const std::vector<WorldObject*>& getObjects(std::string interfaceIdentifier);
252
259 void addSense(std::string interfaceIdentifier, Sense* sense);
260
267 void removeSense(std::string interfaceIdentifier, Sense* sense);
268
275 const std::vector<Sense*>& getSenses(std::string interfaceIdentifier);
276
285
294 virtual void receive(SR_packet& packet) override;
295
304 virtual void print(SR_packet& packet) override;
305};
306
307}
308
309#undef DIMENCOSR_API
Class representing the configuration of the SRContext.
Definition: srconfiguration.h:42
Interface defining how to send messages between SR applications.
Definition: networkinterface.h:24
Interface to be used to enable receiving SR_packet from other SR applications.
Definition: receiver.h:25
Maintains WorldObject and Sense objects during the application lifetime.
Definition: srcontext.h:75
const NetworkMode mode
Affects which implementation of a certain interface will be constructed when the associated create fu...
Definition: srcontext.h:112
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:96
@ StandaloneMode
ClientMode if server is reachable, ServerMode behaviour otherwise.
Definition: srcontext.h:101
@ ClientMode
Receive data from server, keep connecting to server until available.
Definition: srcontext.h:99
@ ServerMode
Send data to client.
Definition: srcontext.h:98
@ EdgeMode
Identical to ServerMode.
Definition: srcontext.h:97
@ HybridMode
Same as StandAlone mode.
Definition: srcontext.h:100
@ NonBlockingClientMode
Try to connect to server once, throw exception otherwise.
Definition: srcontext.h:102
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:37
Class representing both real and virtual objects as nodes in the World tree.
Definition: worldobject.h:30
SR_contextMessageType
Enumeration of SR_contextMessage types.
Definition: srcontext.h:30
@ Initialize
Definition: srcontext.h:31
Namespace containing all C++ Simulated Reality classes.
Definition: srconfiguration.h:20
#define DIMENCOSR_API
Definition: srcontext.h:22
C-compatible struct to signal the SR context.
Definition: srcontext.h:41
SR_contextMessageType type
Definition: srcontext.h:42
C-compatible struct for communication between SR applications.
Definition: packet.h:20