Jack2 1.9.7

JackEngine.h

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 <map>
00030 
00031 namespace Jack
00032 {
00033 
00034 class JackClientInterface;
00035 struct JackEngineControl;
00036 class JackExternalClient;
00037 
00042 class SERVER_EXPORT JackEngine : public JackLockAble
00043 {
00044     friend class JackLockedEngine;
00045 
00046     private:
00047 
00048         JackGraphManager* fGraphManager;
00049         JackEngineControl* fEngineControl;
00050         JackClientInterface* fClientTable[CLIENT_NUM];
00051         JackSynchro* fSynchroTable;
00052         JackServerNotifyChannel fChannel;              
00053         JackProcessSync fSignal;
00054         jack_time_t fLastSwitchUsecs;
00055 
00056         int fSessionPendingReplies;
00057         JackChannelTransaction *fSessionTransaction;
00058         JackSessionNotifyResult *fSessionResult;
00059         std::map<int,std::string> fReservationMap;
00060         int fMaxUUID;
00061 
00062         int ClientCloseAux(int refnum, JackClientInterface* client, bool wait);
00063         void CheckXRun(jack_time_t callback_usecs);
00064 
00065         int NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum);
00066         void NotifyRemoveClient(const char* name, int refnum);
00067 
00068         void ProcessNext(jack_time_t callback_usecs);
00069         void ProcessCurrent(jack_time_t callback_usecs);
00070 
00071         bool ClientCheckName(const char* name);
00072         bool GenerateUniqueName(char* name);
00073 
00074         int AllocateRefnum();
00075         void ReleaseRefnum(int ref);
00076 
00077         void NotifyClient(int refnum, int event, int sync, const char*  message, int value1, int value2);
00078         void NotifyClients(int event, int sync, const char*  message,  int value1, int value2);
00079 
00080         void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
00081         void NotifyPortConnect(jack_port_id_t src, jack_port_id_t dst, bool onoff);
00082         void NotifyPortRename(jack_port_id_t src, const char* old_name);
00083         void NotifyActivate(int refnum);
00084 
00085         int GetNewUUID();
00086         void EnsureUUID(int uuid);
00087 
00088         bool CheckClient(int refnum)
00089         {
00090             return (refnum >= 0 && refnum < CLIENT_NUM && fClientTable[refnum] != NULL);
00091         }
00092 
00093     public:
00094 
00095         JackEngine(JackGraphManager* manager, JackSynchro* table, JackEngineControl* controler);
00096         ~JackEngine();
00097 
00098         int Open();
00099         int Close();
00100 
00101         // Client management
00102         int ClientCheck(const char* name, int uuid, char* name_res, int protocol, int options, int* status);
00103         int ClientExternalOpen(const char* name, int pid, int uuid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
00104         int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
00105 
00106         int ClientExternalClose(int refnum);
00107         int ClientInternalClose(int refnum, bool wait);
00108 
00109         int ClientActivate(int refnum, bool is_real_time);
00110         int ClientDeactivate(int refnum);
00111 
00112         int GetClientPID(const char* name);
00113         int GetClientRefNum(const char* name);
00114 
00115         // Internal client management
00116         int GetInternalClientName(int int_ref, char* name_res);
00117         int InternalClientHandle(const char* client_name, int* status, int* int_ref);
00118         int InternalClientUnload(int refnum, int* status);
00119 
00120         // Port management
00121         int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port);
00122         int PortUnRegister(int refnum, jack_port_id_t port);
00123 
00124         int PortConnect(int refnum, const char* src, const char* dst);
00125         int PortDisconnect(int refnum, const char* src, const char* dst);
00126 
00127         int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
00128         int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
00129 
00130         int PortRename(int refnum, jack_port_id_t port, const char* name);
00131 
00132         int ComputeTotalLatencies();
00133 
00134         // Graph
00135         bool Process(jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
00136 
00137         // Notifications
00138         void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs);
00139         void NotifyFailure(int code, const char* reason);
00140         void NotifyXRun(int refnum);
00141         void NotifyGraphReorder();
00142         void NotifyBufferSize(jack_nframes_t buffer_size);
00143         void NotifySampleRate(jack_nframes_t sample_rate);
00144         void NotifyFreewheel(bool onoff);
00145         void NotifyQuit();
00146 
00147         // Session management
00148         void SessionNotify(int refnum, const char *target, jack_session_event_type_t type, const char *path, JackChannelTransaction *socket);
00149         void SessionReply(int refnum);
00150 
00151         void GetUUIDForClientName(const char *client_name, char *uuid_res, int *result);
00152         void GetClientNameForUUID(const char *uuid, char *name_res, int *result);
00153         void ReserveClientName(const char *name, const char *uuid, int *result);
00154         void ClientHasSessionCallbackRequest(const char *name, int *result);
00155 };
00156 
00157 
00158 } // end of namespace
00159 
00160 #endif
00161