JackThreadedDriver.cpp

00001 /*
00002  Copyright (C) 2001 Paul Davis 
00003  Copyright (C) 2004-2006 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 #ifdef WIN32 
00022 #pragma warning (disable : 4786)
00023 #endif
00024 
00025 #include "JackThreadedDriver.h"
00026 #include "JackError.h"
00027 #include "JackGlobals.h"
00028 #include "JackClient.h"
00029 #include "JackEngineControl.h"
00030 
00031 namespace Jack
00032 {
00033 
00034 JackThreadedDriver::JackThreadedDriver(JackDriverClient* driver)
00035 {
00036     fThread = JackGlobals::MakeThread(this);
00037     fDriver = driver;
00038 }
00039 
00040 JackThreadedDriver::~JackThreadedDriver()
00041 {
00042     delete fThread;
00043     delete fDriver;
00044 }
00045 
00046 int JackThreadedDriver::Start()
00047 {
00048     JackLog("JackThreadedDriver::Start\n");
00049     int res;
00050 
00051     if ((res = fDriver->Start()) < 0) {
00052         jack_error("Cannot start driver");
00053         return res;
00054     }
00055     if ((res = fThread->Start()) < 0) {
00056         jack_error("Cannot start thread");
00057         return res;
00058     }
00059 
00060     if (fDriver->IsRealTime()) {
00061         JackLog("JackThreadedDriver::Start IsRealTime\n");
00062         // Will do "something" on OSX only...
00063         // fThread->SetParams(fDriver->fEngineControl->fPeriod, fDriver->fEngineControl->fComputation, fDriver->fEngineControl->fConstraint);
00064         if (fThread->AcquireRealTime(GetEngineControl()->fPriority) < 0) {
00065             jack_error("AcquireRealTime error");
00066         }
00067     }
00068 
00069     return 0;
00070 }
00071 
00072 int JackThreadedDriver::Stop()
00073 {
00074     JackLog("JackThreadedDriver::Stop\n");
00075     int res;
00076 
00077     if ((res = fThread->Stop()) < 0) {  // Stop when the thread cycle is finished
00078         jack_error("Cannot stop thread");
00079         return res;
00080     }
00081     if ((res = fDriver->Stop()) < 0) {
00082         jack_error("Cannot stop driver");
00083         return res;
00084     }
00085     return 0;
00086 }
00087 
00088 bool JackThreadedDriver::Execute()
00089 {
00090     return (Process() == 0);
00091 }
00092 
00093 } // end of namespace

Generated on Wed Jan 10 11:42:46 2007 for Jackdmp by  doxygen 1.4.5