Jack2  1.9.8
JackFreewheelDriver.cpp
1 /*
2  Copyright (C) 2001 Paul Davis
3  Copyright (C) 2004-2008 Grame
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 #include "JackSystemDeps.h"
22 #include "JackFreewheelDriver.h"
23 #include "JackEngineControl.h"
24 #include "JackLockedEngine.h"
25 
26 namespace Jack
27 {
28 
29 // When used in "master" mode
30 
31 int JackFreewheelDriver::Process()
32 {
33  int res = 0;
34 
35  jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs);
36  JackDriver::CycleTakeBeginTime();
37 
38  if (fEngine->Process(fBeginDateUst, fEndDateUst)) {
39 
40  if (ResumeRefNum()) { // Signal all clients
41  jack_error("JackFreewheelDriver::Process: ResumeRefNum error");
42  res = -1;
43  }
44 
45  // Special "SuspendRefNum" with longer timeout
46  if (SuspendRefNum() < 0) { // Wait for all clients to finish for 10 sec
47  jack_error("JackFreewheelDriver::ProcessSync: SuspendRefNum error");
48  /* We have a client time-out error, but still continue to process, until a better recovery strategy is chosen */
49  return 0;
50  }
51 
52  } else { // Graph not finished: do not activate it
53  jack_error("JackFreewheelDriver::Process: Process error");
54  res = -1;
55  }
56 
57  return res;
58 }
59 
60 // When used in "slave" mode
61 
62 int JackFreewheelDriver::ProcessReadSync()
63 {
64  if (ResumeRefNum() < 0) { // Signal all clients
65  jack_error("JackFreewheelDriver::ProcessReadSync: ResumeRefNum error");
66  return -1;
67  }
68  return 0;
69 }
70 
71 int JackFreewheelDriver::ProcessWriteSync()
72 {
73  // Generic "SuspendRefNum" here
74  if (JackDriver::SuspendRefNum() < 0) {
75  jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error");
76  return -1;
77  }
78  return 0;
79 }
80 
81 int JackFreewheelDriver::ProcessReadAsync()
82 {
83  if (ResumeRefNum() < 0) { // Signal all clients
84  jack_error("JackFreewheelDriver::ProcessReadAsync: ResumeRefNum error");
85  return -1;
86  }
87  return 0;
88 }
89 
90 int JackFreewheelDriver::ProcessWriteAsync()
91 {
92  return 0;
93 }
94 
95 int JackFreewheelDriver::SuspendRefNum()
96 {
97  return fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, FREEWHEEL_DRIVER_TIMEOUT * 1000000);
98 }
99 
100 } // end of namespace