1 /*------------------------------------------------------------------------------
2 
3    Copyright (c) 2000-2007 Tyrell Corporation. All rights reserved.
4 
5    Tyrell DarkIce
6 
7    File     : Source.h
8    Version  : $Revision$
9    Author   : $Author$
10    Location : $HeadURL$
11 
12    Copyright notice:
13 
14     This program is free software; you can redistribute it and/or
15     modify it under the terms of the GNU General Public License
16     as published by the Free Software Foundation; either version 3
17     of the License, or (at your option) any later version.
18 
19     This program is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22     GNU General Public License for more details.
23 
24     You should have received a copy of the GNU General Public License
25     along with this program; if not, write to the Free Software
26     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 
28 ------------------------------------------------------------------------------*/
29 #ifndef SOURCE_H
30 #define SOURCE_H
31 
32 #ifndef __cplusplus
33 #error This is a C++ include file
34 #endif
35 
36 
37 /* ============================================================ include files */
38 
39 #include "Referable.h"
40 #include "Exception.h"
41 
42 
43 /* ================================================================ constants */
44 
45 
46 /* =================================================================== macros */
47 
48 
49 /* =============================================================== data types */
50 
51 /**
52  *  A general data source
53  *
54  *  @author  $Author$
55  *  @version $Revision$
56  */
57 class Source : public virtual Referable
58 {
59     private:
60 
61     protected:
62 
63         /**
64          *  Default Constructor.
65          *
66          *  @exception Exception
67          */
68         inline
Source(void)69         Source ( void )                             throw ( Exception )
70         {
71         }
72 
73         /**
74          *  Copy Constructor.
75          *
76          *  @param source the object to copy.
77          *  @exception Exception
78          */
79         inline
throw(Exception)80         Source (    const Source &  source )        throw ( Exception )
81         {
82         }
83 
84         /**
85          *  Assignment operator.
86          *
87          *  @param source the object to assign to this one.
88          *  @return a reference to this object.
89          *  @exception Exception
90          */
91         inline virtual Source &
throw(Exception)92         operator= ( const Source &  source )        throw ( Exception )
93         {
94             return *this;
95         }
96 
97 
98     public:
99 
100         /**
101          *  Destructor.
102          *
103          *  @exception Exception
104          */
105         inline virtual
~Source(void)106         ~Source ( void )                            throw ( Exception )
107         {
108         }
109 
110         /**
111          *  Open the Source.
112          *
113          *  @return true if opening was successful, false otherwise
114          *  @exception Exception
115          */
116         virtual bool
117         open ( void )                           throw ( Exception )     = 0;
118 
119         /**
120          *  Check if the Source is open.
121          *
122          *  @return true if the Source is open, false otherwise.
123          */
124         virtual bool
125         isOpen ( void ) const                   throw ()                = 0;
126 
127         /**
128          *  Check if the Source can be read from.
129          *  Blocks until the specified time for data to be available.
130          *
131          *  @param sec the maximum seconds to block.
132          *  @param usec micro seconds to block after the full seconds.
133          *  @return true if the Source is ready to be read from,
134          *          false otherwise.
135          *  @exception Exception
136          */
137         virtual bool
138         canRead (  unsigned int    sec,
139                    unsigned int    usec )       throw ( Exception )     = 0;
140 
141         /**
142          *  Read from the Source.
143          *
144          *  @param buf the buffer to read into.
145          *  @param len the number of bytes to read into buf
146          *  @return the number of bytes read (may be less than len).
147          *  @exception Exception
148          */
149         virtual unsigned int
150         read (     void          * buf,
151                    unsigned int    len )        throw ( Exception )     = 0;
152 
153         /**
154          *  Close the Source.
155          *
156          *  @exception Exception
157          */
158         virtual void
159         close ( void )                          throw ( Exception )     = 0;
160 };
161 
162 
163 /* ================================================= external data structures */
164 
165 
166 /* ====================================================== function prototypes */
167 
168 
169 
170 #endif  /* SOURCE_H */
171 
172