IBR-DTNSuite
0.8
|
00001 #ifndef LOWPANSTREAM_H_ 00002 #define LOWPANSTREAM_H_ 00003 00004 #include <ibrcommon/thread/Conditional.h> 00005 #include <streambuf> 00006 #include <iostream> 00007 #include <stdint.h> 00008 00009 namespace ibrcommon 00010 { 00011 class lowpanstream_callback 00012 { 00013 public: 00014 virtual ~lowpanstream_callback() { }; 00019 virtual void send_cb(char *buf, int len, unsigned int address) = 0; 00020 }; 00021 00022 class lowpanstream : public std::basic_streambuf<char, std::char_traits<char> >, public std::iostream 00023 { 00024 public: 00028 static const size_t BUFF_SIZE = 113; 00029 00030 lowpanstream(lowpanstream_callback &callback, unsigned int address); 00031 virtual ~lowpanstream(); 00032 00038 void queue(char *buf, int len); 00039 00040 void abort(); 00041 00042 protected: 00043 virtual int sync(); 00044 virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof()); 00045 virtual std::char_traits<char>::int_type underflow(); 00046 00047 unsigned int _address; 00048 00049 private: 00050 bool _in_first_segment; 00051 char _out_stat; 00052 00053 // Input buffer 00054 char *in_buf_; 00055 int in_buf_len; 00056 bool in_buf_free; 00057 00058 // Output buffer 00059 char *out_buf_; 00060 char *out2_buf_; 00061 00062 // sequence number 00063 uint8_t in_seq_num_; 00064 uint8_t out_seq_num_; 00065 long out_seq_num_global; 00066 00067 bool _abort; 00068 00069 lowpanstream_callback &callback; 00070 00071 ibrcommon::Conditional in_buf_cond; 00072 }; 00073 } 00074 #endif /* LOWPANSTREAM_H_ */