Cleanup
[jack2.git] / common / JackTransportEngine.h
blob0936b94ff5c6effc19968ae6785b69fe4fb768d0
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2006 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __JackTransportEngine__
22 #define __JackTransportEngine__
24 #include "transport_types.h"
25 #include "JackClientInterface.h"
26 #include "JackConstants.h"
27 #include "JackAtomicArrayState.h"
29 namespace Jack
32 typedef enum {
33 TransportCommandNone = 0,
34 TransportCommandStart = 1,
35 TransportCommandStop = 2,
36 } transport_command_t;
38 /*!
39 \brief The client transport structure.
41 We have:
43 - a "current" position
44 - a "pending" position prepared by the server at each cycle
45 - a "request" position wanted by a client
47 At the beginning of a cycle the server needs to select a new current position. When a request and a pending position are available,
48 the resquest takes precedence on the pending one. The server atomically switches to the new position.
49 The current position can be read by clients.
51 We use a JackAtomicArrayState pattern that allows to manage several "next" states independantly.
54 class JackTransportEngine : public JackAtomicArrayState<jack_position_t>
57 private:
59 jack_transport_state_t fTransportState;
60 volatile transport_command_t fTransportCmd;
61 transport_command_t fPreviousCmd; /* previous transport_cmd */
62 jack_time_t fSyncTimeout;
63 int fSyncTimeLeft;
64 int fTimeBaseMaster;
65 bool fPendingPos;
66 volatile SInt32 fWriteCounter;
68 bool CheckOneSynching(JackClientInterface** table);
69 bool CheckAllRolling(JackClientInterface** table);
70 void MakeAllStarting(JackClientInterface** table);
71 void SyncTimeout(jack_nframes_t frame_rate, jack_nframes_t buffer_size);
73 public:
75 JackTransportEngine();
77 ~JackTransportEngine()
80 void SetCommand(transport_command_t state)
82 fTransportCmd = state;
85 jack_transport_state_t GetState() const
87 return fTransportState;
90 int GetTimebaseMaster() const
92 return fTimeBaseMaster;
96 \brief
98 int ResetTimebase(int refnum);
101 \brief
103 int SetTimebase(int refnum, bool conditionnal);
106 \brief
108 void CycleBegin(jack_nframes_t frame_rate, jack_time_t time);
111 \brief
113 void CycleEnd(JackClientInterface** table, jack_nframes_t frame_rate, jack_nframes_t buffer_size);
116 \brief
118 void SetSyncTimeout(jack_time_t timeout)
120 fSyncTimeout = timeout;
123 void ReadCurrentPos(jack_position_t* pos);
125 jack_unique_t GenerateUniqueID()
127 return (jack_unique_t)INC_ATOMIC(&fWriteCounter);
130 static void TransportCopyPosition(jack_position_t* from, jack_position_t* to);
135 } // end of namespace
137 #endif