GComm  0.2.3
transport.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2012 Codership Oy <info@codership.com>
3  */
4 
11 #ifndef _GCOMM_TRANSPORT_HPP_
12 #define _GCOMM_TRANSPORT_HPP_
13 
14 #include "gcomm/uuid.hpp"
15 #include "gcomm/protolay.hpp"
16 #include "gcomm/protostack.hpp"
17 #include "gcomm/protonet.hpp"
18 
19 #include "gu_uri.hpp"
20 
21 namespace gcomm
22 {
28  class Transport;
29 }
30 
34 class gcomm::Transport : public Protolay
35 {
36 public:
37  virtual ~Transport();
38 
39  virtual size_t mtu() const = 0;
40  virtual const UUID& uuid() const = 0;
41  virtual std::string local_addr() const;
42  virtual std::string remote_addr() const;
43 
44  int err_no() const;
45 
46  virtual void connect(bool start_prim)
47  {
48  gu_throw_fatal << "connect(start_prim) not supported";
49  }
50  virtual void connect() // if not overloaded, will default to connect(bool)
51  {
52  connect(false);
53  }
54  virtual void connect(const gu::URI& uri)
55  {
56  gu_throw_fatal << "connect(URI) not supported";
57  }
58 
59  virtual void close(bool force = false) = 0;
60  virtual void close(const UUID& uuid)
61  {
62  gu_throw_error(ENOTSUP) << "close(UUID) not supported by "
63  << uri_.get_scheme();
64  }
65 
66  virtual void listen();
67  virtual std::string listen_addr() const
68  {
69  gu_throw_fatal << "not supported";
70  }
71  virtual Transport* accept();
72  virtual void handle_accept(Transport*)
73  {
74  gu_throw_error(ENOTSUP) << "handle_accept() not supported by"
75  << uri_.get_scheme();
76  }
77  virtual void handle_connect()
78  {
79  gu_throw_error(ENOTSUP) << "handle_connect() not supported by"
80  << uri_.get_scheme();
81  }
82 
83  virtual int handle_down(Datagram&, const ProtoDownMeta&) = 0;
84  virtual void handle_up (const void*, const Datagram&, const ProtoUpMeta&) = 0;
85  virtual void handle_stable_view(const View& view) { }
86  Protostack& pstack() { return pstack_; }
87  Protonet& pnet() { return pnet_; }
88 
89  static Transport* create(Protonet&, const std::string&);
90  static Transport* create(Protonet&, const gu::URI&);
91 
92 protected:
93  Transport (Protonet&, const gu::URI&);
94  Protostack pstack_;
95  Protonet& pnet_;
96  gu::URI uri_;
97  int error_no_;
98 
99 private:
100  Transport (const Transport&);
101  Transport& operator=(const Transport&);
102 };
103 
104 
105 
106 #endif // _GCOMM_TRANSPORT_HPP_
Definition: protostack.hpp:24
Definition: protonet.hpp:37
Transport interface.
Definition: transport.hpp:34
Definition: view.hpp:119
Definition: protolay.hpp:192
Protocol layer interface definitions.
Definition: protolay.hpp:77
Definition: uuid.hpp:26
Definition: protolay.hpp:168
Datagram container.
Definition: datagram.hpp:151