Jack2  1.9.9
JackWaitThreadedDriver.h
1 /*
2  Copyright (C) 2001 Paul Davis
3  Copyright (C) 2004-2008 Grame
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 #ifndef __JackWaitThreadedDriver__
22 #define __JackWaitThreadedDriver__
23 
24 #include "JackThreadedDriver.h"
25 #include "JackTimedDriver.h"
26 
27 namespace Jack
28 {
29 
38 class SERVER_EXPORT JackWaitThreadedDriver : public JackThreadedDriver
39 {
40  private:
41 
42  struct JackDriverStarter : public JackRunnableInterface
43  {
44 
45  JackDriver* fDriver;
46  JackThread fThread;
47  volatile bool fRunning;
48 
49  JackDriverStarter(JackDriver* driver)
50  :fDriver(driver), fThread(this), fRunning(false)
51  {}
52 
53  ~JackDriverStarter()
54  {
55  fThread.Kill();
56  }
57 
58  int Start()
59  {
60  fRunning = false;
61  return fThread.Start();
62  }
63 
64  // JackRunnableInterface interface
65  bool Execute()
66  {
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...");
72  }
73 
74  return false;
75  }
76 
77  };
78 
79  JackDriverStarter fStarter;
80 
81  public:
82 
84  : JackThreadedDriver(net_driver), fStarter(net_driver)
85  {}
86  virtual ~JackWaitThreadedDriver()
87  {}
88 
89  // JackRunnableInterface interface
90  bool Init();
91  bool Execute();
92 };
93 
94 
95 } // end of namespace
96 
97 
98 #endif
The base class for threaded drivers using a "decorator" pattern. Threaded drivers are used with block...
To be used as a wrapper of JackNetDriver.
The base class for runnable objects, that have an Init and Execute method to be called in a threa...
Definition: JackThread.h:34
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91
Darwin threads. Real-time threads are actually "time constraint" threads.