Jack2 1.9.6

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