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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2008-03-23 21:42:49 UTC
  • mfrom: (3.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080323214249-evlfv3y1o8q747la
Tags: 2.4.6.1-2
* Bug fix: "FTBFS with GCC 4.3: missing #includes", thanks to Martin
  Michlmayr (Closes: #454890).
- 13_gcc4: updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// eca-control-base.cpp: Base class providing basic functionality
3
3
//                       for controlling the ecasound library
4
 
// Copyright (C) 1999-2004 Kai Vehmanen
 
4
// Copyright (C) 1999-2004,2006 Kai Vehmanen
5
5
//
6
6
// Attributes:
7
7
//     eca-style-version: 3
106
106
 * @pre is_connected() == true
107
107
 * @pre is_running() != true
108
108
 * @post is_engine_started() == true
 
109
 *
 
110
 * @return negative on error, zero on success 
109
111
 */
110
 
void ECA_CONTROL_BASE::start(void)
 
112
int ECA_CONTROL_BASE::start(void)
111
113
{
112
114
  // --------
113
115
  DBC_REQUIRE(is_connected() == true);
114
116
  DBC_REQUIRE(is_running() != true);
115
117
  // --------
 
118
  
 
119
  int result = 0;
116
120
 
117
121
  ECA_LOG_MSG(ECA_LOGGER::subsystems, "Controller/Processing started");
118
122
 
123
127
 
124
128
  if (is_engine_started() != true) {
125
129
    ECA_LOG_MSG(ECA_LOGGER::info, "Can't start processing: couldn't start engine.");
126
 
    return;
 
130
    result = -1;
127
131
  }  
128
 
 
129
 
  engine_repp->command(ECA_ENGINE::ep_start, 0.0);
130
 
 
131
 
  // --------
132
 
  DBC_ENSURE(is_engine_started() == true);
133
 
  // --------
 
132
  else {
 
133
    engine_repp->command(ECA_ENGINE::ep_start, 0.0);
 
134
  }
 
135
 
 
136
  // --------
 
137
  DBC_ENSURE(result != 0 || is_engine_started() == true);
 
138
  // --------
 
139
 
 
140
  return result;
134
141
}
135
142
 
136
143
/**
148
155
 *       (is_engine_started() != true ||
149
156
 *        is_engine_started() == true &&
150
157
 *        engine_repp->status() != ECA_ENGINE::engine_status_stopped))
 
158
 *
 
159
 * @return negative on error, zero on success 
151
160
 */
152
 
void ECA_CONTROL_BASE::run(bool batchmode)
 
161
int ECA_CONTROL_BASE::run(bool batchmode)
153
162
{
154
163
  // --------
155
164
  DBC_REQUIRE(is_connected() == true);
159
168
  ECA_LOG_MSG(ECA_LOGGER::subsystems, "Controller/Starting batch processing");
160
169
 
161
170
  bool processing_started = false;
 
171
  int result = -1;
162
172
 
163
173
  if (is_engine_started() != true) {
164
174
    /* request_batchmode=true */
172
182
    engine_repp->command(ECA_ENGINE::ep_start, 0.0);
173
183
 
174
184
    DBC_CHECK(is_finished() != true);
 
185
    
 
186
    result = 0;
175
187
 
176
188
    /* run until processing is finished; in batchmode run forever (or
177
189
     * until error occurs) */
191
203
          if (engine_repp->status() == ECA_ENGINE::engine_status_error) {
192
204
            /* not running, so status() is either 'not_ready' or 'error' */
193
205
            ECA_LOG_MSG(ECA_LOGGER::info, "Can't start processing: engine startup failed. (3)");
 
206
            result = -2;
194
207
            break;
195
208
          }
196
209
          /* other valid state alternatives: */
199
212
        }
200
213
        else {
201
214
          /* ECA_CONTROL_BASE destructor has been run and 
202
 
           * engine_repp is now 0 (--> is_engine_start() != true) */
 
215
           * engine_repp is now 0 (--> is_engine_started() != true) */
203
216
          break;
204
217
        }
205
218
      }
214
227
    }
215
228
  }    
216
229
 
217
 
  ECA_LOG_MSG(ECA_LOGGER::subsystems, "Controller/Batch processing finished");
 
230
  if (last_exec_res_rep < 0) {
 
231
    /* error occured during processing */
 
232
    result = -3;
 
233
  }
218
234
 
 
235
  ECA_LOG_MSG(ECA_LOGGER::subsystems, 
 
236
              std::string("Controller/Batch processing finished (")
 
237
              + kvu_numtostr(result) + ")");
 
238
  
219
239
  // --------
220
240
  DBC_ENSURE(is_finished() == true ||
221
241
             processing_started == true && is_running() != true ||
224
244
              is_engine_started() == true &&
225
245
              engine_repp->status() != ECA_ENGINE::engine_status_stopped));
226
246
  // --------
 
247
 
 
248
  return result;
227
249
}
228
250
 
229
251
/**
324
346
 */
325
347
void ECA_CONTROL_BASE::run_engine(void)
326
348
{
327
 
  engine_repp->exec(req_batchmode_rep);
 
349
  last_exec_res_rep = 0;
 
350
  last_exec_res_rep = engine_repp->exec(req_batchmode_rep);
328
351
  engine_exited_rep.set(1); 
329
352
}
330
353
 
340
363
 
341
364
  engine_repp->command(ECA_ENGINE::ep_exit, 0.0);
342
365
 
343
 
 // --
344
 
  // wait until run_engine() is finished
 
366
  ECA_LOG_MSG(ECA_LOGGER::system_objects, "Waiting for engine thread to exit.");
345
367
  pthread_join(th_cqueue_rep,NULL);
346
368
 
347
369
  if (engine_exited_rep.get() == 1) {
 
370
    ECA_LOG_MSG(ECA_LOGGER::system_objects, "Engine thread has exited succesfully.");
348
371
    delete engine_repp;
349
372
    engine_repp = 0;
350
373
    engine_exited_rep.set(0);