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