sipxmedialib  Version 3.3
StreamDataSource.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2006 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _StreamDataSource_h_
16 #define _StreamDataSource_h_
17 
18 // SYSTEM INCLUDES
19 // APPLICATION INCLUDES
20 #include <utl/UtlString.h>
21 #include "mp/StreamDefs.h"
22 #include "os/OsStatus.h"
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 
31 typedef enum // Data source event definitions
32 {
33  LoadingStartedEvent, // Data source statred loading
34  LoadingThrottledEvent, // Data source throttled
35  LoadingCompletedEvent, // Data source completed loading
36  LoadingErrorEvent // Data source error
37 
39 
40 // FORWARD DECLARATIONS
42 
43 
48 {
49 /* //////////////////////////// PUBLIC //////////////////////////////////// */
50 public:
51 
52 /* ============================ CREATORS ================================== */
54 
55 
57  StreamDataSource(int iFlags = 0);
62  virtual ~StreamDataSource();
64 
66 
67 /* ============================ MANIPULATORS ============================== */
69 
70 
72  virtual OsStatus open() = 0 ;
73 
75  virtual OsStatus close() = 0 ;
76 
78  virtual OsStatus destroyAndDelete() = 0 ;
79 
82  virtual OsStatus read(char *szBuffer, int iLength, int& iLengthRead) = 0;
89  virtual OsStatus peek(char* szBuffer, int iLength, int& iLengthRead) = 0;
97  virtual OsStatus interrupt() ;
106  virtual OsStatus seek(unsigned int iLocation) = 0 ;
112  void setListener(StreamDataSourceListener* pListener);
115 
117 
118 /* ============================ ACCESSORS ================================= */
120 
121 
123  virtual OsStatus getLength(int& iLength) = 0 ;
124 
126  virtual OsStatus getPosition(int& iPosition) = 0 ;
127 
129  virtual OsStatus toString(UtlString& string) = 0 ;
130  // This is often used for debugging purposes.
131 
133  int getFlags() ;
134 
136 
137 /* ============================ INQUIRY =================================== */
139 
140 
142 
143 /* ============================ TESTING =================================== */
144 
145 #ifdef MP_STREAM_DEBUG /* [ */
146 static const char* getEventString(StreamDataSourceEvent event);
147 #endif /* MP_STREAM_DEBUG ] */
148 
149 /* //////////////////////////// PROTECTED ///////////////////////////////// */
150 protected:
151 
153  StreamDataSource(const StreamDataSource& rStreamDataSource);
154 
157 
159  void fireEvent(StreamDataSourceEvent event);
160 
161 
162 /* //////////////////////////// PRIVATE /////////////////////////////////// */
163 private:
165  int miFlags;
166 };
167 
168 /* ============================ INLINE METHODS ============================ */
169 
170 #endif // _StreamDataSource_h_
virtual OsStatus read(char *szBuffer, int iLength, int &iLengthRead)=0
An abstraction definition of a stream data source.
Definition: StreamDataSource.h:47
StreamDataSourceEvent
Definition: StreamDataSource.h:31
virtual OsStatus seek(unsigned int iLocation)=0
Moves the stream pointer to the an absolute location.
Definition: StreamDataSource.h:33
virtual OsStatus destroyAndDelete()=0
Destroys and deletes the data source object.
StreamDataSource(int iFlags=0)
Constructors a StreamDataSource given optional flags.
Definition: StreamDataSource.cpp:29
Definition: StreamDataSource.h:36
StreamDataSource & operator=(const StreamDataSource &rhs)
Assignment operator (not supported)
Definition: StreamDataSource.cpp:102
virtual OsStatus close()=0
Closes the data source.
int getFlags()
Gets the flags specified at time of construction.
Definition: StreamDataSource.cpp:63
Definition: StreamDataSource.h:35
virtual OsStatus getPosition(int &iPosition)=0
Gets the current position within the stream.
void fireEvent(StreamDataSourceEvent event)
Fires a data source event to the interested consumer.
Definition: StreamDataSource.cpp:116
Definition: StreamDataSourceListener.h:32
int miFlags
flags specified during construction
Definition: StreamDataSource.h:165
virtual OsStatus getLength(int &iLength)=0
Gets the length of the stream (if available)
virtual OsStatus interrupt()
Interrupts any time consuming operation.
Definition: StreamDataSource.cpp:45
void setListener(StreamDataSourceListener *pListener)
Definition: StreamDataSource.cpp:54
Definition: StreamDataSource.h:34
virtual OsStatus peek(char *szBuffer, int iLength, int &iLengthRead)=0
Identical to read, except the stream pointer is not advanced.
StreamDataSourceListener * mpListener
data source listener
Definition: StreamDataSource.h:164
virtual OsStatus open()=0
Opens the data source.
virtual OsStatus toString(UtlString &string)=0
Renders a string describing this data source.
virtual ~StreamDataSource()
Destructor.
Definition: StreamDataSource.cpp:37