Merge branch 'master' into develop
[jack2.git] / common / JackWaitThreadedDriver.h
blobd9cda65284b2e257e83988dbc6a808c2fde6cdba
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 #ifndef __JackWaitThreadedDriver__
22 #define __JackWaitThreadedDriver__
24 #include "JackThreadedDriver.h"
25 #include "JackTimedDriver.h"
27 namespace Jack
30 /*!
31 \brief Wrapper for a restartable threaded driver (e.g. JackNetDriver).
33 The idea is to behave as the "dummy" driver, until the network connection is really started and processing starts.
34 The Execute method will call the ProcessNull method from the base JackWaiterDriver, until the decorated driver Initialize method returns.
35 A helper JackDriverStarter thread is used for that purpose.
38 class SERVER_EXPORT JackWaitThreadedDriver : public JackThreadedDriver
40 private:
42 struct JackDriverStarter : public JackRunnableInterface
45 JackDriver* fDriver;
46 JackThread fThread;
47 volatile bool fRunning;
49 JackDriverStarter(JackDriver* driver)
50 :fDriver(driver), fThread(this), fRunning(false)
53 ~JackDriverStarter()
55 fThread.Kill();
58 int Start()
60 fRunning = false;
61 return fThread.Start();
64 // JackRunnableInterface interface
65 bool Execute()
67 // Blocks until decorated driver is started (that is when it's Initialize method returns).
68 if (fDriver->Initialize()) {
69 fRunning = true;
70 } else {
71 jack_error("Initing net driver fails...");
74 return false;
79 JackDriverStarter fStarter;
81 public:
83 JackWaitThreadedDriver(JackDriver* net_driver)
84 : JackThreadedDriver(net_driver), fStarter(net_driver)
86 virtual ~JackWaitThreadedDriver()
89 // JackRunnableInterface interface
90 bool Init();
91 bool Execute();
93 protected:
95 virtual bool ExecuteReal(); /*!< Real work to be done when the decorated driver has finish initializing */
99 } // end of namespace
102 #endif