-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisp.cc
73 lines (51 loc) · 1.31 KB
/
disp.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <thread>
#include <Poco/Logger.h>
#include "disp.h"
using namespace vid;
using Poco::Logger;
void
Dispatcher::run(bool should_join)
{
using namespace std;
typedef size_t (ba::io_service::*IORunMethodPtr)();
// using namespace boost::asio;
Logger &dlog = Logger::get("dbg-connect");
int ncores = thread::hardware_concurrency();
poco_warning_f1( dlog, "Number of cores (by lib) => %d", ncores);
if (ncores <= 1) {
ncores = DEFAULT_IO_THREADS_NUMBER; // 2 threads default value
}
thrs.reserve(ncores);
generate_n(back_inserter(thrs), ncores,
[&, this] ()
{
poco_warning(dlog, "Starting thread...");
return ThreadSPtr( new thread(std::bind( static_cast<IORunMethodPtr>(&ba::io_service::run), &this->io) ) );
}
);
if (should_join)
wait();
}
void
Dispatcher::wait()
{
std::for_each(begin(thrs), end(thrs),
[&] (ThreadSPtr t) { t->join(); } );
}
void
Dispatcher::add_camera(const std::string &name, CameraSPtr cam)
{
CamerasMap::iterator f = cams.find(name);
if (f == cams.end() || f->second != cam) {
cams.insert(make_pair(name,cam));
}
}
void
Dispatcher::bind(IView::pointer view, const std::string &cname, const std::string &sname)
{
// TODO!
}