Jack2  1.9.10
JackWaitThreadedDriver.cpp
00001 /*
00002  Copyright (C) 2001 Paul Davis
00003  Copyright (C) 2004-2008 Grame
00004 
00005  This program is free software; you can redistribute it and/or modify
00006  it under the terms of the GNU General Public License as published by
00007  the Free Software Foundation; either version 2 of the License, or
00008  (at your option) any later version.
00009 
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  GNU General Public License for more details.
00014 
00015  You should have received a copy of the GNU General Public License
00016  along with this program; if not, write to the Free Software
00017  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #include "JackSystemDeps.h"
00022 #include "JackWaitThreadedDriver.h"
00023 #include "JackGlobals.h"
00024 #include "JackClient.h"
00025 #include "JackEngineControl.h"
00026 #include "JackException.h"
00027 #include "JackError.h"
00028 #include "JackTools.h"
00029 
00030 namespace Jack
00031 {
00032 
00033 bool JackWaitThreadedDriver::Init()
00034 {
00035     return (fStarter.Start() == 0);
00036 }
00037 
00038 bool JackWaitThreadedDriver::Execute()
00039 {
00040     try {
00041 
00042         SetRealTime();
00043 
00044         // Process a null cycle until NetDriver has started
00045         while (!fStarter.fRunning && fThread.GetStatus() == JackThread::kRunning) {
00046             // Use base class method
00047             assert(static_cast<JackWaiterDriver*>(fDriver));
00048             static_cast<JackWaiterDriver*>(fDriver)->ProcessNull();
00049         }
00050 
00051         // Switch to keep running even in case of error
00052         while (fThread.GetStatus() == JackThread::kRunning) {
00053             fDriver->Process();
00054         }
00055 
00056         return false;
00057 
00058     } catch (JackNetException& e) {
00059 
00060         e.PrintMessage();
00061         jack_info("Driver is restarted");
00062         fThread.DropSelfRealTime();
00063 
00064         // Thread has been stopped...
00065         if (fThread.GetStatus() == JackThread::kIdle) {
00066             return false;
00067         }
00068 
00069         // Thread in kIniting status again...
00070         fThread.SetStatus(JackThread::kIniting);
00071         if (Init()) {
00072             // Thread in kRunning status again...
00073             fThread.SetStatus(JackThread::kRunning);
00074             return true;
00075         }
00076 
00077         return false;
00078     }
00079 }
00080 
00081 } // end of namespace