Robot Raconteur Core C++ Library
RobotRaconteurEmscripten.h
1 #pragma once
2 
3 #include <boost/date_time/posix_time/ptime.hpp>
4 #include <boost/function.hpp>
5 #include <boost/system/error_code.hpp>
6 
7 namespace RobotRaconteur
8 {
9 class WallTimer;
10 }
11 
12 namespace boost
13 {
14 template <typename T>
15 class null_lock
16 {
17  public:
18  null_lock() {}
19  template <typename U>
20  null_lock(U& u)
21  {}
22  void lock() {}
23  void unlock() {}
24 
25  template <typename U>
26  void swap(U& l)
27  {}
28 };
29 
30 template <typename T>
31 using unique_lock = null_lock<T>;
32 template <typename T>
33 using shared_lock = null_lock<T>;
34 template <typename T>
35 using upgrade_lock = null_lock<T>;
36 template <typename T>
37 using upgrade_to_unique_lock = null_lock<T>;
38 
39 class null_mutex
40 {
41  public:
42  null_mutex() {}
43 
44  void lock() {}
45  void notify_all() {}
46  void unlock() {}
47  void notify_one() {}
48 
49  template <typename U>
50  void wait(U& u)
51  {
52  throw std::runtime_error("Operation requires threading");
53  }
54 
55  template <typename U, typename V>
56  void timed_wait(U& u, V v)
57  {
58  throw std::runtime_error("Operation requires threading");
59  }
60 
61  template <typename U, typename V>
62  void wait_for(U& u, V v)
63  {
64  throw std::runtime_error("Operation requires threading");
65  }
66 
67  typedef unique_lock<null_mutex> scoped_lock;
68 };
69 
70 typedef boost::null_mutex mutex;
71 typedef boost::null_mutex recursive_mutex;
72 typedef boost::null_mutex shared_mutex;
73 typedef boost::null_mutex condition_variable;
74 
75 namespace asio
76 {
77 class strand
78 {
79  public:
80  template <typename T>
81  strand(T& t)
82  {}
83 };
84 class io_service_work
85 {
86  public:
87  template <typename U>
88  io_service_work(U& u)
89  {}
90 };
91 class io_service
92 {
93  public:
94  typedef io_service_work work;
95  typedef strand strand;
96  void run_one() {}
97  bool stopped() { return false; }
98  void stop() {}
99  void post(boost::function<void()> f);
100 };
101 class deadline_timer
102 {
103  public:
104  deadline_timer(io_service& service);
105  deadline_timer(io_service& service, boost::posix_time::time_duration duration);
106  ~deadline_timer();
107  void expires_from_now(boost::posix_time::time_duration duration);
108  boost::posix_time::time_duration expires_from_now();
109  void expires_at(boost::posix_time::ptime duration);
110  void async_wait(boost::function<void(boost::system::error_code)> f);
111  void cancel();
112  void cancel(boost::system::error_code ec);
113  void wait();
114 
115  protected:
116  boost::shared_ptr<RobotRaconteur::WallTimer> timer;
117  double next_timeout;
118 };
119 } // namespace asio
120 
121 template <typename T>
122 class thread_specific_ptr
123 {
124  T* val_;
125 
126  public:
127  thread_specific_ptr() : val_(0) {}
128  thread_specific_ptr(T* val) : val_(val) {}
129 
130  void reset(T* val)
131  {
132  if (val_)
133  {
134  delete val_;
135  }
136  val_ = val;
137  }
138 
139  void reset() { reset(0); }
140 
141  T* get() { return val_; }
142 
143  T& operator*() { return *val_; }
144 };
145 
146 class thread
147 {
148  public:
149  thread() {}
150  template <typename U>
151  thread(U u)
152  {}
153 
154  void join() {}
155 };
156 
157 typedef boost::posix_time::ptime system_time;
158 
159 namespace this_thread
160 {
161 template <typename T>
162 static void sleep(T& t)
163 {
164  throw std::runtime_error("Operation requires threading");
165 }
166 
167 int get_id();
168 } // namespace this_thread
169 } // namespace boost
170 
171 #undef RR_BOOST_ASIO_STRAND_WRAP
172 #define RR_BOOST_ASIO_STRAND_WRAP(strand, f) (f)