Piac test code coverage report
Current view: top level - src - cli_message_thread.cpp (source / functions) Hit Total Coverage
Commit: Piac-DEBUG Lines: 25 25 100.0 %
Date: 2022-12-16 13:46:15 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 68 54.4 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/cli_matrix_thread.cpp
       4                 :            :   \copyright 2022-2025 J. Bakosi,
       5                 :            :              All rights reserved. See the LICENSE file for details.
       6                 :            :   \brief     Piac message thread receiving messages from matrix client
       7                 :            : */
       8                 :            : // *****************************************************************************
       9                 :            : 
      10                 :            : #include "logging_util.hpp"
      11                 :            : 
      12                 :            : #include "cli_message_thread.hpp"
      13                 :            : #include "cli_matrix_thread.hpp"
      14                 :            : 
      15                 :            : static void
      16                 :         16 : msg_handle_mtx( zmqpp::message& msg, bool& to_shutdown )
      17                 :            : // *****************************************************************************
      18                 :            : //  Handle message from matrix client thread
      19                 :            : //! \param[in,out] msg Incoming message to handle
      20                 :            : //! \param[in,out] to_shutdown Set to true here if to shut down
      21                 :            : // *****************************************************************************
      22                 :            : {
      23                 :         32 :   std::string s;
      24         [ +  - ]:         16 :   msg >> s;
      25                 :            : 
      26         [ +  + ]:         16 :   if (s == "SHUTDOWN") {
      27                 :          3 :     to_shutdown = true;
      28         [ +  - ]:         13 :   } else if (s == "parsed_messages") {
      29 [ +  - ][ +  - ]:         13 :     MINFO( "recv parsed_messages" );
         [ +  - ][ +  - ]
      30                 :            :   }
      31                 :         16 : }
      32                 :            : 
      33                 :            : void
      34                 :          3 : piac::message_thread()
      35                 :            : // *****************************************************************************
      36                 :            : //! Entry point to thread to receive matrix messages
      37                 :            : // *****************************************************************************
      38                 :            : {
      39 [ +  - ][ +  - ]:          3 :   MLOG_SET_THREAD_NAME( "msg" );
      40 [ +  - ][ +  - ]:          3 :   MINFO( "msg thread initialized" );
         [ +  - ][ +  - ]
      41                 :            : 
      42                 :            :   // create socket that will receive messages from the matrix client thread
      43         [ +  - ]:          6 :   zmqpp::socket msg_mtx( g_ctx_msg, zmqpp::socket_type::pair );
      44 [ +  - ][ +  - ]:          3 :   msg_mtx.bind( "inproc://msg_mtx" );
      45 [ +  - ][ +  - ]:          3 :   MDEBUG( "Bound to inproc:://msg_mtx" );
         [ +  - ][ +  - ]
      46                 :            : 
      47                 :            :   // listen to messages
      48         [ +  - ]:          6 :   zmqpp::poller poller;
      49         [ +  - ]:          3 :   poller.add( msg_mtx );
      50                 :          3 :   bool to_shutdown = false;
      51         [ +  + ]:        105 :   while (not to_shutdown) {
      52 [ +  - ][ +  + ]:        102 :     if (poller.poll(100)) {
      53 [ +  - ][ +  - ]:         16 :       if (poller.has_input( msg_mtx )) {
      54         [ +  - ]:         32 :         zmqpp::message msg;
      55         [ +  - ]:         16 :         msg_mtx.receive( msg );
      56         [ +  - ]:         16 :         msg_handle_mtx( msg, to_shutdown );
      57                 :            :       }
      58                 :            :     }
      59                 :            :   }
      60                 :            : 
      61 [ +  - ][ +  - ]:          3 :   MINFO( "msg thread quit" );
         [ +  - ][ +  - ]
      62                 :          3 : }

Generated by: LCOV version 1.14