1
// ------------------------------------------------------------------------
2
// eca-control-mt.h: ECA_CONTROL_MT class implementation
3
// Copyright (C) 2009 Kai Vehmanen
6
// eca-style-version: 3
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
13
// This program is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
// ------------------------------------------------------------------------
22
#include "eca-control-mt.h"
23
#include "eca-control.h"
25
ECA_CONTROL_MT::ECA_CONTROL_MT(ECA_SESSION* psession)
27
pthread_mutexattr_t mutex_attr;
28
pthread_mutexattr_init(&mutex_attr);
29
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
30
pthread_mutex_init(&mutex_rep, &mutex_attr);
31
ec_repp = new ECA_CONTROL(psession);
34
ECA_CONTROL_MT::~ECA_CONTROL_MT(void)
36
pthread_mutex_destroy(&mutex_rep);
40
void ECA_CONTROL_MT::lock_control(void)
42
pthread_mutex_lock(&mutex_rep);
45
void ECA_CONTROL_MT::unlock_control(void)
47
pthread_mutex_unlock(&mutex_rep);
50
void ECA_CONTROL_MT::engine_start(void)
52
pthread_mutex_lock(&mutex_rep);
53
ec_repp->engine_start();
54
pthread_mutex_unlock(&mutex_rep);
57
int ECA_CONTROL_MT::start(void)
60
pthread_mutex_lock(&mutex_rep);
61
res = ec_repp->start();
62
pthread_mutex_unlock(&mutex_rep);
66
void ECA_CONTROL_MT::stop(void)
68
pthread_mutex_lock(&mutex_rep);
70
pthread_mutex_unlock(&mutex_rep);
73
void ECA_CONTROL_MT::stop_on_condition(void)
75
pthread_mutex_lock(&mutex_rep);
76
ec_repp->stop_on_condition();
77
pthread_mutex_unlock(&mutex_rep);
80
int ECA_CONTROL_MT::run(bool batchmode)
83
pthread_mutex_lock(&mutex_rep);
84
res = ec_repp->run(batchmode);
85
pthread_mutex_unlock(&mutex_rep);
89
void ECA_CONTROL_MT::quit(void)
91
pthread_mutex_lock(&mutex_rep);
93
pthread_mutex_unlock(&mutex_rep);
96
void ECA_CONTROL_MT::quit_async(void)
98
/* note: does not need locking! */
99
ec_repp->quit_async();
102
bool ECA_CONTROL_MT::is_running(void) const
104
/* note: thread-safe as the member function is thread-safe,
105
* but ordering across CPUs is not guaranteed (one
106
* might get stale data */
107
return ec_repp->is_running();
110
bool ECA_CONTROL_MT::is_connected(void) const
112
/* see note for is_running() */
113
return ec_repp->is_connected();
116
bool ECA_CONTROL_MT::is_selected(void) const
118
/* see note for is_running() */
119
return ec_repp->is_selected();
122
bool ECA_CONTROL_MT::is_finished(void) const
124
/* see note for is_running() */
125
return ec_repp->is_finished();
128
bool ECA_CONTROL_MT::is_valid(void) const
130
/* see note for is_running() */
131
return ec_repp->is_valid();
134
bool ECA_CONTROL_MT::is_engine_created(void) const
136
/* see note for is_running() */
137
return ec_repp->is_engine_created();
140
bool ECA_CONTROL_MT::is_engine_running(void) const
142
/* see note for is_running() */
143
return ec_repp->is_engine_running();
146
const ECA_CHAINSETUP* ECA_CONTROL_MT::get_connected_chainsetup(void) const
148
/* note: locking even though this is const */
149
const ECA_CHAINSETUP* res;
150
pthread_mutex_lock(&mutex_rep);
151
res = ec_repp->get_connected_chainsetup();
152
pthread_mutex_unlock(&mutex_rep);
157
void ECA_CONTROL_MT::connect_chainsetup(struct eci_return_value *retval)
159
pthread_mutex_lock(&mutex_rep);
160
ec_repp->connect_chainsetup(retval);
161
pthread_mutex_unlock(&mutex_rep);
164
void ECA_CONTROL_MT::disconnect_chainsetup(void)
166
pthread_mutex_lock(&mutex_rep);
167
ec_repp->disconnect_chainsetup();
168
pthread_mutex_unlock(&mutex_rep);
171
bool ECA_CONTROL_MT::execute_edit_on_connected(const ECA::chainsetup_edit_t& edit)
174
pthread_mutex_lock(&mutex_rep);
175
res = ec_repp->execute_edit_on_connected(edit);
176
pthread_mutex_unlock(&mutex_rep);
180
bool ECA_CONTROL_MT::execute_edit_on_selected(const ECA::chainsetup_edit_t& edit, int index)
183
pthread_mutex_lock(&mutex_rep);
184
res = ec_repp->execute_edit_on_selected(edit);
185
pthread_mutex_unlock(&mutex_rep);
189
void ECA_CONTROL_MT::command(const std::string& cmd_and_args, struct eci_return_value *retval)
191
pthread_mutex_lock(&mutex_rep);
192
ec_repp->command(cmd_and_args, retval);
193
pthread_mutex_unlock(&mutex_rep);
197
void ECA_CONTROL_MT::command_float_arg(const std::string& cmd, double arg, struct eci_return_value *retval)
199
pthread_mutex_lock(&mutex_rep);
200
ec_repp->command_float_arg(cmd, arg, retval);
201
pthread_mutex_unlock(&mutex_rep);
204
void ECA_CONTROL_MT::print_last_value(struct eci_return_value *retval) const
206
/* note: a const function that only depends on 'retval', so
208
ec_repp->print_last_value(retval);