LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/sandesh/library/cpp - sandesh_server.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 2 6 33.3 %
Date: 2026-11-09 02:10:49 Functions: 2 5 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : //
       7             : // sandesh_server.h
       8             : //
       9             : // Sandesh Analytics Database Server
      10             : //
      11             : 
      12             : #ifndef __SANDESH_SERVER_H__
      13             : #define __SANDESH_SERVER_H__
      14             : 
      15             : #include <mutex>
      16             : 
      17             : #include <boost/asio.hpp>
      18             : #include <boost/asio/ip/tcp.hpp>
      19             : #include <boost/ptr_container/ptr_map.hpp>
      20             : #include <boost/scoped_ptr.hpp>
      21             : #include <boost/dynamic_bitset.hpp>
      22             : #include <base/lifetime.h>
      23             : #include <sandesh/sandesh.h>
      24             : #include <io/ssl_server.h>
      25             : #include <io/tcp_session.h>
      26             : 
      27             : class SandeshConnection;
      28             : class SandeshSession;
      29             : class SandeshStateMachine;
      30             : class LifetimeActor;
      31             : class LifetimeManager;
      32             : class SandeshMessage;
      33             : 
      34             : class SandeshServer : public SslServer {
      35             : public:
      36             :     explicit SandeshServer(EventManager *evm, const SandeshConfig &config);
      37             :     virtual ~SandeshServer();
      38             : 
      39             :     virtual bool Initialize(short port, const std::string &ip="0.0.0.0");
      40             :     virtual TcpSession *CreateSession();
      41             :     void Initiate();
      42             :     void Shutdown();
      43             :     virtual void SessionShutdown();
      44             : 
      45             :     LifetimeManager *lifetime_manager();
      46             :     LifetimeActor *deleter();
      47             :     int lifetime_mgr_task_id();
      48             : 
      49             :     SandeshConnection *FindConnection(const Endpoint &peer_addr);
      50             :     void RemoveConnection(SandeshConnection *connection);
      51           0 :     virtual bool DisableSandeshLogMessages() const { return true; }
      52             : 
      53           0 :     virtual bool ReceiveResourceUpdate(SandeshSession *session,
      54           0 :             bool rsc) { return true; }
      55             :     virtual bool ReceiveSandeshMsg(SandeshSession *session,
      56             :         const SandeshMessage *msg, bool resource) = 0;
      57             :     virtual bool ReceiveSandeshCtrlMsg(SandeshStateMachine *state_machine,
      58             :             SandeshSession *session, const Sandesh *sandesh);
      59           0 :     virtual void DisconnectSession(SandeshSession *session) {}
      60             :     size_t ConnectionsCount() { return connection_.size(); }
      61             :     int AllocConnectionIndex();
      62             :     void FreeConnectionIndex(int);
      63             : 
      64             : protected:
      65             :     virtual SslSession *AllocSession(SslSocket *socket);
      66             :     virtual bool AcceptSession(TcpSession *session);
      67             :     // Session read, write, and state machine tasks run exclusively
      68          37 :     int session_writer_task_id() const { return sm_task_id_; }
      69          37 :     int session_reader_task_id() const { return session_reader_task_id_; }
      70             : 
      71             : private:
      72             :     static const int kMaxInitRetries = 5;
      73             :     static const std::string kSessionReaderTask;
      74             :     static const std::string kStateMachineTask;
      75             :     static const std::string kLifetimeMgrTask;
      76             :     static bool task_policy_set_;
      77             : 
      78             :     class DeleteActor;
      79             :     friend class DeleteActor;
      80             : 
      81             :     typedef boost::ptr_map<boost::asio::ip::tcp::endpoint,
      82             :                            SandeshConnection> SandeshConnectionMap;
      83             :     typedef boost::ptr_container_detail::ref_pair<
      84             :                    boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>,
      85             :                    SandeshConnection *const> SandeshConnectionPair;
      86             :     bool Compare(const Endpoint &peer_addr, const SandeshConnectionPair &) const;
      87             : 
      88             :     SandeshConnectionMap connection_;
      89             :     boost::dynamic_bitset<> conn_bmap_;
      90             :     int sm_task_id_;
      91             :     int session_reader_task_id_;
      92             :     int lifetime_mgr_task_id_;
      93             :     boost::scoped_ptr<LifetimeManager> lifetime_manager_;
      94             :     boost::scoped_ptr<DeleteActor> deleter_;
      95             :     // Protect connection map and bmap
      96             :     std::mutex mutex_;
      97             : 
      98             :     DISALLOW_COPY_AND_ASSIGN(SandeshServer);
      99             : };
     100             : 
     101             : #endif // __SANDESH_SERVER_H__

Generated by: LCOV version 1.14