Merge pull request #23 from jackaudio/device_reservation_fixes
[jack2.git] / common / JackNetManager.h
blobc88a09ba4f608abe8584f0bbffc96999f30515cc
1 /*
2 Copyright (C) 2008-2011 Romain Moret at Grame
4 This program 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.
9 This program 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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JACKNETMANAGER_H__
21 #define __JACKNETMANAGER_H__
23 #include "JackNetInterface.h"
24 #include "thread.h"
25 #include "jack.h"
26 #include "jslist.h"
27 #include <list>
29 namespace Jack
31 class JackNetMasterManager;
33 /**
34 \Brief This class describes a Net Master
37 class JackNetMaster : public JackNetMasterInterface
39 friend class JackNetMasterManager;
41 private:
43 static int SetProcess(jack_nframes_t nframes, void* arg);
44 static int SetBufferSize(jack_nframes_t nframes, void* arg);
45 static void SetTimebaseCallback(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
46 static void SetConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
48 //jack client
49 jack_client_t* fClient;
50 const char* fName;
52 //jack ports
53 jack_port_t** fAudioCapturePorts;
54 jack_port_t** fAudioPlaybackPorts;
55 jack_port_t** fMidiCapturePorts;
56 jack_port_t** fMidiPlaybackPorts;
58 //sync and transport
59 int fLastTransportState;
61 //monitoring
62 #ifdef JACK_MONITOR
63 jack_time_t fPeriodUsecs;
64 JackGnuPlotMonitor<float>* fNetTimeMon;
65 #endif
67 bool Init(bool auto_connect);
68 int AllocPorts();
69 void FreePorts();
71 //transport
72 void EncodeTransportData();
73 void DecodeTransportData();
75 int Process();
76 void TimebaseCallback(jack_position_t* pos);
77 void ConnectPorts();
78 void ConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect);
80 public:
82 JackNetMaster(JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
83 ~JackNetMaster();
85 bool IsSlaveReadyToRoll();
88 typedef std::list<JackNetMaster*> master_list_t;
89 typedef master_list_t::iterator master_list_it_t;
91 /**
92 \Brief This class describer the Network Manager
95 class JackNetMasterManager
97 friend class JackNetMaster;
99 private:
101 static void SetShutDown(void* arg);
102 static int SetSyncCallback(jack_transport_state_t state, jack_position_t* pos, void* arg);
103 static void* NetManagerThread(void* arg);
105 jack_client_t* fClient;
106 const char* fName;
107 char fMulticastIP[32];
108 JackNetSocket fSocket;
109 jack_native_thread_t fThread;
110 master_list_t fMasterList;
111 uint32_t fGlobalID;
112 bool fRunning;
113 bool fAutoConnect;
115 void Run();
116 JackNetMaster* InitMaster(session_params_t& params);
117 master_list_it_t FindMaster(uint32_t client_id);
118 int KillMaster(session_params_t* params);
119 int SyncCallback(jack_transport_state_t state, jack_position_t* pos);
120 int CountIO(int flags);
121 void ShutDown();
123 public:
125 JackNetMasterManager(jack_client_t* jack_client, const JSList* params);
126 ~JackNetMasterManager();
130 #endif