~ubuntu-branches/ubuntu/lucid/ecasound2.2/lucid

« back to all changes in this revision

Viewing changes to libecasound/eca-control-mt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2009-11-02 18:22:35 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091102182235-4ngh7699dmkgonyu
Tags: 2.7.0-1
* New upstream release.
* Depend on libreadline-dev instead of libreadline5-dev by request of
  Mattias Klose. It's now libreadline6-dev. (closes: #553748)
* Update menu file to use section Applications/ instead of Apps/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ------------------------------------------------------------------------
 
2
// eca-control-mt.h: ECA_CONTROL_MT class implementation
 
3
// Copyright (C) 2009 Kai Vehmanen
 
4
//
 
5
// Attributes:
 
6
//     eca-style-version: 3
 
7
//
 
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.
 
12
// 
 
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.
 
17
// 
 
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
// ------------------------------------------------------------------------
 
21
 
 
22
#include "eca-control-mt.h"
 
23
#include "eca-control.h"
 
24
 
 
25
ECA_CONTROL_MT::ECA_CONTROL_MT(ECA_SESSION* psession)
 
26
{
 
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);
 
32
}
 
33
 
 
34
ECA_CONTROL_MT::~ECA_CONTROL_MT(void)
 
35
{
 
36
  pthread_mutex_destroy(&mutex_rep);
 
37
  delete ec_repp;
 
38
}
 
39
 
 
40
void ECA_CONTROL_MT::lock_control(void)
 
41
{
 
42
  pthread_mutex_lock(&mutex_rep);
 
43
}
 
44
 
 
45
void ECA_CONTROL_MT::unlock_control(void)
 
46
{
 
47
  pthread_mutex_unlock(&mutex_rep);
 
48
}
 
49
 
 
50
void ECA_CONTROL_MT::engine_start(void)
 
51
{
 
52
  pthread_mutex_lock(&mutex_rep);
 
53
  ec_repp->engine_start();
 
54
  pthread_mutex_unlock(&mutex_rep);
 
55
}
 
56
 
 
57
int ECA_CONTROL_MT::start(void)
 
58
{
 
59
  int res;
 
60
  pthread_mutex_lock(&mutex_rep);
 
61
  res = ec_repp->start();
 
62
  pthread_mutex_unlock(&mutex_rep);
 
63
  return res;
 
64
}
 
65
 
 
66
void ECA_CONTROL_MT::stop(void)
 
67
{
 
68
  pthread_mutex_lock(&mutex_rep);
 
69
  ec_repp->stop();
 
70
  pthread_mutex_unlock(&mutex_rep);
 
71
}
 
72
 
 
73
void ECA_CONTROL_MT::stop_on_condition(void)
 
74
{
 
75
  pthread_mutex_lock(&mutex_rep);
 
76
  ec_repp->stop_on_condition();
 
77
  pthread_mutex_unlock(&mutex_rep);
 
78
}
 
79
 
 
80
int ECA_CONTROL_MT::run(bool batchmode)
 
81
{
 
82
  int res;
 
83
  pthread_mutex_lock(&mutex_rep);
 
84
  res = ec_repp->run(batchmode);
 
85
  pthread_mutex_unlock(&mutex_rep);
 
86
  return res;
 
87
}
 
88
 
 
89
void ECA_CONTROL_MT::quit(void)
 
90
{
 
91
  pthread_mutex_lock(&mutex_rep);
 
92
  ec_repp->quit();
 
93
  pthread_mutex_unlock(&mutex_rep);
 
94
}
 
95
 
 
96
void ECA_CONTROL_MT::quit_async(void)
 
97
{
 
98
  /* note: does not need locking! */
 
99
  ec_repp->quit_async();
 
100
}
 
101
 
 
102
bool ECA_CONTROL_MT::is_running(void) const
 
103
{
 
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();
 
108
}
 
109
 
 
110
bool ECA_CONTROL_MT::is_connected(void) const
 
