Jack2 1.9.10

JackWaitThreadedDriver.h

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 #ifndef __JackWaitThreadedDriver__
00022 #define __JackWaitThreadedDriver__
00023 
00024 #include "JackThreadedDriver.h"
00025 #include "JackTimedDriver.h"
00026 
00027 namespace Jack
00028 {
00029 
00038 class SERVER_EXPORT JackWaitThreadedDriver : public JackThreadedDriver
00039 {
00040     private:
00041 
00042         struct JackDriverStarter : public JackRunnableInterface
00043         {
00044 
00045                 JackDriver* fDriver;
00046                 JackThread fThread;
00047                 volatile bool fRunning;
00048 
00049                 JackDriverStarter(JackDriver* driver)
00050                     :fDriver(driver), fThread(this), fRunning(false)
00051                 {}
00052 
00053                 ~JackDriverStarter()
00054                 {
00055                      fThread.Kill();
00056                 }
00057 
00058                 int Start()
00059                 {
00060                     fRunning = false;
00061                     return fThread.Start();
00062                 }
00063 
00064                 // JackRunnableInterface interface
00065                 bool Execute()
00066                 {
00067                     // Blocks until decorated driver is started (that is when it's Initialize method returns).
00068                     if (fDriver->Initialize()) {
00069                         fRunning = true;
00070                     } else {
00071                         jack_error("Initing net driver fails...");
00072                     }
00073 
00074                     return false;
00075                 }
00076 
00077         };
00078 
00079         JackDriverStarter fStarter;
00080 
00081     public:
00082 
00083         JackWaitThreadedDriver(JackDriver* net_driver)
00084             : JackThreadedDriver(net_driver), fStarter(net_driver)
00085         {}
00086         virtual ~JackWaitThreadedDriver()
00087         {}
00088 
00089         // JackRunnableInterface interface
00090         bool Init();
00091         bool Execute();
00092 };
00093 
00094 
00095 } // end of namespace
00096 
00097 
00098 #endif