LCOV - code coverage report
Current view: top level - src - UserInterface.cxx (source / functions) Hit Total Coverage
Test: all_coverage_lcov.info Lines: 7 28 25.0 %
Date: 2024-04-08 10:29:30 Functions: 2 3 66.7 %
Branches: 4 32 12.5 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  ******************************************************************************
       3                 :            :  * @file           : UserInterface.cxx
       4                 :            :  * @brief          : UserInterface's source file.
       5                 :            :  ******************************************************************************
       6                 :            :  * @attention
       7                 :            :  *
       8                 :            :  * BSD 3-Clause License
       9                 :            :  *
      10                 :            :  * Copyright (c) 2024, Sang Tan Truong.
      11                 :            :  * All rights reserved.
      12                 :            :  *
      13                 :            :  * Redistribution and use in source and binary forms, with or without
      14                 :            :  * modification, are permitted provided that the following conditions are met:
      15                 :            :  *
      16                 :            :  * 1. Redistributions of source code must retain the above copyright notice,
      17                 :            :  *    this list of conditions and the following disclaimer.
      18                 :            :  *
      19                 :            :  * 2. Redistributions in binary form must reproduce the above copyright notice,
      20                 :            :  *    this list of conditions and the following disclaimer in the documentation
      21                 :            :  *    and/or other materials provided with the distribution.
      22                 :            :  *
      23                 :            :  * 3. Neither the name of Sang Tan Truong nor the names of its contributors may
      24                 :            :  *    be used to endorse or promote products derived from this software without
      25                 :            :  *    specific prior written permission.
      26                 :            :  *
      27                 :            :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
      28                 :            :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      29                 :            :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      30                 :            :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
      31                 :            :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      32                 :            :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      33                 :            :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      34                 :            :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      35                 :            :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      36                 :            :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      37                 :            :  * POSSIBILITY OF SUCH DAMAGE.
      38                 :            :  *
      39                 :            :  ******************************************************************************
      40                 :            :  */
      41                 :            : /* Includes ------------------------------------------------------------------*/
      42                 :            : #include "UserInterface.h"
      43                 :            : 
      44                 :            : #include <iostream>
      45                 :            : 
      46                 :            : /* Definitions ---------------------------------------------------------------*/
      47                 :            : namespace Farm {
      48                 :            : 
      49                 :          1 : UserInterface::UserInterface(std::mutex *Mutex)
      50         [ +  + ]:          1 :     : pMutex(Mutex), mIsPoisonReceived(false) {
      51         [ +  + ]:          1 :     LOG_USER(LogLevel::INFO, "Initiated User Interface class");
      52                 :          1 : }
      53                 :            : 
      54                 :          1 : UserInterface::~UserInterface() {
      55                 :          1 :     LOG_USER(LogLevel::INFO, "De-initiated User Interface class");
      56                 :          1 : }
      57                 :            : 
      58                 :          0 : void UserInterface::start() {
      59                 :          0 :     LOG_USER(LogLevel::INFO, "Enter UserInterface::start()");
      60                 :          0 :     while (true) {
      61                 :          0 :         std::unique_lock<std::mutex> lock(*this->pMutex);
      62            [ # ]:          0 :         this->mCV.wait(lock, [this] { return this->mIss.peek() == EOF; });
      63      [ #  #  # ]:          0 :         const char *userInput = GET_LINE("Please type your commands: ");
      64         [ #  # ]:          0 :         if (userInput == nullptr) {
      65         [ #  # ]:          0 :             LOG_USER(LogLevel::ERROR, "Failed to get user input");
      66         [ #  # ]:          0 :             continue;
      67                 :            :         }
      68            [ # ]:          0 :         this->mIss.clear();
      69      [ #  #  # ]:          0 :         this->mIss.str(userInput);
      70            [ # ]:          0 :         std::stringstream ss{};
      71                 :            : 
      72         [ #  # ]:          0 :         ss << "User Input is: " << userInput;
      73      [ #  #  # ]:          0 :         LOG_USER(LogLevel::DEBUG, ss.str().c_str());
      74                 :            : 
      75                 :          0 :         this->mCV.notify_one();
      76         [ #  # ]:          0 :         if ((mIsPoisonReceived = ((*userInput) == EOT_CHAR))) {
      77         [ #  # ]:          0 :             LOG_USER(LogLevel::INFO, "Poison signal received");
      78                 :          0 :             break;
      79                 :            :         }
      80   [ #  #  #  # ]:          0 :     }
      81                 :          0 :     LOG_USER(LogLevel::INFO, "Exit UserInterface::start() thread");
      82                 :          0 : }
      83                 :            : } // namespace Farm

Generated by: LCOV version 1.16