gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
JackPortMonitor.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef JACKPORTMANAGER_H_
18 #define JACKPORTMANAGER_H_
19 
20 #include "JackBase.H"
21 
22 #define JACK_PORT_MONITOR_CLIENT_NAME "Jack Port Monitor"
23 
24 #include "Thread.H"
25 
34 class JackPortMonitor : virtual public JackBase, public WaitingThread {
35 
39  void init(bool monitorPorts);
40 
45  void init(bool monitorPorts, bool autoConnectNetClientsIn);
46 
50 
57  static void jackPortConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void *arg) {
58  //cout<<"\njackPortConnectCallback\n"<<endl;
59  static_cast<JackPortMonitor*>(arg)->jackPortConnected(a, b, connect);
60  }
61 
67  static void jackPortRegistrationCallback(jack_port_id_t port, int reg, void *arg) {
68  //cout<<"\njackPortRegistrationCallback\n"<<endl;
69  static_cast<JackPortMonitor*>(arg)->jackPortRegistered(port, reg);
70  }
71 
78  static void jackPortRenameCallback(jack_port_id_t port, const char *oldName, const char *newName, void *arg) {
79  //cout<<"\njackPortRenameCallback\n"<<endl;
80  static_cast<JackPortMonitor*>(arg)->jackPortRenamed(port, oldName, newName);
81  }
82 
87  virtual void breakDownPortsToClients(vector<jack_port_t *> &ports);
88 
94  void reSyncPorts(JackPortFlags flags);
95 
96 
101  virtual int disconnect(void);
102 
103 
109  virtual int connect(string clientName_){return JackBase::connect(clientName_);}
110 
118  virtual int connect(const string &clientName_, const string &serverName);
119 
122  virtual void *threadMain(void);
123 
124 protected:
125 
128  struct CompareStrings : unary_function<string,bool> {
129  public:
130  string cn;
131 
135  CompareStrings(string cn_) : cn(cn_) {}
136 
141  return cl->getClientName()==cn;
142  }
143  };
144 
145  vector<JackBaseWithPortNames *> knownClients;
146 
148 
151  virtual void autoConnectNetClientsPorts(void);
152 
155  virtual void reSyncPorts(void);
156 
159  virtual void reSyncConnections(void);
160 
166  virtual void jackPortConnected(jack_port_id_t a, jack_port_id_t b, int connect) {
168  this->print(cout);
169  }
170 
175  virtual void jackPortRegistered(jack_port_id_t port, int reg) {
176  if (autoConnectNetClients){
177  //autoConnectNetClientsPorts(); // can't connect ports in a critical server thread.
178  // Instruct the network port manager thread to connect the net ports.
179  cond.lock(); // lock the mutex and wake the thread.
180  cond.signal(); // Wake the WaitingThread
181  cond.unLock(); // Unlock so the WaitingThread can continue.
182  }
183  reSyncPorts();
185  this->print(cout);
186  }
187 
193  virtual void jackPortRenamed(jack_port_id_t port, const char *oldName, const char *newName) {
194  reSyncPorts();
196  this->print(cout);
197  }
198 
199 public:
203  JackPortMonitor();
204 
208  JackPortMonitor(bool monitorPorts);
209 
210 
215  JackPortMonitor(bool monitorPorts, bool autoConnectNetClientsIn);
216 
221  JackPortMonitor(string clientName_);
222 
227  JackPortMonitor(string clientName_, bool monitorPorts);
228 
234  JackPortMonitor(string clientName_, bool monitorPorts, bool autoConnectNetClientsIn);
235 
241  JackPortMonitor(string clientName_, string serverName);
242 
248  JackPortMonitor(string clientName_, string serverName, bool monitorPorts);
249 
256  JackPortMonitor(string clientName_, string serverName, bool monitorPorts, bool autoConnectNetClients);
257 
263 
265  virtual ~JackPortMonitor() {}
266 
270  virtual void print(ostream &os);
271 
275  void connectPortRenameCallback(void);
276 
281 
285  void connectPortConnectCallback(void);
286 
287 
288 // /** Allow printing of port information to an ostream.
289 // \param os The ostream to output to.
290 // \param jpm The JackPortMonitor to print out.
291 // */
292 // friend ostream &operator<<(ostream &os, JackPortMonitor &jpm);
293 };
294 
295 //ostream &operator<<(ostream &os, JackPortMonitor &jpm){
296 // jpm.print(os);
297 // return os;
298 //}
299 
300 #endif // JACKPORTMANAGER_H_
virtual void jackPortRenamed(jack_port_id_t port, const char *oldName, const char *newName)
void signal()
Definition: Thread.H:369
bool autoConnectNetClients
When true, autoconnect networked client&#39;s ports to the system ports.
virtual int connect(string clientName_)
Definition: JackBase.H:369
virtual void print(ostream &os)
virtual int connect(string clientName_)
string cn
The string to compare against.
virtual int disconnect(void)
void init()
Definition: JackBase.H:92
static void jackPortConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void *arg)
virtual void breakDownPortsToClients(vector< jack_port_t *> &ports)
virtual void * threadMain(void)
void connectPortRenameCallback(void)
vector< JackBaseWithPortNames * > knownClients
A vector of clients and their ports both ids and names.
virtual ~JackPortMonitor()
Destructor.
int unLock()
Definition: Thread.H:325
static void jackPortRegistrationCallback(jack_port_id_t port, int reg, void *arg)
virtual void reSyncPorts(void)
virtual void reSyncConnections(void)
Cond cond
Definition: Thread.H:441
static void jackPortRenameCallback(jack_port_id_t port, const char *oldName, const char *newName, void *arg)
virtual void jackPortRegistered(jack_port_id_t port, int reg)
bool operator()(JackBaseWithPortNames *cl)
virtual void jackPortConnected(jack_port_id_t a, jack_port_id_t b, int connect)
virtual void autoConnectNetClientsPorts(void)
void connectPortRegistrationCallback(void)
void connectPortMonitoringCallbacks(void)
int lock()
Definition: Thread.H:295
string getClientName()
Definition: JackBase.H:436
void connectPortConnectCallback(void)
gtkIOStream: /tmp/gtkiostream/include/JackPortMonitor.H Source File
GTK+ IOStream  Beta