Merge branch 'master' into develop
[jack2.git] / common / JackNetManager.h
blob80a66070b2d165ecdd87427ba6acc5b17142591a
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 "jack.h"
25 #include <list>
26 #include <map>
28 namespace Jack
30 class JackNetMasterManager;
32 /**
33 \Brief This class describes a Net Master
36 typedef std::list<std::pair<std::string, std::string> > connections_list_t;
38 class JackNetMaster : public JackNetMasterInterface
40 friend class JackNetMasterManager;
42 private:
44 static int SetProcess(jack_nframes_t nframes, void* arg);
45 static int SetBufferSize(jack_nframes_t nframes, void* arg);
46 static int SetSampleRate(jack_nframes_t nframes, void* arg);
47 static void SetTimebaseCallback(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
48 static void SetConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
49 static void LatencyCallback(jack_latency_callback_mode_t mode, void* arg);
51 //jack client
52 jack_client_t* fClient;
53 const char* fName;
55 //jack ports
56 jack_port_t** fAudioCapturePorts;
57 jack_port_t** fAudioPlaybackPorts;
58 jack_port_t** fMidiCapturePorts;
59 jack_port_t** fMidiPlaybackPorts;
61 //sync and transport
62 int fLastTransportState;
64 //monitoring
65 #ifdef JACK_MONITOR
66 jack_time_t fPeriodUsecs;
67 JackGnuPlotMonitor<float>* fNetTimeMon;
68 #endif
70 bool Init(bool auto_connect);
71 int AllocPorts();
72 void FreePorts();
74 //transport
75 void EncodeTransportData();
76 void DecodeTransportData();
78 int Process();
79 void TimebaseCallback(jack_position_t* pos);
80 void ConnectPorts();
81 void ConnectCallback(jack_port_id_t a, jack_port_id_t b, int connect);
83 void SaveConnections(connections_list_t& connections);
84 void LoadConnections(const connections_list_t& connections);
86 public:
88 JackNetMaster(JackNetSocket& socket, session_params_t& params, const char* multicast_ip);
89 ~JackNetMaster();
91 bool IsSlaveReadyToRoll();
94 typedef std::list<JackNetMaster*> master_list_t;
95 typedef master_list_t::iterator master_list_it_t;
96 typedef std::map <std::string, connections_list_t> master_connections_list_t;
98 /**
99 \Brief This class describer the Network Manager
102 class JackNetMasterManager
104 friend class JackNetMaster;
106 private:
108 static void SetShutDown(void* arg);
109 static int SetSyncCallback(jack_transport_state_t state, jack_position_t* pos, void* arg);
110 static void* NetManagerThread(void* arg);
112 jack_client_t* fClient;
113 const char* fName;
114 char fMulticastIP[32];
115 JackNetSocket fSocket;
116 jack_native_thread_t fThread;
117 master_list_t fMasterList;
118 master_connections_list_t fMasterConnectionList;
119 uint32_t fGlobalID;
120 bool fRunning;
121 bool fAutoConnect;
122 bool fAutoSave;
124 void Run();
125 JackNetMaster* InitMaster(session_params_t& params);
126 master_list_it_t FindMaster(uint32_t client_id);
127 int KillMaster(session_params_t* params);
128 int SyncCallback(jack_transport_state_t state, jack_position_t* pos);
129 int CountIO(const char* type, int flags);
130 void ShutDown();
132 public:
134 JackNetMasterManager(jack_client_t* jack_client, const JSList* params);
135 ~JackNetMasterManager();
139 #endif