00001 /*===========================================================================*/ 00002 /* 00003 * This file is part of libogg++ - a c++ library for the Ogg transport format 00004 * 00005 * Copyright (C) 2006, 2007, 2008 Elaine Tsiang YueLien 00006 * 00007 * libogg++ is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the 00019 * Free Software Foundation, Inc. 00020 * 51 Franklin Street, Fifth Floor 00021 * Boston, MA 02110-1301, USA 00022 * 00023 *===========================================================================*/ 00028 /*===========================================================================*/ 00029 #ifndef LogicalToApplicationInterface 00030 #define LogicalToApplicationInterface 00031 00032 #ifdef __GNUG__ 00033 #pragma interface 00034 #endif 00035 00036 00037 namespace Ogg 00038 { 00039 class Logical; 00040 class Packet; 00041 } 00042 00043 #include <Ogg/Ogg.H> 00044 #include <Ogg/Transport.H> 00045 #include <Ogg/Exception.H> 00046 00047 namespace Ogg 00048 { 00050 00051 00058 class Packet 00059 { 00060 private: 00061 Packet(const Packet &); 00062 00063 Packet & 00064 operator =(const Packet &); 00065 00066 protected: 00067 Packet(){}; 00068 00069 public: 00070 void 00071 data(void * 00072 ,size_t 00073 ); 00074 00075 void * 00076 data(); 00077 00078 size_t 00079 size(); 00080 00081 PacketNo 00082 packetNo(); 00083 00084 }; 00085 00091 class Logical 00092 { 00093 private: 00094 void * impl_; 00095 00096 Logical(const Logical &); 00097 00098 Logical & 00099 operator =(const Logical &); 00100 00101 protected: 00103 Logical( 00104 bool dummy 00105 ) 00106 : impl_(0) 00107 {} 00108 00109 public: 00110 void * 00111 impl() 00112 { 00113 return(impl_); 00114 } 00115 00116 /*----- Exceptions thrown by a Logical thread ---------------------------------*/ 00117 00119 class SerialNotPositive : public Exception 00120 { 00121 public: 00122 SerialNotPositive( 00123 const long serialNo 00124 ) throw() 00125 : Exception("Serial no. ") 00126 { 00127 *this << serialNo << "is not positive" << std::endl; 00128 } 00129 00130 SerialNotPositive( 00131 const SerialNotPositive & ex 00132 ) throw() 00133 : Exception(ex) 00134 {} 00135 00136 ~SerialNotPositive() throw() 00137 {} 00138 } 00139 ; 00140 00142 class WriterAlreadyExists : public Exception 00143 { 00144 public: 00145 WriterAlreadyExists( 00146 const long serialNo 00147 ) throw() 00148 : Exception("Writer for this Logical already exists,") 00149 { 00150 *this << " serial no. = " << serialNo << std::endl; 00151 } 00152 00153 WriterAlreadyExists( 00154 const WriterAlreadyExists & ex 00155 ) throw() 00156 : Exception(ex) 00157 {} 00158 00159 ~WriterAlreadyExists() throw() 00160 {} 00161 } 00162 ; 00163 00165 class NotForWriting : public Exception 00166 { 00167 public: 00168 NotForWriting( 00169 const long serialNo 00170 ) throw() 00171 : Exception("This Logical not for writing") 00172 { 00173 *this << " serial no. = " << serialNo << std::endl; 00174 } 00175 00176 NotForWriting( 00177 const NotForWriting & ex 00178 ) throw() 00179 : Exception(ex) 00180 {} 00181 00182 ~NotForWriting() throw() 00183 {} 00184 } 00185 ; 00186 00188 class ReaderAlreadyExists : public Exception 00189 { 00190 public: 00191 ReaderAlreadyExists( 00192 const long serialNo 00193 ) throw() 00194 : Exception("Reader for this Logical already exists,") 00195 { 00196 *this << " serial no. = " << serialNo << std::endl; 00197 } 00198 00199 ReaderAlreadyExists( 00200 const ReaderAlreadyExists & ex 00201 ) throw() 00202 : Exception(ex) 00203 {} 00204 00205 ~ReaderAlreadyExists() throw() 00206 {} 00207 } 00208 ; 00209 00211 class NotForReading : public Exception 00212 { 00213 public: 00214 NotForReading( 00215 const long serialNo 00216 ) throw() 00217 : Exception("This Logical not for reading,") 00218 { 00219 *this << " serial no. = " << serialNo << std::endl; 00220 } 00221 00222 NotForReading( 00223 const NotForReading & ex 00224 ) throw() 00225 : Exception(ex) 00226 {} 00227 00228 ~NotForReading() throw() 00229 {} 00230 } 00231 ; 00232 00234 class MuxTooLate : public Exception 00235 { 00236 public: 00237 MuxTooLate( 00238 const long serialNo 00239 ) throw() 00240 : Exception("This Logical stream comes in too late - synchronize better,") 00241 { 00242 *this << " serial no. = " << serialNo << std::endl; 00243 } 00244 00245 MuxTooLate( 00246 const MuxTooLate & ex 00247 ) throw() 00248 : Exception(ex) 00249 {} 00250 00251 ~MuxTooLate() throw() 00252 {} 00253 } 00254 ; 00255 00257 class SerialNoAlreadyUsed : public Exception 00258 { 00259 public: 00260 SerialNoAlreadyUsed( 00261 const long serialNo 00262 ) throw() 00263 : Exception("This serial no. has been taken already,") 00264 { 00265 *this << " serial no. = " << serialNo << std::endl; 00266 } 00267 00268 SerialNoAlreadyUsed( 00269 const SerialNoAlreadyUsed & ex 00270 ) throw() 00271 : Exception(ex) 00272 {} 00273 00274 ~SerialNoAlreadyUsed() throw() 00275 {} 00276 } 00277 ; 00278 00280 class StreamAlreadyClaimed : public Exception 00281 { 00282 public: 00283 StreamAlreadyClaimed( 00284 const long serialNo 00285 ) throw() 00286 : Exception("Stream already has been claimed,") 00287 { 00288 *this << " serial no. = " << serialNo << std::endl; 00289 } 00290 00291 StreamAlreadyClaimed( 00292 const StreamAlreadyClaimed & ex 00293 ) throw() 00294 : Exception(ex) 00295 {} 00296 00297 ~StreamAlreadyClaimed() throw() 00298 {} 00299 } 00300 ; 00301 00303 class NoSuchStream : public Exception 00304 { 00305 public: 00306 NoSuchStream( 00307 const long serialNo 00308 ) throw() 00309 : Exception("No stream found,") 00310 { 00311 *this << " serial no. = " << serialNo << std::endl; 00312 } 00313 00314 NoSuchStream( 00315 const NoSuchStream & ex 00316 ) throw() 00317 : Exception(ex) 00318 {} 00319 00320 ~NoSuchStream() throw() 00321 {} 00322 } 00323 ; 00324 00326 class FailedToSelectStream : public Exception 00327 { 00328 public: 00329 FailedToSelectStream( 00330 const long serialNo 00331 ) throw() 00332 : Exception("Failed to find a stream with ") 00333 { 00334 *this << " serial no. = " << serialNo << std::endl; 00335 } 00336 00337 FailedToSelectStream( 00338 const FailedToSelectStream & ex 00339 ) throw() 00340 : Exception(ex) 00341 {} 00342 00343 ~FailedToSelectStream() throw() 00344 {} 00345 } 00346 ; 00347 00349 class SeekInternalError : public Exception 00350 { 00351 public: 00352 SeekInternalError( 00353 const long serialNo 00354 ) throw() 00355 : Exception("Please let developers know this happened.") 00356 { 00357 *this << " serial no. = " << serialNo << std::endl; 00358 } 00359 00360 SeekInternalError( 00361 const SeekInternalError & ex 00362 ) throw() 00363 : Exception(ex) 00364 {} 00365 00366 ~SeekInternalError() throw() 00367 {} 00368 } 00369 ; 00370 00371 /*- end Exceptions thrown by a Logical thread ---------------------------------*/ 00372 00374 Logical( 00375 Transport & transport 00376 ,long serialNo 00377 ); 00378 00380 Logical( 00381 Transport & transport 00382 ); 00383 00384 00388 virtual 00389 ~Logical(); 00390 00397 virtual 00398 bool 00399 selectCallback( 00400 Packet & firstPacket 00401 ) 00402 { 00403 return(true); 00404 } 00405 00411 long 00412 serialNo() const; 00413 00415 Transport & 00416 transport() const; 00417 00424 class Writer 00425 { 00426 private: 00427 Writer(const Writer &); 00428 00429 Writer & 00430 operator =(const Writer &); 00431 00432 protected: 00433 Writer(){}; 00434 00435 public: 00443 ~Writer(); 00444 00446 size_t 00447 dataSize() const; 00448 00453 void 00454 dataSize(size_t); 00455 00457 void 00458 flush(); 00459 00464 void 00465 beginData(); 00466 00471 void 00472 granulePosition( 00473 Position 00474 ); 00475 00477 Position 00478 granulePosition() const; 00479 00481 size_t 00482 pageSize() const; 00483 00488 void 00489 pageSize( 00490 size_t 00491 ); 00492 00494 Writer & 00495 operator ++(); 00496 00498 Packet * 00499 operator->() const throw(); 00500 00502 Packet * 00503 packet() const throw() 00504 { 00505 return(operator->()); 00506 } 00507 }; 00508 00515 class Reader 00516 { 00517 private: 00518 Reader(const Reader &); 00519 00520 Reader & 00521 operator =(const Reader &); 00522 00523 protected: 00524 Reader(){}; 00525 00526 public: 00531 ~Reader(); 00532 00534 Reader & 00535 operator ++(); 00536 00541 Reader & 00542 operator +=(PacketNo packets); 00543 00548 Reader & 00549 operator =(Position position); 00550 00551 bool 00552 ending() const; 00553 00554 Error 00555 transportError() 00556 const; 00557 00558 Position 00559 granulePosition() 00560 const; 00561 00563 Packet * 00564 operator->() const throw(); 00565 00567 Packet * 00568 packet() const throw() 00569 { 00570 return(operator->()); 00571 } 00572 }; 00573 00578 Writer & 00579 writer(); 00580 00581 00586 Reader & 00587 reader(); 00588 00589 }; 00591 }; 00592 #endif