1 /******************************************************************************
3 File: BufferStreamManager.h
5 Copyright 1995-97, Be Incorporated
7 ******************************************************************************/
8 #ifndef _BUFFER_STREAM_MANAGER_H
9 #define _BUFFER_STREAM_MANAGER_H
13 #include <SupportDefs.h>
16 #include "OldBufferStream.h"
23 #define B_DEFAULT_BSTREAM_COUNT 3
24 #define B_DEFAULT_BSTREAM_SIZE B_PAGE_SIZE
25 #define B_DEFAULT_BSTREAM_DELAY 10000
26 #define B_DEFAULT_BSTREAM_TIMEOUT 5000000
30 B_IDLE
= 100, /* stream is shut down */
31 B_RUNNING
, /* stream is running */
32 B_STOPPING
/* waiting for final buffer to return */
37 Class definition for BBufferStreamManager
41 class BBufferStreamManager
{
45 BBufferStreamManager(char* name
);
46 virtual ~BBufferStreamManager();
50 BBufferStream
*Stream() const;
52 int32
BufferCount() const;
53 void SetBufferCount(int32 count
);
55 int32
BufferSize() const;
56 void SetBufferSize(int32 bytes
);
58 /* Get or set the minimum delay between sending out successive buffers.
59 * Although the StreamManager automatically shuts down when there
60 * are no more subscribers, setting the minimum delay can prevent
61 * prevent runaway streams. A zero or negative value means no
64 bigtime_t
BufferDelay() const;
65 void SetBufferDelay(bigtime_t usecs
);
67 /* If no Buffers return to the StreamManager within a period of time, the
68 * StreamManager will decide that one of the subscribers is broken and
69 * will go hunting for it. When it finds the offending subscriber,
70 * it will be removed from the chain with impunity.
72 * The default is B_DEFAULT_TIMEOUT. Setting the timeout to 0 or a
73 * negative number will disable this.
75 bigtime_t
Timeout() const;
76 void SetTimeout(bigtime_t usecs
);
78 /****************************************************************
79 * Control the running of the stream.
83 /* Set the pending state to B_RUNNING and, if required, start up
84 * the processing thread. The processing thread will start
85 * emitting buffers to the stream.
89 /* Set the pending state to B_STOPPING. The processing thread will
90 * stop emitting new buffers to the stream, and when all buffers
91 * are accounted for, will automatically set the desired state
96 /* Set the desired state to B_IDLE. The processing thread will
97 * stop immediately and all buffers will be "reclaimed" back
98 * to the StreamManager.
100 stream_state
Abort();
102 /* Return the current state of the stream (B_RUNNING, B_STOPPING, or B_IDLE).
104 stream_state
State() const;
106 /* When NotificationPort is set, the receiver will get a message
107 * whenever the state of the StreamManager changes. The msg_id of the
108 * message will be the new state of the StreamManager.
110 port_id
NotificationPort() const;
111 void SetNotificationPort(port_id port
);
113 /* Lock the data structures associated with this StreamManager
118 /****************************************************************
119 * Subscribe functions
122 status_t
Subscribe(BBufferStream
*stream
);
123 status_t
Unsubscribe();
124 subscriber_id
ID() const;
128 Protected member functions.
133 /****************************************************************
135 * The processing thread. This thread waits to acquire a Buffer
136 * (or for the timeout to expire) and takes appropriate action.
138 virtual void StartProcessing();
139 virtual void StopProcessing();
140 static status_t
_ProcessingThread(void *arg
);
141 virtual void ProcessingThread();
143 /* Set the state of the stream. If newState is the same as the
144 * current state, this is a no-op. Otherwise, this method will
145 * notify anyone listening on the notification port about the
146 * changed state and will send a StateChange buffer through the
149 virtual void SetState(stream_state newState
);
151 /* Snooze until the desired time arrives. Returns the
152 * current time upon returning.
154 bigtime_t
SnoozeUntil(bigtime_t sys_time
);
162 virtual void _ReservedBufferStreamManager1();
163 virtual void _ReservedBufferStreamManager2();
164 virtual void _ReservedBufferStreamManager3();
166 /****************************************************************
172 BBufferStream
*fStream
; /* a BBufferStream object */
173 stream_state fState
; /* running, stopping, etc. */
176 int32 fBufferCount
; /* desired # of buffers */
177 int32 fBufferSize
; /* desired size of each buffer */
178 bigtime_t fBufferDelay
; /* minimum time between sends */
179 bigtime_t fTimeout
; /* watchdog timer */
181 port_id fNotifyPort
; /* when set, send change of state msgs */
182 thread_id fProcessingThread
; /* thread to dispatch buffers */
183 subscriber_id fManagerID
; /* StreamManager's subID in fStream */
190 #endif // #ifdef _BUFFER_STREAM_MANAGER_H