Jack2
1.9.10
|
00001 /* 00002 Copyright (C) 2004-2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef __JackEngine__ 00021 #define __JackEngine__ 00022 00023 #include "JackConstants.h" 00024 #include "JackGraphManager.h" 00025 #include "JackSynchro.h" 00026 #include "JackMutex.h" 00027 #include "JackTransportEngine.h" 00028 #include "JackPlatformPlug.h" 00029 #include "JackRequest.h" 00030 #include "JackChannel.h" 00031 #include <map> 00032 00033 namespace Jack 00034 { 00035 00036 class JackClientInterface; 00037 struct JackEngineControl; 00038 class JackExternalClient; 00039 00044 class SERVER_EXPORT JackEngine : public JackLockAble 00045 { 00046 friend class JackLockedEngine; 00047 00048 private: 00049 00050 JackGraphManager* fGraphManager; 00051 JackEngineControl* fEngineControl; 00052 char fSelfConnectMode; 00053 JackClientInterface* fClientTable[CLIENT_NUM]; 00054 JackSynchro* fSynchroTable; 00055 JackServerNotifyChannel fChannel; 00056 JackProcessSync fSignal; 00057 jack_time_t fLastSwitchUsecs; 00058 00059 int fSessionPendingReplies; 00060 detail::JackChannelTransactionInterface* fSessionTransaction; 00061 JackSessionNotifyResult* fSessionResult; 00062 std::map<int,std::string> fReservationMap; 00063 int fMaxUUID; 00064 00065 int ClientCloseAux(int refnum, bool wait); 00066 void CheckXRun(jack_time_t callback_usecs); 00067 00068 int NotifyAddClient(JackClientInterface* new_client, const char* new_name, int refnum); 00069 void NotifyRemoveClient(const char* name, int refnum); 00070 00071 void ProcessNext(jack_time_t callback_usecs); 00072 void ProcessCurrent(jack_time_t callback_usecs); 00073 00074 bool ClientCheckName(const char* name); 00075 bool GenerateUniqueName(char* name); 00076 00077 int AllocateRefnum(); 00078 void ReleaseRefnum(int refnum); 00079 00080 int ClientNotify(JackClientInterface* client, int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2); 00081 00082 void NotifyClient(int refnum, int event, int sync, const char* message, int value1, int value2); 00083 void NotifyClients(int event, int sync, const char* message, int value1, int value2); 00084 00085 void NotifyPortRegistation(jack_port_id_t port_index, bool onoff); 00086 void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff); 00087 void NotifyPortRename(jack_port_id_t src, const char* old_name); 00088 void NotifyActivate(int refnum); 00089 00090 int GetNewUUID(); 00091 void EnsureUUID(int uuid); 00092 00093 bool CheckClient(int refnum) 00094 { 00095 return (refnum >= 0 && refnum < CLIENT_NUM && fClientTable[refnum] != NULL); 00096 } 00097 00098 int CheckPortsConnect(int refnum, jack_port_id_t src, jack_port_id_t dst); 00099 00100 public: 00101 00102 JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler, char self_connect_mode); 00103 ~JackEngine(); 00104 00105 int Open(); 00106 int Close(); 00107 00108 // Client management 00109 int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status); 00110 00111 int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager); 00112 int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait); 00113 00114 int ClientExternalClose(int refnum); 00115 int ClientInternalClose(int refnum, bool wait); 00116 00117 int ClientActivate(int refnum, bool is_real_time); 00118 int ClientDeactivate(int refnum); 00119 00120 void ClientKill(int refnum); 00121 00122 int GetClientPID(const char* name); 00123 int GetClientRefNum(const char* name); 00124 00125 // Internal client management 00126 int GetInternalClientName(int int_ref, char* name_res); 00127 int InternalClientHandle(const char* client_name, int* status, int* int_ref); 00128 int InternalClientUnload(int refnum, int* status); 00129 00130 // Port management 00131 int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port); 00132 int PortUnRegister(int refnum, jack_port_id_t port); 00133 00134 int PortConnect(int refnum, const char* src, const char* dst); 00135 int PortDisconnect(int refnum, const char* src, const char* dst); 00136 00137 int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst); 00138 int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst); 00139 00140 int PortRename(int refnum, jack_port_id_t port, const char* name); 00141 00142 int ComputeTotalLatencies(); 00143 00144 // Graph 00145 bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end); 00146 00147 // Notifications 00148 void NotifyDriverXRun(); 00149 void NotifyClientXRun(int refnum); 00150 void NotifyFailure(int code, const char* reason); 00151 void NotifyGraphReorder(); 00152 void NotifyBufferSize(jack_nframes_t buffer_size); 00153 void NotifySampleRate(jack_nframes_t sample_rate); 00154 void NotifyFreewheel(bool onoff); 00155 void NotifyQuit(); 00156 00157 // Session management 00158 void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, detail::JackChannelTransactionInterface *socket, JackSessionNotifyResult** result); 00159 int SessionReply(int refnum); 00160 00161 int GetUUIDForClientName(const char *client_name, char *uuid_res); 00162 int GetClientNameForUUID(const char *uuid, char *name_res); 00163 int ReserveClientName(const char *name, const char *uuid); 00164 int ClientHasSessionCallback(const char *name); 00165 }; 00166 00167 00168 } // end of namespace 00169 00170 #endif 00171