JackThreadedDriver.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 #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         if (fThread->AcquireRealTime(GetEngineControl()->fPriority) < 0) 
00063             jack_error("AcquireRealTime error");
00064     }
00065 
00066     return 0;
00067 }
00068 
00069 int JackThreadedDriver::Stop()
00070 {
00071     JackLog("JackThreadedDriver::Stop\n");
00072     int res;
00073 
00074     if ((res = fThread->Stop()) < 0) {  // Stop when the thread cycle is finished
00075         jack_error("Cannot stop thread");
00076         return res;
00077     }
00078     if ((res = fDriver->Stop()) < 0) {
00079         jack_error("Cannot stop driver");
00080         return res;
00081     }
00082     return 0;
00083 }
00084 
00085 bool JackThreadedDriver::Execute()
00086 {
00087     return (Process() == 0);
00088 }
00089 
00090 } // end of namespace

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1