merge new MTDM code from Fons' latest release.
[jack2.git] / common / JackFreewheelDriver.cpp
blobd0234f3b70a27301bbf24ae76d763b0f36ba60bd
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "JackSystemDeps.h"
22 #include "JackFreewheelDriver.h"
23 #include "JackEngineControl.h"
24 #include "JackLockedEngine.h"
26 namespace Jack
29 // When used in "master" mode
31 int JackFreewheelDriver::Process()
33 int res = 0;
35 jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs);
36 JackDriver::CycleTakeBeginTime();
38 if (fEngine->Process(fBeginDateUst, fEndDateUst)) {
40 // Resume connected clients in the graph
41 if (ResumeRefNum()) {
42 jack_error("JackFreewheelDriver::Process: ResumeRefNum error");
43 res = -1;
46 // Special "SuspendRefNum" with longer timeout
47 if (SuspendRefNum() < 0) { // Wait for all clients to finish for 10 sec
48 jack_error("JackFreewheelDriver::ProcessSync: SuspendRefNum error");
49 /* We have a client time-out error, but still continue to process, until a better recovery strategy is chosen */
50 return 0;
53 } else { // Graph not finished: do not activate it
54 jack_error("JackFreewheelDriver::Process: Process error");
55 res = -1;
58 return res;
61 // When used in "slave" mode
63 int JackFreewheelDriver::ProcessReadSync()
65 // Resume connected clients in the graph
66 if (ResumeRefNum() < 0) { // Signal all clients
67 jack_error("JackFreewheelDriver::ProcessReadSync: ResumeRefNum error");
68 return -1;
70 return 0;
73 int JackFreewheelDriver::ProcessWriteSync()
75 // Generic "SuspendRefNum" here
76 if (JackDriver::SuspendRefNum() < 0) {
77 jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error");
78 return -1;
80 return 0;
83 int JackFreewheelDriver::ProcessReadAsync()
85 // Resume connected clients in the graph
86 if (ResumeRefNum() < 0) { // Signal all clients
87 jack_error("JackFreewheelDriver::ProcessReadAsync: ResumeRefNum error");
88 return -1;
90 return 0;
93 int JackFreewheelDriver::ProcessWriteAsync()
95 return 0;
98 int JackFreewheelDriver::SuspendRefNum()
100 return fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, FREEWHEEL_DRIVER_TIMEOUT * 1000000);
103 } // end of namespace