JackEngine.h 4.52 KB
Newer Older
sletz's avatar
sletz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Copyright (C) 2004-2006 Grame  

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackEngine__
#define __JackEngine__

#include "JackConstants.h"
#include "JackGraphManager.h"
#include "JackSynchro.h"
#include "JackTransportEngine.h"

namespace Jack
{

class JackClientInterface;
struct JackEngineControl;
class JackServerNotifyChannelInterface;
class JackEngineTiming;
class JackExternalClient;
class JackSyncInterface;

/*!
\brief Engine description.
*/

class JackEngine
{
    private:

        JackGraphManager* fGraphManager;
        JackEngineControl* fEngineControl;
        JackClientInterface* fClientTable[CLIENT_NUM];
        JackSynchro** fSynchroTable;
        JackServerNotifyChannelInterface* fChannel;              /*! To communicate between the RT thread and server */
51
        JackEngineTiming* fEngineTiming;
sletz's avatar
sletz committed
52
53
54
55
56
        JackSyncInterface* fSignal;
        jack_time_t fLastSwitchUsecs;

        int ClientCloseAux(int refnum, JackClientInterface* client, bool wait);
        void CheckXRun(jack_time_t callback_usecs);
sletz's avatar
Cleanup    
sletz committed
57
		
sletz's avatar
sletz committed
58
59
        int NotifyAddClient(JackClientInterface* new_client, const char* name, int refnum);
        void NotifyRemoveClient(const char* name, int refnum);
sletz's avatar
Cleanup    
sletz committed
60
		
sletz's avatar
sletz committed
61
62
63
        bool IsZombie(JackClientInterface* client, jack_time_t current_time);
        void RemoveZombifiedClients(jack_time_t current_time);
        void GetZombifiedClients(bool clients[CLIENT_NUM], jack_time_t current_time);
sletz's avatar
Cleanup    
sletz committed
64
		
sletz's avatar
sletz committed
65
66
		void ProcessNext(jack_time_t callback_usecs);
		void ProcessCurrent(jack_time_t callback_usecs);
sletz's avatar
Cleanup    
sletz committed
67
		
sletz's avatar
sletz committed
68
		bool ClientCheckName(const char* name);
69
		bool GenerateUniqueName(char* name);
sletz's avatar
Cleanup    
sletz committed
70
		
sletz's avatar
sletz committed
71
72
		int AllocateRefnum();
		void ReleaseRefnum(int ref);
sletz's avatar
sletz committed
73
74
75

    public:

sletz's avatar
sletz committed
76
        JackEngine(JackGraphManager* manager, JackSynchro** table, JackEngineControl* controler);
sletz's avatar
sletz committed
77
78
79
80
        virtual ~JackEngine();

        int Open();
        int Close();
81
	
sletz's avatar
sletz committed
82
        // Client management
83
		int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status);
sletz's avatar
sletz committed
84
        int ClientExternalOpen(const char* name, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager);
85
        int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait);
sletz's avatar
sletz committed
86

sletz's avatar
sletz committed
87
        int ClientExternalClose(int refnum);
88
89
        int ClientInternalClose(int refnum, bool wait);
    
sletz's avatar
sletz committed
90
91
        int ClientActivate(int refnum);
        int ClientDeactivate(int refnum);
92
93
94
95
96
		
		// Internal lient management
		int GetInternalClientName(int int_ref, char* name_res);
		int InternalClientHandle(const char* client_name, int* status, int* int_ref);
		int InternalClientUnload(int refnum, int* status);
sletz's avatar
sletz committed
97
98

        // Port management
sletz's avatar
sletz committed
99
        int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port_index);
sletz's avatar
sletz committed
100
101
102
103
104
105
106
107
108
109
110
111
112
        int PortUnRegister(int refnum, jack_port_id_t port);

        int PortConnect(int refnum, const char* src, const char* dst);
        int PortDisconnect(int refnum, const char* src, const char* dst);

        int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst);
        int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst);

        // Transport management
        int ReleaseTimebase(int refnum);
        int SetTimebaseCallback(int refnum, int conditional);

        // Graph
sletz's avatar
sletz committed
113
        bool Process(jack_time_t callback_usecs);
sletz's avatar
sletz committed
114
115
116
117
118
119
120
121
122
123
124
        void ZombifyClient(int refnum);

        // Notifications
        void NotifyClient(int refnum, int event, int sync, int value);
        void NotifyClients(int event, int sync, int value);
        void NotifyXRun(jack_time_t callback_usecs);
        void NotifyXRun(int refnum);
        void NotifyGraphReorder();
        void NotifyBufferSize(jack_nframes_t nframes);
        void NotifyFreewheel(bool onoff);
        void NotifyPortRegistation(jack_port_id_t port_index, bool onoff);
125
		void NotifyActivate(int refnum);
sletz's avatar
sletz committed
126
127
128
129
130
131
132
};


} // end of namespace

#endif