Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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 }
00152
00153 #endif