OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
com_osvr_example_DummyDetectAndCreateAsync.cpp
Go to the documentation of this file.
1 
12 // Copyright 2014 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 // Internal Includes
28 
29 // Library/third-party includes
30 // - none
31 
32 // Standard includes
33 #include <iostream>
34 
35 // Anonymous namespace to avoid symbol collision
36 namespace {
37 OSVR_MessageType dummyMessage;
38 
39 class DummyDevice {
40  public:
41  DummyDevice(OSVR_PluginRegContext ctx) {
43  m_dev.initAsync(ctx, "MyAsyncDevice");
44 
46  m_dev.registerUpdateCallback(this);
47  }
48 
52  OSVR_ReturnCode update() {
53  // block on waiting for data.
54  // once we have enough, send it.
55  const char mydata[] = "something";
56  m_dev.sendData(dummyMessage, mydata);
57  return OSVR_RETURN_SUCCESS;
58  }
59 
60  private:
62 };
63 
64 class HardwareDetection {
65  public:
66  HardwareDetection() : m_found(false) {}
67  OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx) {
68 
69  std::cout << "PLUGIN: Got a hardware detection request" << std::endl;
70  if (!m_found) {
71  std::cout << "PLUGIN: We have detected our fake device! Doing "
72  "setup stuff!" << std::endl;
73  m_found = true;
74 
77  new DummyDevice(ctx));
78  }
79  return OSVR_RETURN_SUCCESS;
80  }
81 
82  private:
85  bool m_found;
86 };
87 } // namespace
88 
89 OSVR_PLUGIN(com_osvr_example_DummyDetectAndCreateAsync) {
91  osvrDeviceRegisterMessageType(ctx, "DummyMessage", &dummyMessage);
92 
93  osvr::pluginkit::PluginContext context(ctx);
94 
96  context.registerHardwareDetectCallback(new HardwareDetection());
97 
98  return OSVR_RETURN_SUCCESS;
99 }
Wrapper class for OSVR_DeviceToken.
C++ wrapper class for the opaque plugin context.
Definition: PluginKit.h:59
Base class for connection-specific message type registration.
Definition: MessageType.h:38
void registerHardwareDetectCallback(T functor)
Register a hardware detect callback.
Definition: PluginKit.h:70
T * registerObjectForDeletion(OSVR_PluginRegContext ctx, T *obj)
Registers an object to be destroyed with delete when the plugin is unloaded.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
Header including the full PluginKit C++ interface.
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin's entry point and other locations of control flow transfer...
OSVR_ReturnCode osvrDeviceRegisterMessageType(OSVR_PluginRegContext ctx, const char *name, OSVR_MessageType *msgtype)
Register (or recall) a message type by name.
OSVR_PLUGIN(com_osvr_example_DummyDetectAndCreateAsync)