OSVR-Core
NetworkClassOfService.h
Go to the documentation of this file.
1 
11 // Copyright 2015 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_NetworkClassOfService_h_GUID_5B1253E0_C690_4891_5C84_3F713099B8BE
26 #define INCLUDED_NetworkClassOfService_h_GUID_5B1253E0_C690_4891_5C84_3F713099B8BE
27 
28 // Internal Includes
29 #include <osvr/Util/StdInt.h>
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <type_traits>
36 #include <stddef.h>
37 
38 namespace osvr {
39 namespace common {
42  namespace class_of_service {
51  struct Reliable;
52 
56  struct FixedLatency;
57 
66  struct LowLatency;
67 
71  struct FixedThroughput;
72 
76  struct HighThroughput;
77 
81  template <typename ClassOfService> struct ClassOfServiceBase;
82 
85  template <typename T> struct IsClassOfService;
86 
88  template <typename ClassOfService>
90 
95  template <typename ClassOfService> struct VRPNConnectionValue;
96 
97  template <>
99  : std::integral_constant<uint32_t, (1 << 0)> {};
100  template <>
101  struct VRPNConnectionValue<FixedLatency>
102  : std::integral_constant<uint32_t, (1 << 1)> {};
103  template <>
104  struct VRPNConnectionValue<LowLatency>
105  : std::integral_constant<uint32_t, (1 << 2)> {};
106  template <>
107  struct VRPNConnectionValue<FixedThroughput>
108  : std::integral_constant<uint32_t, (1 << 3)> {};
109  template <>
110  struct VRPNConnectionValue<HighThroughput>
111  : std::integral_constant<uint32_t, (1 << 4)> {};
112 
113  /* -----implementation follows----- */
114 
116  namespace detail {
118  struct ClassOfServiceRoot {
119  protected:
120  ClassOfServiceRoot() = default;
121  };
122 
123  template <typename SpecificClass> struct GetMessageSizeLimit {
124  static size_t get();
125  };
126  } // namespace detail
127 
128  template <typename ClassOfService>
129  struct ClassOfServiceBase : detail::ClassOfServiceRoot {
130  typedef ClassOfService type;
131  typedef ClassOfServiceBase<ClassOfService> base_type;
132  ClassOfServiceBase();
133  };
134  struct Reliable : ClassOfServiceBase<Reliable> {};
135 
136  struct FixedLatency : ClassOfServiceBase<FixedLatency> {};
137 
138  struct LowLatency : ClassOfServiceBase<LowLatency> {};
139 
140  struct FixedThroughput : ClassOfServiceBase<FixedThroughput> {};
141 
142  struct HighThroughput : ClassOfServiceBase<HighThroughput> {};
143 
144  template <typename T>
145  struct IsClassOfService
146  : std::is_base_of<detail::ClassOfServiceRoot, T> {};
147 
148  template <typename ClassOfService>
149  inline size_t
150  getMessageSizeLimit(ClassOfServiceBase<ClassOfService> const &) {
151  return detail::GetMessageSizeLimit<ClassOfService>::get();
152  }
153 
158  template <typename ClassOfService>
159  inline ClassOfServiceBase<ClassOfService>::ClassOfServiceBase() {
166  static_assert(std::is_base_of<base_type, type>::value,
167  "ClassOfServiceBase<T> must be the base of a class "
168  "of service type T (the CRTP)!");
169  }
170 
171  } // namespace class_of_service
172 } // namespace common
173 } // namespace osvr
174 #endif // INCLUDED_NetworkClassOfService_h_GUID_5B1253E0_C690_4891_5C84_3F713099B8BE
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Definition: NetworkClassOfService.h:134
Header wrapping the C99 standard stdint header.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
CRTP base for classes of service, useful for accepting classes of service for an argument without let...
Definition: NetworkClassOfService.h:81
Definition: NetworkClassOfService.h:142
size_t getMessageSizeLimit(ClassOfServiceBase< ClassOfService > const &)
Given a class of service, returns a m.
Definition: NetworkClassOfService.h:150
Association of class of service types with integral constants.
Definition: NetworkClassOfService.h:95
Definition: NetworkClassOfService.h:138
Definition: NetworkClassOfService.h:140
Type trait like std::is_base_of indicating whether the given type is a recognized class of service...
Definition: NetworkClassOfService.h:85
Definition: NetworkClassOfService.h:136