OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sandesh_connection.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh_connection.h
7 //
8 // Sandesh connection class
9 //
10 
11 #ifndef __SANDESH_CONNECTION_H__
12 #define __SANDESH_CONNECTION_H__
13 
14 #include <boost/asio/ip/tcp.hpp>
15 
16 #include <base/util.h>
17 #include <base/lifetime.h>
18 #include "sandesh_state_machine.h"
19 
20 class Sandesh;
21 class SandeshSession;
22 class TcpSession;
23 class TcpServer;
24 class SandeshUVE;
25 class SandeshHeader;
26 class SandeshMessage;
27 
29 public:
30  typedef boost::asio::ip::tcp::endpoint Endpoint;
31  SandeshConnection(const char *prefix, TcpServer *server, Endpoint endpoint,
32  int task_instance, int task_id);
33  virtual ~SandeshConnection();
34 
35  // Invoked from server when a session is accepted.
37  virtual bool ReceiveMsg(const std::string &msg, SandeshSession *session);
38 
39  TcpServer *server() { return server_; }
40 
41  Endpoint endpoint() { return endpoint_; }
42  bool SendSandesh(Sandesh *snh);
43 
45 
46  SandeshSession *session() const;
48 
49  std::string StateName() const { return state_machine_->StateName(); }
50 
51  int GetTaskInstance() const {
52  // Parallelism between connections
53  return task_instance_;
54  }
55 
56  int GetTaskId() const {
57  return task_id_;
58  }
59 
60  void Initialize() {
61  state_machine_->Initialize();
62  }
63 
64  void Shutdown();
65  bool MayDelete() const;
66 
67  void SetAdminState(bool down);
68 
69  virtual bool ProcessResourceUpdate(bool res) { return true; }
70  virtual bool ProcessSandeshMessage(const SandeshMessage *msg,
71  bool resource) = 0;
72  virtual bool ProcessSandeshCtrlMessage(const std::string &msg,
73  const SandeshHeader &header, const std::string sandesh_name,
74  const uint32_t header_offset) = 0;
75  virtual void ProcessDisconnect(SandeshSession * sess) = 0;
76 
77  virtual void ManagedDelete() = 0;
78  virtual LifetimeActor *deleter() = 0;
79  virtual LifetimeManager *lifetime_manager() = 0;
80  virtual void Destroy() = 0;
81 
82 protected:
84 
85 private:
87 
93  int task_id_;
94  boost::scoped_ptr<SandeshStateMachine> state_machine_;
95 
97 };
98 
100 public:
102  int task_instance, int task_id);
103  virtual ~SandeshServerConnection();
104 
105  virtual bool ProcessResourceUpdate(bool res);
106  virtual bool ProcessSandeshMessage(const SandeshMessage *msg,
107  bool resource);
108  virtual bool ProcessSandeshCtrlMessage(const std::string &msg,
109  const SandeshHeader &header, const std::string sandesh_name,
110  const uint32_t header_offset);
112 
113  virtual void ManagedDelete();
114  virtual LifetimeActor *deleter();
116  virtual void Destroy();
117 
118 private:
119  class DeleteActor;
120  boost::scoped_ptr<DeleteActor> deleter_;
122 
124 };
125 
126 #endif // __SANDESH_CONNECTION_H__
virtual LifetimeManager * lifetime_manager()
boost::scoped_ptr< DeleteActor > deleter_
virtual bool ProcessResourceUpdate(bool res)
TcpServer * server()
virtual void Destroy()=0
SandeshConnection(const char *prefix, TcpServer *server, Endpoint endpoint, int task_instance, int task_id)
SandeshSession * session() const
void AcceptSession(SandeshSession *session)
virtual LifetimeActor * deleter()=0
LifetimeRef< SandeshServerConnection > server_delete_ref_
SandeshServerConnection(TcpServer *server, Endpoint endpoint, int task_instance, int task_id)
DISALLOW_COPY_AND_ASSIGN(SandeshConnection)
boost::asio::ip::tcp::endpoint Endpoint
std::string StateName() const
virtual bool ProcessSandeshMessage(const SandeshMessage *msg, bool resource)=0
virtual bool ProcessSandeshCtrlMessage(const std::string &msg, const SandeshHeader &header, const std::string sandesh_name, const uint32_t header_offset)=0
virtual void ProcessDisconnect(SandeshSession *sess)=0
virtual void ManagedDelete()=0
void SetAdminState(bool down)
void set_session(SandeshSession *session)
SandeshSession * session_
virtual LifetimeActor * deleter()
friend class SandeshServerStateMachineTest
DISALLOW_COPY_AND_ASSIGN(SandeshServerConnection)
virtual bool ProcessResourceUpdate(bool res)
int GetTaskInstance() const
virtual LifetimeManager * lifetime_manager()=0
virtual void ProcessDisconnect(SandeshSession *session)
virtual bool ProcessSandeshMessage(const SandeshMessage *msg, bool resource)
int GetTaskId() const
SandeshStateMachine * state_machine() const
virtual bool ReceiveMsg(const std::string &msg, SandeshSession *session)
virtual bool ProcessSandeshCtrlMessage(const std::string &msg, const SandeshHeader &header, const std::string sandesh_name, const uint32_t header_offset)
bool SendSandesh(Sandesh *snh)
boost::scoped_ptr< SandeshStateMachine > state_machine_