libfluid
The ONF OpenFlow driver
BaseOFConnection.hh
1 
2 #ifndef __BASEOFCONNECTION_HH__
3 #define __BASEOFCONNECTION_HH__
4 
5 #include <stdlib.h>
6 #include <vector>
7 
8 #include "fluid/base/EventLoop.hh"
9 
10 namespace fluid_base {
11 class BaseOFHandler;
12 
22 public:
35  BaseOFConnection(int id,
36  BaseOFHandler* ofhandler,
37  EventLoop* evloop,
38  int fd,
39  bool secure);
40  virtual ~BaseOFConnection();
41 
43  enum Event {
50  };
51 
60  void send(void* data, size_t len);
61 
73  void add_timed_callback(void* (*cb)(void*), int interval, void* arg);
74  // TODO: add the option for the function to unschedule itself by returning
75  // false
76 
77  // TODO: these methods are not thread-safe, and they really aren't
78  // currently called from more than one thread. But perhaps we should
79  // consider that...
80 
91  void set_manager(void* manager);
92 
98  void* get_manager();
99 
103  int get_id();
104 
115  void close();
116 
122  static void free_data(void* data);
123 
124 private:
125  int id;
126  EventLoop* evloop;
127  class OFReadBuffer;
128  OFReadBuffer* buffer;
129  void* manager;
130  bool secure;
131  BaseOFHandler* ofhandler;
132 
133  bool running;
134 
135  // Types for internal use (timed callbacks)
136  struct timed_callback {
137  void* (*cb)(void*);
138  void* cb_arg;
139  void* data;
140  };
141  std::vector<struct timed_callback*> timed_callbacks;
142 
143  void notify_msg_cb(void* data, size_t n);
144  void notify_conn_cb(BaseOFConnection::Event event_type);
145  void do_close();
146 
147  class LibEventBaseOFConnection;
148  friend class LibEventBaseOFConnection;
149  LibEventBaseOFConnection* m_implementation;
150 };
151 
157 public:
158  virtual ~BaseOFHandler() {}
159 
173  virtual void base_connection_callback(BaseOFConnection* conn,
174  BaseOFConnection::Event event_type)
175  = 0;
176 
194  virtual void base_message_callback(BaseOFConnection* conn,
195  void* data,
196  size_t len) = 0;
197 
201  virtual void free_data(void* data) = 0;
202 };
203 
204 }
205 
206 #endif