IBR-DTNSuite  0.10
lowpanstream.h
Go to the documentation of this file.
1 /*
2  * lowpanstream.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef LOWPANSTREAM_H_
23 #define LOWPANSTREAM_H_
24 
26 #include "ibrcommon/net/vaddress.h"
27 #include <streambuf>
28 #include <iostream>
29 #include <vector>
30 #include <stdint.h>
31 
32 namespace ibrcommon
33 {
35  {
36  public:
37  virtual ~lowpanstream_callback() { };
42  virtual void send_cb(const char *buf, size_t len, const ibrcommon::vaddress &address) = 0;
43  };
44 
45  class lowpanstream : public std::basic_streambuf<char, std::char_traits<char> >, public std::iostream
46  {
47  public:
51  static const size_t BUFF_SIZE = 113;
52 
53  lowpanstream(lowpanstream_callback &callback, const ibrcommon::vaddress &address);
54  virtual ~lowpanstream();
55 
61  void queue(char *buf, size_t len);
62 
63  void abort();
64 
65  protected:
66  virtual int sync();
67  virtual std::char_traits<char>::int_type overflow(std::char_traits<char>::int_type = std::char_traits<char>::eof());
68  virtual std::char_traits<char>::int_type underflow();
69 
71 
72  private:
73  bool _in_first_segment;
74  char _out_stat;
75 
76  // Input buffer
77  std::vector<char> in_buf_;
78  size_t in_buf_len;
79  bool in_buf_free;
80 
81  // Output buffer
82  std::vector<char> out_buf_;
83  std::vector<char> out2_buf_;
84 
85  // sequence number
86  uint8_t in_seq_num_;
87  uint8_t out_seq_num_;
88  long out_seq_num_global;
89 
90  bool _abort;
91 
92  lowpanstream_callback &callback;
93 
94  ibrcommon::Conditional in_buf_cond;
95  };
96 }
97 #endif /* LOWPANSTREAM_H_ */