Jack2  1.9.10
JackEngine.h
1 /*
2 Copyright (C) 2004-2008 Grame
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #ifndef __JackEngine__
21 #define __JackEngine__
22 
23 #include "JackConstants.h"
24 #include "JackGraphManager.h"
25 #include "JackSynchro.h"
26 #include "JackMutex.h"
27 #include "JackTransportEngine.h"
28 #include "JackPlatformPlug.h"
29 #include "JackRequest.h"
30 #include "JackChannel.h"
31 #include <map>
32 
33 namespace Jack
34 {
35 
36 class JackClientInterface;
37 struct JackEngineControl;
38 class JackExternalClient;
39 
44 class SERVER_EXPORT JackEngine : public JackLockAble
45 {
46  friend class JackLockedEngine;
47 
48  private:
49 
50  JackGraphManager* fGraphManager;
51  JackEngineControl* fEngineControl;
52  char fSelfConnectMode;
53  JackClientInterface* fClientTable[CLIENT_NUM];
54  JackSynchro* fSynchroTable;
55  JackServerNotifyChannel fChannel;
56  JackProcessSync fSignal;
57  jack_time_t fLastSwitchUsecs;
58 
59  int fSessionPendingReplies;
60  detail::JackChannelTransactionInterface* fSessionTransaction;
61  JackSessionNotifyResult* fSessionResult;
62  std::map<int,std::string> fReservationMap;
63  int fMaxUUID;
64 
65  int ClientCloseAux(int refnum, bool wait);
66  void CheckXRun(jack_time_t callback_usecs);
67 
68  int NotifyAddClient(JackClientInterface* new_client, const char* new_name, int refnum);
69  void NotifyRemoveClient(const char* name, int refnum);
70 
71  void ProcessNext(jack_time_t callback_usecs);
72  void ProcessCurrent(jack_time_t callback_usecs);
73 
74  bool ClientCheckName(const char* name);
75  bool GenerateUniqueName(char* name);
76 
77  int AllocateRefnum();
78  void ReleaseRefnum(int refnum);
79 
80  int ClientNotify(JackClientInterface* client, int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
81 
82  void NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2);
83  void NotifyClients(int event, int sync, const char* message, int value1, int value2);
84 
85  void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
86  void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
87  void NotifyPortRename(jack_port_id_t src, const char* old_name);
88  void NotifyActivate(int refnum);
89 
90  int GetNewUUID();
91  void EnsureUUID(int uuid);
92 
93  bool CheckClient(int refnum)
94  {
95  return (refnum >= 0 && refnum < CLIENT_NUM && fClientTable[refnum] != NULL);
96  }
97 
98  int CheckPortsConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
99 
100  public:
101 
102  JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode);
103  ~JackEngine();
104 
105  int Open();
106  int Close();
107 
108  // Client management
109  int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status);
110 
111  int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
112  int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
113 
114  int ClientExternalClose(int refnum);
115  int ClientInternalClose(int refnum, bool wait);
116 
117  int ClientActivate(int refnum, bool is_real_time);
118  int ClientDeactivate(int refnum);
119 
120  void ClientKill(int refnum);
121 
122  int GetClientPID(const char* name);
123  int GetClientRefNum(const char* name);
124 
125  // Internal client management
126  int GetInternalClientName(int int_ref, char* name_res);
127  int InternalClientHandle(const char* client_name, int* status, int* int_ref);
128  int InternalClientUnload(int refnum, int* status);
129 
130  // Port management
131  int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port);
132  int PortUnRegister(int refnum, jack_port_id_t port);
133 
134  int PortConnect(int refnum, const char* src, const char* dst);
135  int PortDisconnect(int refnum, const char* src, const char* dst);
136 
137  int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
138  int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
139 
140  int PortRename(int refnum, jack_port_id_t port, const char* name);
141 
142  int ComputeTotalLatencies();
143 
144  // Graph
145  bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
146 
147  // Notifications
148  void NotifyDriverXRun();
149  void NotifyClientXRun(int refnum);
150  void NotifyFailure(int code, const char* reason);
151  void NotifyGraphReorder();
152  void NotifyBufferSize(jack_nframes_t buffer_size);
153  void NotifySampleRate(jack_nframes_t sample_rate);
154  void NotifyFreewheel(bool onoff);
155  void NotifyQuit();
156 
157  // Session management
158  void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result);
159  int SessionReply(int refnum);
160 
161  int GetUUIDForClientName(const char *client_name, char *uuid_res);
162  int GetClientNameForUUID(const char *uuid, char *name_res);
163  int ReserveClientName(const char *name, const char *uuid);
164  int ClientHasSessionCallback(const char *name);
165 };
166 
167 
168 } // end of namespace
169 
170 #endif
171