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

Generated by: LCOV version 1.14