Simulated Reality SDK 7500c78d v1.30.2.51085 2024-04-26T11:23:03Z
Stable
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SR::SRContext Class Reference

Maintains WorldObject and Sense objects during the application lifetime. More...

#include <srcontext.h>

Inheritance diagram for SR::SRContext:
[legend]
Collaboration diagram for SR::SRContext:
[legend]

Public Types

enum  NetworkMode {
  EdgeMode , ServerMode , ClientMode , HybridMode ,
  StandaloneMode , NonBlockingClientMode
}
 

Public Member Functions

 SRContext (NetworkMode mode=NetworkMode::NonBlockingClientMode)
 Construct the SRContext. More...
 
 SRContext (std::string serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 Construct the SRContext. More...
 
 SRContext (bool lensPreference, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 Construct the SRContext. More...
 
 SRContext (bool lensPreference, std::string serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 Construct the SRContext. More...
 
void setOther (uint64_t srContext)
 set remote SRContext to communicate with More...
 
 ~SRContext ()
 Clean up the SRContext and associated world. More...
 
void initialize ()
 Initialize all senses. More...
 
void addObject (std::string interfaceIdentifier, WorldObject *worldObject)
 Register a world object of the given interface with the context. More...
 
const std::vector< WorldObject * > & getObjects (std::string interfaceIdentifier)
 Get all registered world objects of the given interface. More...
 
void addSense (std::string interfaceIdentifier, Sense *sense)
 Register a sense of the given interface with the context. More...
 
void removeSense (std::string interfaceIdentifier, Sense *sense)
 Unregister a sense of the given interface from the context. More...
 
const std::vector< Sense * > & getSenses (std::string interfaceIdentifier)
 Get all registered senses of the given interface. More...
 
const ConfigurationgetConfiguration ()
 Get configuration information. More...
 
virtual void receive (SR_packet &packet) override
 Receives SR_packet sent over network to control remote instances of SRContext. More...
 
virtual void print (SR_packet &packet) override
 Prints text representation of SR_packet containing eye position updates sent over network. More...
 
- Public Member Functions inherited from SR::Receiver
virtual ~Receiver ()
 Ensures that the destructor of extending classes is called when a pointer has been cast to Receiver*. More...
 

Static Public Member Functions

static SRContextcreate (NetworkMode mode=NetworkMode::NonBlockingClientMode)
 create new SRContext instance More...
 
static SRContextcreate (const char *serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 create new SRContext instance More...
 
static SRContextcreate (bool lensPreference, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 create new SRContext instance More...
 
static SRContextcreate (bool lensPreference, const char *serverAddress, NetworkMode mode=NetworkMode::NonBlockingClientMode)
 create new SRContext instance More...
 
static void deleteSRContext (SRContext *context)
 delete SRContext instance More...
 

Public Attributes

const NetworkMode mode
 Affects which implementation of a certain interface will be constructed when the associated create function is called. More...
 
NetworkInterfaceconnectionToServer = nullptr
 NetworkInterface to application controlling sense implementations. More...
 
NetworkInterfaceclient = nullptr
 instance of Client More...
 

Detailed Description

Maintains WorldObject and Sense objects during the application lifetime.

Member Enumeration Documentation

◆ NetworkMode

enum SR::SRContext::NetworkMode
Enumerator
EdgeMode 

Identical to ServerMode.

ServerMode 

Send data to client.

ClientMode 

Receive data from server, keep connecting to server until available.

HybridMode 

Same as StandAlone mode.

StandaloneMode 

ClientMode if server is reachable, ServerMode behaviour otherwise.

NonBlockingClientMode 

Try to connect to server once, throw exception otherwise.

Constructor & Destructor Documentation

◆ SRContext() [1/4]

SR::SRContext::SRContext ( NetworkMode  mode = NetworkMode::NonBlockingClientMode)

Construct the SRContext.

Parameters
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.

◆ SRContext() [2/4]

SR::SRContext::SRContext ( std::string  serverAddress,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)

Construct the SRContext.

Parameters
serveraddress to connect to
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.

◆ SRContext() [3/4]

SR::SRContext::SRContext ( bool  lensPreference,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)

Construct the SRContext.

Parameters
lenspreference determines the initial lens state preference
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.

◆ SRContext() [4/4]

SR::SRContext::SRContext ( bool  lensPreference,
std::string  serverAddress,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)

Construct the SRContext.

Parameters
lenspreference determines the initial lens state preference
serveraddress to connect to
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.

◆ ~SRContext()

SR::SRContext::~SRContext ( )

Clean up the SRContext and associated world.

Member Function Documentation

◆ addObject()

void SR::SRContext::addObject ( std::string  interfaceIdentifier,
WorldObject worldObject 
)

Register a world object of the given interface with the context.

Parameters
interfaceIdentifiergroup identifier used as part of a given interface's create function
worldObjectto be registered as interfaceIdentifier

◆ addSense()

void SR::SRContext::addSense ( std::string  interfaceIdentifier,
Sense sense 
)

Register a sense of the given interface with the context.

Parameters
interfaceIdentifiergroup identifier used as part of a given interface's create function
senseto be registered as interfaceIdentifier

◆ create() [1/4]

static SRContext * SR::SRContext::create ( bool  lensPreference,
const char *  serverAddress,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)
static

create new SRContext instance

Parameters
lenspreference determines the initial lens state preference
serveraddress to connect to
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.
Returns
SRContext* new instance

◆ create() [2/4]

static SRContext * SR::SRContext::create ( bool  lensPreference,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)
static

create new SRContext instance

Parameters
lenspreference determines the initial lens state preference
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.
Returns
SRContext* new instance

◆ create() [3/4]

static SRContext * SR::SRContext::create ( const char *  serverAddress,
NetworkMode  mode = NetworkMode::NonBlockingClientMode 
)
static

create new SRContext instance

Parameters
serveraddress to connect to
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.
Returns
SRContext* new instance

◆ create() [4/4]

static SRContext * SR::SRContext::create ( NetworkMode  mode = NetworkMode::NonBlockingClientMode)
static

create new SRContext instance

Parameters
modeaffects which implementation of a certain interface will be constructed when the associated create function is called
Exceptions
aServerNotAvailableException when the context could not establish a connection to the SR Service, the SR Service might not be running.
Returns
SRContext* new instance

◆ deleteSRContext()

static void SR::SRContext::deleteSRContext ( SRContext context)
static

delete SRContext instance

Parameters
contextto be deleted

◆ getConfiguration()

const Configuration & SR::SRContext::getConfiguration ( )

Get configuration information.

Returns
const Configuration & object to represent configurations of the full system
Deprecated:
Senses should handle their own configuration.

◆ getObjects()

const std::vector< WorldObject * > & SR::SRContext::getObjects ( std::string  interfaceIdentifier)

Get all registered world objects of the given interface.

Parameters
interfaceIdentifiergroup identifier used as part of a given interface's create function
Returns
std::vector<WorldObject*>& which is a list of objects registered as interfaceIdentifier

◆ getSenses()

const std::vector< Sense * > & SR::SRContext::getSenses ( std::string  interfaceIdentifier)

Get all registered senses of the given interface.

Parameters
interfaceIdentifiergroup identifier used as part of a given interface's create function
Returns
std::vector<Sense*>& which is a list of senses registered as interfaceIdentifier

◆ initialize()

void SR::SRContext::initialize ( )

Initialize all senses.

Call after all objects and senses have been added.

◆ print()

virtual void SR::SRContext::print ( SR_packet packet)
overridevirtual

Prints text representation of SR_packet containing eye position updates sent over network.

Parameters
packetis a C-compatible message which requires no further serialization

Used for debugging purposes. Inherited via Receiver.

Implements SR::Receiver.

◆ receive()

virtual void SR::SRContext::receive ( SR_packet packet)
overridevirtual

Receives SR_packet sent over network to control remote instances of SRContext.

Parameters
packetis a C-compatible message which requires no further serialization

SRContext specifically receives packets to achieve the desired startup behaviour. Inherited via Receiver.

Implements SR::Receiver.

◆ removeSense()

void SR::SRContext::removeSense ( std::string  interfaceIdentifier,
Sense sense 
)

Unregister a sense of the given interface from the context.

Parameters
interfaceIdentifiergroup identifier used as part of a given interface's create function
senseto be unregistered as interfaceIdentifier

◆ setOther()

void SR::SRContext::setOther ( uint64_t  srContext)

set remote SRContext to communicate with

Parameters
srContextis used to identify remote SRContext

Member Data Documentation

◆ client

NetworkInterface* SR::SRContext::client = nullptr

instance of Client

Connection to a more centralized application in the SR system. This may connect to the application controlling the physical components or services shared between SR devices connectionToServer may point to the same instance as client unless server is connected to a remote server

TODO scope should be private (accessed to check mode in several locations to switch between implementations)

◆ connectionToServer

NetworkInterface* SR::SRContext::connectionToServer = nullptr

NetworkInterface to application controlling sense implementations.

There is one application which controls the physical components, this NetworkInterface connects to it. When a Sense is created and this is not nullptr, the functional implementation will be constructed on the remote application.

TODO scope should be private (server is setting connectionToServer directly)

◆ mode

const NetworkMode SR::SRContext::mode

Affects which implementation of a certain interface will be constructed when the associated create function is called.


The documentation for this class was generated from the following file: