OSVR-Core
VrpnBaseFlexServer.h
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 #ifndef INCLUDED_VrpnBaseFlexServer_h_GUID_BA2E66A9_F0F3_4BBE_5248_62C5B7E5CBDE
26 #define INCLUDED_VrpnBaseFlexServer_h_GUID_BA2E66A9_F0F3_4BBE_5248_62C5B7E5CBDE
27 
28 // Internal Includes
29 #include "DeviceConstructionData.h"
30 #include <osvr/Common/BaseDevice.h>
31 #include <osvr/Util/Verbosity.h>
32 #include <osvr/Util/TimeValue.h>
33 
34 // Library/third-party includes
35 #include <vrpn_BaseClass.h>
36 
37 // Standard includes
38 // - none
39 
40 namespace osvr {
41 namespace connection {
43  class vrpn_BaseFlexServer : public vrpn_BaseClass,
44  public common::BaseDevice {
45  public:
47  : vrpn_BaseClass(init.getQualifiedName().c_str(), init.conn) {
48  vrpn_BaseClass::init();
49  init.flexServer = this;
50  m_setup(vrpn_ConnectionPtr(init.conn),
51  common::RawSenderType(d_sender_id),
52  init.getQualifiedName());
53  }
54  virtual ~vrpn_BaseFlexServer() {}
55 
56  virtual void mainloop() {
59 
61  update();
62 
63  server_mainloop();
64  }
65  void sendData(util::time::TimeValue const &timestamp, vrpn_uint32 msgID,
66  const char *bytestream, size_t len) {
67  struct timeval now;
68  util::time::toStructTimeval(now, timestamp);
69  d_connection->pack_message(len, now, msgID, d_sender_id, bytestream,
70  vrpn_CONNECTION_LOW_LATENCY);
71  }
72 
73  protected:
74  virtual int register_types() { return 0; }
75  virtual void m_update() {
76  // can be empty since we handle things in mainloop above.
77  }
78  };
79 } // namespace connection
80 } // namespace osvr
81 #endif // INCLUDED_VrpnBaseFlexServer_h_GUID_BA2E66A9_F0F3_4BBE_5248_62C5B7E5CBDE
Basic implementation of a vrpn_BaseClass server.
Definition: VrpnBaseFlexServer.h:43
Class used as an interface for underlying devices that can have device components (corresponding to i...
Definition: BaseDevice.h:51
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
virtual void m_update()
Implementation-specific update (call client_mainloop() or server_mainloop() in it!) ...
Definition: VrpnBaseFlexServer.h:75
Definition: DeviceConstructionData.h:41
OSVR_COMMON_EXPORT void m_setup(vrpn_ConnectionPtr conn, RawSenderType sender, std::string const &name)
Should be called by derived class to set the connection, etc.
Definition: BaseDevice.cpp:106
OSVR_COMMON_EXPORT void update()
Called from the outside to run the mainloop on the device and its components.
Definition: BaseDevice.cpp:79
Header providing a C++ wrapper around TimeValueC.h.
Header.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
Type-safe wrapper with built-in default for a VRPN "sender type" integer.
Definition: RawSenderType.h:45
virtual void mainloop()
Definition: VrpnBaseFlexServer.h:56