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