Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / common / JackWaitThreadedDriver.cpp
blob09c2cae45a6fd57380ac91c158384666652e4a80
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 "JackWaitThreadedDriver.h"
23 #include "JackGlobals.h"
24 #include "JackClient.h"
25 #include "JackEngineControl.h"
26 #include "JackException.h"
27 #include "JackError.h"
28 #include "JackTools.h"
30 namespace Jack
33 bool JackWaitThreadedDriver::Init()
35 return (fStarter.Start() == 0);
38 bool JackWaitThreadedDriver::Execute()
40 try {
42 SetRealTime();
44 // Process a null cycle until NetDriver has started
45 while (!fStarter.fRunning && fThread.GetStatus() == JackThread::kRunning) {
46 // Use base class method
47 assert(static_cast<JackWaiterDriver*>(fDriver));
48 static_cast<JackWaiterDriver*>(fDriver)->ProcessNull();
51 // Switch to keep running even in case of error
52 while (fThread.GetStatus() == JackThread::kRunning) {
53 fDriver->Process();
56 return false;
58 } catch (JackNetException& e) {
60 e.PrintMessage();
61 jack_info("Driver is restarted");
62 fThread.DropSelfRealTime();
64 // Thread has been stopped...
65 if (fThread.GetStatus() == JackThread::kIdle) {
66 return false;
69 // Thread in kIniting status again...
70 fThread.SetStatus(JackThread::kIniting);
71 if (Init()) {
72 // Thread in kRunning status again...
73 fThread.SetStatus(JackThread::kRunning);
74 return true;
77 return false;
81 } // end of namespace