32 #include <boost/assert.hpp>
38 using ::osvr::common::ClientInterface;
39 using ::osvr::common::ClientContextDeleter;
40 using ::osvr::make_shared;
51 static const auto CLIENT_LOG_PREFIX =
"Client: ";
52 static const auto OSVR_LIBS_CLIENT_LOG_PREFIX =
"OSVR: ";
53 static const auto OSVR_LIBS_CLIENT_LOG_SUFFIX =
"";
58 osvr::common::ClientContextDeleter del)
59 : m_appId(appId), m_clientInterfaceFactory(interfaceFactory),
61 m_logger(
osvr::util::log::make_logger(
62 OSVR_LIBS_CLIENT_LOG_PREFIX + m_appId + OSVR_LIBS_CLIENT_LOG_SUFFIX)),
64 osvr::util::log::make_logger(CLIENT_LOG_PREFIX + m_appId)) {
65 m_logger->info() <<
"OSVR client context initialized for " << m_appId;
74 ClientContextDeleter del)
79 m_logger->info() <<
"OSVR client context shut down for " << m_appId;
89 for (
auto const &iface : m_interfaces) {
95 auto ret = m_clientInterfaceFactory(*
this, path);
99 m_handleNewInterface(ret);
100 m_interfaces.push_back(ret);
110 auto it = std::find_if(begin(m_interfaces), end(m_interfaces),
112 if (ptr.get() == iface) {
119 (it == end(m_interfaces)) == (!ret),
120 "We should have a pointer if and only if we have the iterator");
123 m_interfaces.erase(it);
125 m_handleReleasingInterface(ret);
136 return m_getPathTree();
144 return m_ownedObjects.
release(obj);
149 return m_getRoomToWorldTransform();
154 m_setRoomToWorldTransform(xform);
164 const char *message) {
165 m_clientLogger->log(severity, message);
168 bool OSVR_ClientContextObject::m_getStatus()
const {
173 void OSVR_ClientContextObject::m_handleNewInterface(
178 void OSVR_ClientContextObject::m_handleReleasingInterface(
bool getStatus() const
Returns true if we are started up and fully connected (path tree received, etc.)
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
std::string getStringParameter(std::string const &path) const
Gets a string parameter value.
A tree representation, with path/url syntax, of the known OSVR system.
osvr::common::Transform const & getRoomToWorldTransform() const
Gets the transform from room space to world space.
void sendRoute(std::string const &route)
Sends a JSON route/transform object to the server.
osvr::common::ClientInterfacePtr getInterface(const char path[])
Creates an interface object for the given path. The context retains shared ownership.
osvr::common::ClientInterfacePtr releaseInterface(osvr::common::ClientInterface *iface)
Searches through this context to determine if the passed interface object has been retained...
bool release(void *ptr)
Releases the indicated smart pointer in our ownership, if we have it.
std::string const & getAppId() const
Accessor for app ID.
void setRoomToWorldTransform(osvr::common::Transform const &xform)
Sets the transform from room space to world space.
OSVR_ClientContextObject(const char appId[], osvr::common::ClientContextDeleter del)
Constructor for derived class use only.
bool releaseObject(void *obj)
Frees some object whose lifetime is controlled by the client context.
osvr::common::PathTree const & getPathTree() const
Accessor for the path tree.
virtual ~OSVR_ClientContextObject()
Destructor.
void log(osvr::util::log::LogLevel severity, const char *message)
Logs a message from the client.
std::function< ClientInterfacePtr(ClientContext &, const char[])> ClientInterfaceFactory
A factory function type taking the client context and path, and returning a ClientInterfacePtr. The ClientContext will handle notifying its internals about the new interface before returning it.
ClientInterfaceFactory getStandardClientInterfaceFactory()
Returns a client interface factory suitable for standard client use.
Internal, configured header file for verbosity macros.
osvr::util::log::LoggerPtr const & logger() const
Provides logger access for related internal classes.
void deleteContext(ClientContext *ctx)
Use the stored deleter to appropriately delete the client context.
void update()
System-wide update method.
osvr::common::ClientContextDeleter getDeleter() const
Returns the specialized deleter for this object.