Jack2  1.9.9
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  JackClientInterface* fClientTable[CLIENT_NUM];
53  JackSynchro* fSynchroTable;
54  JackServerNotifyChannel fChannel;
55  JackProcessSync fSignal;
56  jack_time_t fLastSwitchUsecs;
57 
58  int fSessionPendingReplies;
59  detail::JackChannelTransactionInterface* fSessionTransaction;
60  JackSessionNotifyResult* fSessionResult;
61  std::map<int,std::string> fReservationMap;
62  int fMaxUUID;
63 
64  int ClientCloseAux(int refnum, bool wait);
65  void CheckXRun(jack_time_t callback_usecs);
66 
67  int NotifyAddClient(JackClientInterface* new_client, const char* new_name, int refnum);
68  void NotifyRemoveClient(const char* name, int refnum);
69 
70  void ProcessNext(jack_time_t callback_usecs);
71  void ProcessCurrent(jack_time_t callback_usecs);
72 
73  bool ClientCheckName(const char* name);
74  bool GenerateUniqueName(char* name);
75 
76  int AllocateRefnum();
77  void ReleaseRefnum(int ref);
78 
79  int ClientNotify(JackClientInterface* client, int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
80 
81  void NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2);
82  void NotifyClients(int event, int sync, const char* message, int value1, int value2);
83 
84  void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
85  void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
86  void NotifyPortRename(jack_port_id_t src, const char* old_name);
87  void NotifyActivate(int refnum);
88 
89  int GetNewUUID();
90  void EnsureUUID(int uuid);
91 
92  bool CheckClient(int refnum)
93  {
94  return (refnum >= 0 && refnum < CLIENT_NUM && fClientTable[refnum] != NULL);
95  }
96 
97  public:
98 
99  JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler);
100  ~JackEngine();
101 
102  int Open();
103  int Close();
104 
105  void ShutDown();
106 
107  // Client management
108  int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status);
109  int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
110  int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
111 
112  int ClientExternalClose(int refnum);
113  int ClientInternalClose(int refnum, bool wait);
114 
115  int ClientActivate(int refnum, bool is_real_time);
116  int ClientDeactivate(int refnum);
117 
118  int GetClientPID(const char* name);
119  int GetClientRefNum(const char* name);
120 
121  // Internal client management
122  int GetInternalClientName(int int_ref, char* name_res);
123  int InternalClientHandle(const char* client_name, int* status, int* int_ref);
124  int InternalClientUnload(int refnum, int* status);
125 
126  // Port management
127  int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port);
128  int PortUnRegister(int refnum, jack_port_id_t port);
129 
130  int PortConnect(int refnum, const char* src, const char* dst);
131  int PortDisconnect(int refnum, const char* src, const char* dst);
132 
133  int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
134  int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
135 
136  int PortRename(int refnum, jack_port_id_t port, const char* name);
137 
138  int ComputeTotalLatencies();
139 
140  // Graph
141  bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
142 
143  // Notifications
144  void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs);
145  void NotifyFailure(int code, const char* reason);
146  void NotifyXRun(int refnum);
147  void NotifyGraphReorder();
148  void NotifyBufferSize(jack_nframes_t buffer_size);
149  void NotifySampleRate(jack_nframes_t sample_rate);
150  void NotifyFreewheel(bool onoff);
151  void NotifyQuit();
152 
153  // Session management
154  void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result);
155  int SessionReply(int refnum);
156 
157  int GetUUIDForClientName(const char *client_name, char *uuid_res);
158  int GetClientNameForUUID(const char *uuid, char *name_res);
159  int ReserveClientName(const char *name, const char *uuid);
160  int ClientHasSessionCallback(const char *name);
161 };
162 
163 
164 } // end of namespace
165 
166 #endif
167 
Engine description.
Definition: JackEngine.h:44
Inter process synchronization using using Mach semaphore.
Locked Engine, access to methods is serialized using a mutex.
A synchronization primitive built using a condition variable.
Base class for &quot;lockable&quot; objects.
Definition: JackMutex.h:36
Graph manager: contains the connection manager and the port array.
JackServerNotifyChannel using sockets.
Engine control in shared memory.