1 /****************************************************************************** 2 3 File: Subscriber.h 4 5 Description: Support for communication with a buffer stream server 6 7 Copyright 1995-97, Be Incorporated 8 9 ******************************************************************************/ 10 11 #ifndef _SUBSCRIBER_H 12 #define _SUBSCRIBER_H 13 14 #include <MediaDefs.h> 15 16 #include "OldBufferStream.h" 17 18 /* ================ 19 declarations 20 ================ */ 21 22 typedef bool (*enter_stream_hook)(void *userData, char *buffer, size_t count, 23 void *header); 24 typedef status_t (*exit_stream_hook)(void *userData, status_t error); 25 26 /* ================ 27 Class definition for BSubscriber 28 ================ */ 29 30 class BSubscriber 31 { 32 public: 33 BSubscriber(const char *name = NULL); 34 virtual ~BSubscriber(); 35 36 /* ================ 37 Gaining access to the Buffer Stream 38 ================ */ 39 40 virtual status_t Subscribe(BAbstractBufferStream* stream); 41 virtual status_t Unsubscribe(); 42 43 subscriber_id ID() const; 44 const char *Name() const; 45 46 void SetTimeout(bigtime_t microseconds); 47 bigtime_t Timeout() const; 48 49 /* ================ 50 Streaming functions. 51 ================ */ 52 53 virtual status_t EnterStream(subscriber_id neighbor, 54 bool before, 55 void *userData, 56 enter_stream_hook entryFunction, 57 exit_stream_hook exitFunction, 58 bool background); 59 60 virtual status_t ExitStream(bool synch=FALSE); 61 62 bool IsInStream() const; 63 64 /* ================ 65 Protected members (may be used by inherited classes) 66 ================ */ 67 68 protected: 69 70 static status_t _ProcessLoop(void *arg); 71 virtual status_t ProcessLoop(); 72 BAbstractBufferStream *Stream() const; 73 74 /* ================ 75 Private members 76 ================ */ 77 78 private: 79 80 virtual void _ReservedSubscriber1(); 81 virtual void _ReservedSubscriber2(); 82 virtual void _ReservedSubscriber3(); 83 84 char *fName; /* name given to constructor */ 85 subscriber_id fSubID; /* our subscriber_id */ 86 sem_id fSem; /* stream semaphore */ 87 BAbstractBufferStream *fStream; /* buffer stream */ 88 void *fUserData; /* arg to fStreamFn and fCompletionFn */ 89 enter_stream_hook fStreamFn; /* per-buffer user function */ 90 exit_stream_hook fCompletionFn; /* called after streaming stops */ 91 bool fCallStreamFn; /* true while we should call fStreamFn */ 92 bigtime_t fTimeout; /* time out while awaiting buffers */ 93 thread_id fBackThread; 94 sem_id fSynchLock; 95 96 int32 fFileID; /* reserved for future use */ 97 uint32 _reserved[4]; 98 }; 99 100 #endif // #ifdef _SUBSCRIBER_H 101