debug.
[dcpomatic.git] / src / wx / cucumber_bridge.cc
1 /*
2     Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "cucumber_bridge.h"
23 #include "lib/nanomsg.h"
24 #include "lib/dcpomatic_assert.h"
25 #include <boost/ref.hpp>
26 #include <iostream>
27
28
29 using std::string;
30 using boost::optional;
31 using boost::bind;
32
33
34 CucumberBridge::CucumberBridge ()
35 {
36
37 }
38
39
40 void
41 CucumberBridge::listener ()
42 {
43         Nanomsg nanomsg (false);
44         nanomsg.send (CUCUMBER_BRIDGE_READY "\n", -1);
45
46         while (true) {
47                 auto message = nanomsg.receive (-1);
48                 if (!message) {
49                         continue;
50                 }
51
52                 std::cout << "CB receives " << *message << "\n";
53
54                 if (*message == CUCUMBER_BRIDGE_CLICK_BUTTON) {
55                         emit (bind(boost::ref(ClickButton), get_parameter(nanomsg)));
56                 } else if (*message == CUCUMBER_BRIDGE_SELECT_MENU) {
57                         emit (bind(boost::ref(SelectMenu), get_parameter(nanomsg)));
58                 } else if (*message == CUCUMBER_BRIDGE_TYPE) {
59                         emit (bind(boost::ref(Type), get_parameter(nanomsg)));
60                 } else if (*message == CUCUMBER_BRIDGE_ADD_CONTENT_FILE) {
61                         emit (bind(boost::ref(AddContentFile), get_parameter(nanomsg)));
62                 } else if (*message == CUCUMBER_BRIDGE_GET_CONTENT_LIST) {
63                         nanomsg.send (GetContentList()->c_str(), -1);
64                 }
65         }
66 }
67
68
69 string
70 CucumberBridge::get_parameter (Nanomsg& nanomsg)
71 {
72         auto p = nanomsg.receive (100);
73         DCPOMATIC_ASSERT (p);
74         return *p;
75 }
76
77
78 void
79 CucumberBridge::start ()
80 {
81         _thread = boost::thread(&CucumberBridge::listener, this);
82 }
83