OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ContextC.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
29 #include <osvr/Common/Tracing.h>
31 #include <osvr/Util/Log.h>
32 #include <osvr/Util/LogNames.h>
33 #include <osvr/Util/Verbosity.h>
34 
35 // Library/third-party includes
36 // - none
37 
38 // Standard includes
39 #include <iostream>
40 
41 static const char HOST_ENV_VAR[] = "OSVR_HOST";
42 
43 static inline osvr::util::log::LoggerPtr make_clientkit_logger() {
44  namespace log = osvr::util::log;
45  return log::make_logger(log::OSVR_CLIENTKIT_LOG_NAME);
46 }
47 
48 OSVR_ClientContext osvrClientInit(const char applicationIdentifier[],
49  uint32_t /*flags*/) {
50  auto host = osvr::util::getEnvironmentVariable(HOST_ENV_VAR);
51  if (host.is_initialized()) {
52 
53  make_clientkit_logger()->notice() << "App " << applicationIdentifier
54  << ": Connecting to non-default host "
55  << *host;
56  return ::osvr::client::createContext(applicationIdentifier,
57  host->c_str());
58  }
59  make_clientkit_logger()->debug("Connecting to default (local) host");
60  return ::osvr::client::createContext(applicationIdentifier);
61 }
62 
64  if (!ctx) {
65  make_clientkit_logger()->error(
66  "Can't check status of a null Client Context!");
67  return OSVR_RETURN_FAILURE;
68  }
70 }
71 
72 OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx) {
74  ctx->update();
75  return OSVR_RETURN_SUCCESS;
76 }
77 
78 OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx) {
79  if (nullptr == ctx) {
80  make_clientkit_logger()->error("Can't delete a null Client Context!");
81  return OSVR_RETURN_FAILURE;
82  }
84  return OSVR_RETURN_SUCCESS;
85 }
86 
88  const char *message) {
89  const auto s = static_cast<osvr::util::log::LogLevel>(severity);
90  if (!ctx) {
91  make_clientkit_logger()->log(s)
92  << "Message from app (no client context): " << message;
93  return;
94  }
95 
96  ctx->log(s, message);
97 }
bool getStatus() const
Returns true if we are started up and fully connected (path tree received, etc.)
"Guard"-type class to trace the region of a server update
Definition: Tracing.h:122
OSVR_ClientContext osvrClientInit(const char applicationIdentifier[], uint32_t)
Initialize the library.
Definition: ContextC.cpp:48
Header for basic internal log reference. To actually log to the produced loggers, include
OSVR_ReturnCode osvrClientCheckStatus(OSVR_ClientContext ctx)
Checks to see if the client context is fully started up and connected properly to a server...
Definition: ContextC.cpp:63
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
Definition: ContextC.cpp:78
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx)
Updates the state of the context - call regularly in your mainloop.
Definition: ContextC.cpp:72
OSVR_LogLevel
Log message severity levels.
Definition: LogLevelC.h:44
void osvrClientLog(OSVR_ClientContext ctx, OSVR_LogLevel severity, const char *message)
Log a message from the client.
Definition: ContextC.cpp:87
void log(osvr::util::log::LogLevel severity, const char *message)
Logs a message from the client.
boost::optional< std::string > getEnvironmentVariable(std::string const &var)
Gets an environment variable's value. On systems that don't distinguish between having a variable def...
Internal, configured header file for verbosity macros.
Header.
void deleteContext(ClientContext *ctx)
Use the stored deleter to appropriately delete the client context.
void update()
System-wide update method.
Header.
Header.