111
{
 
112
  /* see note for is_running() */
 
113
  return ec_repp->is_connected();
 
114
}
 
115
 
 
116
bool ECA_CONTROL_MT::is_selected(void) const
 
117
{
 
118
  /* see note for is_running() */
 
119
  return ec_repp->is_selected();
 
120
}
 
121
 
 
122
bool ECA_CONTROL_MT::is_finished(void) const
 
123
{
 
124
  /* see note for is_running() */
 
125
  return ec_repp->is_finished();
 
126
}
 
127
 
 
128
bool ECA_CONTROL_MT::is_valid(void) const
 
129
{
 
130
  /* see note for is_running() */
 
131
  return ec_repp->is_valid();
 
132
}
 
133
 
 
134
bool ECA_CONTROL_MT::is_engine_created(void) const
 
135
{
 
136
  /* see note for is_running() */
 
137
  return ec_repp->is_engine_created();
 
138
}
 
139
 
 
140
bool ECA_CONTROL_MT::is_engine_running(void) const
 
141
{
 
142
  /* see note for is_running() */
 
143
  return ec_repp->is_engine_running();
 
144
}
 
145
 
 
146
const ECA_CHAINSETUP* ECA_CONTROL_MT::get_connected_chainsetup(void) const
 
147
{
 
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);
 
153
  return res;
 
154
}
 
155
 
 
156
 
 
157
void ECA_CONTROL_MT::connect_chainsetup(struct eci_return_value *retval)
 
158
{
 
159
  pthread_mutex_lock(&mutex_rep);
 
160
  ec_repp->connect_chainsetup(retval);
 
161
  pthread_mutex_unlock(&mutex_rep);
 
162
}
 
163
 
 
164
void ECA_CONTROL_MT::disconnect_chainsetup(void)
 
165
{
 
166
  pthread_mutex_lock(&mutex_rep);
 
167
  ec_repp->disconnect_chainsetup();
 
168
  pthread_mutex_unlock(&mutex_rep);
 
169
}
 
170
 
 
171
bool ECA_CONTROL_MT::execute_edit_on_connected(const ECA::chainsetup_edit_t& edit)
 
172
{
 
173
  bool res;
 
174
  pthread_mutex_lock(&mutex_rep);
 
175
  res = ec_repp->execute_edit_on_connected(edit);
 
176
  pthread_mutex_unlock(&mutex_rep);
 
177
  return res;
 
178
}
 
179
 
 
180
bool ECA_CONTROL_MT::execute_edit_on_selected(const ECA::chainsetup_edit_t& edit, int index)
 
181
{
 
182
  bool res;
 
183
  pthread_mutex_lock(&mutex_rep);
 
184
  res = ec_repp->execute_edit_on_selected(edit);
 
185
  pthread_mutex_unlock(&mutex_rep);
 
186
  return res;
 
187
}
 
188
 
 
189
void ECA_CONTROL_MT::command(const std::string& cmd_and_args, struct eci_return_value *retval)
 
190
{
 
191
  pthread_mutex_lock(&mutex_rep);
 
192
  ec_repp->command(cmd_and_args, retval);
 
193
  pthread_mutex_unlock(&mutex_rep);
 
194
}
 
195
 
 
196
 
 
197
void ECA_CONTROL_MT::command_float_arg(const std::string& cmd, double arg, struct eci_return_value *retval)
 
198
{
 
199
  pthread_mutex_lock(&mutex_rep);
 
200
  ec_repp->command_float_arg(cmd, arg, retval);
 
201
  pthread_mutex_unlock(&mutex_rep);
 
202
}
 
203
 
 
204
void ECA_CONTROL_MT::print_last_value(struct eci_return_value *retval) const
 
205
{
 
206
  /* note: a const function that only depends on 'retval', so 
 
207
   *       this is safe */
 
208
  ec_repp->print_last_value(retval);
 
209
}