OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ClientMainloop.h
Go to the documentation of this file.
1 
12 // Copyright 2015 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 #ifndef INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE
27 #define INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE
28 
29 // Internal Includes
31 
32 // Library/third-party includes
33 #include <boost/noncopyable.hpp>
34 #include <boost/thread/recursive_mutex.hpp>
35 #include <boost/thread/locks.hpp>
36 
37 // Standard includes
38 // - none
39 
42 class ClientMainloop : boost::noncopyable {
43  public:
44  typedef boost::recursive_mutex mutex_type;
45  typedef boost::unique_lock<mutex_type> lock_type;
47  void mainloop() {
48  lock_type lock(m_mutex, boost::try_to_lock);
49  if (lock) {
50  m_ctx.update();
51  }
52  }
53  mutex_type &getMutex() { return m_mutex; }
54 
55  private:
57  mutex_type m_mutex;
58 };
59 
60 #endif // INCLUDED_ClientMainloop_h_GUID_CE5D82DA_5A69_46A0_55BA_BE9DB68B61CE
Client context object: Create and keep one in your application. Handles lifetime management and provi...
Definition: Context_decl.h:57
Header.
Simple class to handle running a client mainloop in another thread, but easily pausable.
void update()
Updates the state of the context - call regularly in your mainloop.
Definition: Context.h:54