stream.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 ********************************************************************/
00034 
00035 #ifndef ROSBAG_STREAM_H
00036 #define ROSBAG_STREAM_H
00037 
00038 #include <ios>
00039 #include <stdint.h>
00040 #include <string>
00041 
00042 #include <boost/shared_ptr.hpp>
00043 
00044 #include <bzlib.h>
00045 
00046 #include "rosbag/exceptions.h"
00047 #include "rosbag/macros.h"
00048 
00049 namespace rosbag {
00050 
00051 namespace compression
00052 {
00053     enum CompressionType
00054     {
00055         Uncompressed = 0,
00056         BZ2          = 1,
00057     };
00058 }
00059 typedef compression::CompressionType CompressionType;
00060 
00061 class ChunkedFile;
00062 
00063 class ROSBAG_DECL Stream
00064 {
00065 public:
00066     Stream(ChunkedFile* file);
00067     virtual ~Stream();
00068 
00069     virtual CompressionType getCompressionType() const = 0;
00070 
00071     virtual void write(void* ptr, size_t size) = 0;
00072     virtual void read (void* ptr, size_t size) = 0;
00073 
00074     virtual void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len) = 0;
00075 
00076     virtual void startWrite();
00077     virtual void stopWrite();
00078 
00079     virtual void startRead();
00080     virtual void stopRead();
00081 
00082 protected:
00083     FILE*    getFilePointer();
00084     uint64_t getCompressedIn();
00085     void     setCompressedIn(uint64_t nbytes);
00086     void     advanceOffset(uint64_t nbytes);
00087     char*    getUnused();
00088     int      getUnusedLength();
00089     void     setUnused(char* unused);
00090     void     setUnusedLength(int nUnused);
00091     void     clearUnused();
00092 
00093 protected:
00094     ChunkedFile* file_;
00095 };
00096 
00097 class ROSBAG_DECL StreamFactory
00098 {
00099 public:
00100     StreamFactory(ChunkedFile* file);
00101 
00102     boost::shared_ptr<Stream> getStream(CompressionType type) const;
00103 
00104 private:
00105     boost::shared_ptr<Stream> uncompressed_stream_;
00106     boost::shared_ptr<Stream> bz2_stream_;
00107 };
00108 
00109 class ROSBAG_DECL UncompressedStream : public Stream
00110 {
00111 public:
00112     UncompressedStream(ChunkedFile* file);
00113 
00114     CompressionType getCompressionType() const;
00115 
00116     void write(void* ptr, size_t size);
00117     void read(void* ptr, size_t size);
00118 
00119     void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
00120 };
00121 
00125 class ROSBAG_DECL BZ2Stream : public Stream
00126 {
00127 public:
00128     BZ2Stream(ChunkedFile* file);
00129 
00130     CompressionType getCompressionType() const;
00131 
00132     void startWrite();
00133     void write(void* ptr, size_t size);
00134     void stopWrite();
00135 
00136     void startRead();
00137     void read(void* ptr, size_t size);
00138     void stopRead();
00139 
00140     void decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
00141 
00142 private:
00143     int     verbosity_;        
00144     int     block_size_100k_;  
00145     int     work_factor_;      
00146 
00147     BZFILE* bzfile_;           
00148     int     bzerror_;          
00149 };
00150 
00151 } // namespace rosbag
00152 
00153 #endif


rosbag_storage
Author(s):
autogenerated on Fri Aug 28 2015 12:33:40