2 Copyright (C) 2004-2008 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 __JackEngine__
21 #define __JackEngine__
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"
36 class JackClientInterface
;
37 struct JackEngineControl
;
38 class JackExternalClient
;
41 \brief Engine description.
44 class SERVER_EXPORT JackEngine
: public JackLockAble
46 friend class JackLockedEngine
;
50 JackGraphManager
* fGraphManager
;
51 JackEngineControl
* fEngineControl
;
52 char fSelfConnectMode
;
53 JackClientInterface
* fClientTable
[CLIENT_NUM
];
54 JackSynchro
* fSynchroTable
;
55 JackServerNotifyChannel fChannel
; /*! To communicate between the RT thread and server */
56 JackProcessSync fSignal
;
57 jack_time_t fLastSwitchUsecs
;
58 JackMetadata fMetadata
;
60 int fSessionPendingReplies
;
61 detail::JackChannelTransactionInterface
* fSessionTransaction
;
62 JackSessionNotifyResult
* fSessionResult
;
63 std::map
<int,std::string
> fReservationMap
;
65 int ClientCloseAux(int refnum
, bool wait
);
66 void CheckXRun(jack_time_t callback_usecs
);
68 int NotifyAddClient(JackClientInterface
* new_client
, const char* new_name
, int refnum
);
69 void NotifyRemoveClient(const char* name
, int refnum
);
71 void ProcessNext(jack_time_t callback_usecs
);
72 void ProcessCurrent(jack_time_t callback_usecs
);
74 bool ClientCheckName(const char* name
);
75 bool GenerateUniqueName(char* name
);
78 void ReleaseRefnum(int refnum
);
80 int ClientNotify(JackClientInterface
* client
, int refnum
, const char* name
, int notify
, int sync
, const char* message
, int value1
, int value2
);
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
);
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
);
90 void EnsureUUID(jack_uuid_t uuid
);
92 bool CheckClient(int refnum
)
94 return (refnum
>= 0 && refnum
< CLIENT_NUM
&& fClientTable
[refnum
] != NULL
);
97 int CheckPortsConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
);
101 JackEngine(JackGraphManager
* manager
, JackSynchro
* table
, JackEngineControl
* controler
, char self_connect_mode
);
108 int ClientCheck(const char* name
, jack_uuid_t uuid
, char* name_res
, int protocol
, int options
, int* status
);
110 int ClientExternalOpen(const char* name
, int pid
, jack_uuid_t uuid
, int* ref
, int* shared_engine
, int* shared_client
, int* shared_graph_manager
);
111 int ClientInternalOpen(const char* name
, int* ref
, JackEngineControl
** shared_engine
, JackGraphManager
** shared_manager
, JackClientInterface
* client
, bool wait
);
113 int ClientExternalClose(int refnum
);
114 int ClientInternalClose(int refnum
, bool wait
);
116 int ClientActivate(int refnum
, bool is_real_time
);
117 int ClientDeactivate(int refnum
);
119 void ClientKill(int refnum
);
121 int GetClientPID(const char* name
);
122 int GetClientRefNum(const char* name
);
124 // Internal client management
125 int GetInternalClientName(int int_ref
, char* name_res
);
126 int InternalClientHandle(const char* client_name
, int* status
, int* int_ref
);
127 int InternalClientUnload(int refnum
, int* status
);
130 int PortRegister(int refnum
, const char* name
, const char *type
, unsigned int flags
, unsigned int buffer_size
, jack_port_id_t
* port
);
131 int PortUnRegister(int refnum
, jack_port_id_t port
);
133 int PortConnect(int refnum
, const char* src
, const char* dst
);
134 int PortDisconnect(int refnum
, const char* src
, const char* dst
);
136 int PortConnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
);
137 int PortDisconnect(int refnum
, jack_port_id_t src
, jack_port_id_t dst
);
139 int PortRename(int refnum
, jack_port_id_t port
, const char* name
);
141 int PortSetDefaultMetadata(jack_port_id_t port
, const char* pretty_name
);
143 int ComputeTotalLatencies();
145 int PropertyChangeNotify(jack_uuid_t subject
, const char* key
,jack_property_change_t change
);
148 bool Process(jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
);
151 void NotifyDriverXRun();
152 void NotifyClientXRun(int refnum
);
153 void NotifyFailure(int code
, const char* reason
);
154 void NotifyGraphReorder();
155 void NotifyBufferSize(jack_nframes_t buffer_size
);
156 void NotifySampleRate(jack_nframes_t sample_rate
);
157 void NotifyFreewheel(bool onoff
);
160 // Session management
161 void SessionNotify(int refnum
, const char *target
, jack_session_event_type_t type
, const char *path
, detail::JackChannelTransactionInterface
*socket
, JackSessionNotifyResult
** result
);
162 int SessionReply(int refnum
);
164 int GetUUIDForClientName(const char *client_name
, char *uuid_res
);
165 int GetClientNameForUUID(const char *uuid
, char *name_res
);
166 int ReserveClientName(const char *name
, const char *uuid
);
167 int ClientHasSessionCallback(const char *name
);
171 } // end of namespace