LCOV - code coverage report
Current view: top level - src/frontend - stmclient.h (source / functions) Hit Total Coverage
Test: mosh-1.3.2 Code Coverage Lines: 28 34 82.4 %
Date: 2022-02-06 20:19:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :     Mosh: the mobile shell
       3             :     Copyright 2012 Keith Winstein
       4             : 
       5             :     This program is free software: you can redistribute it and/or modify
       6             :     it under the terms of the GNU General Public License as published by
       7             :     the Free Software Foundation, either version 3 of the License, or
       8             :     (at your option) any later version.
       9             : 
      10             :     This program is distributed in the hope that it will be useful,
      11             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :     GNU General Public License for more details.
      14             : 
      15             :     You should have received a copy of the GNU General Public License
      16             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             : 
      18             :     In addition, as a special exception, the copyright holders give
      19             :     permission to link the code of portions of this program with the
      20             :     OpenSSL library under certain conditions as described in each
      21             :     individual source file, and distribute linked combinations including
      22             :     the two.
      23             : 
      24             :     You must obey the GNU General Public License in all respects for all
      25             :     of the code used other than OpenSSL. If you modify file(s) with this
      26             :     exception, you may extend this exception to your version of the
      27             :     file(s), but you are not obligated to do so. If you do not wish to do
      28             :     so, delete this exception statement from your version. If you delete
      29             :     this exception statement from all source files in the program, then
      30             :     also delete it here.
      31             : */
      32             : 
      33             : #ifndef STM_CLIENT_HPP
      34             : #define STM_CLIENT_HPP
      35             : 
      36             : #include <sys/ioctl.h>
      37             : #include <termios.h>
      38             : #include <string>
      39             : 
      40             : #include "completeterminal.h"
      41             : #include "networktransport.h"
      42             : #include "user.h"
      43             : #include "shared.h"
      44             : #include "terminaloverlay.h"
      45             : 
      46             : class STMClient {
      47             : private:
      48             :   std::string ip;
      49             :   std::string port;
      50             :   std::string key;
      51             : 
      52             :   int escape_key;
      53             :   int escape_pass_key;
      54             :   int escape_pass_key2;
      55             :   bool escape_requires_lf;
      56             :   std::wstring escape_key_help;
      57             : 
      58             :   struct termios saved_termios, raw_termios;
      59             : 
      60             :   struct winsize window_size;
      61             : 
      62             :   Terminal::Framebuffer local_framebuffer, new_state;
      63             :   Overlay::OverlayManager overlays;
      64             :   typedef Network::Transport< Network::UserStream, Terminal::Complete > NetworkType;
      65             :   typedef shared::shared_ptr< NetworkType > NetworkPointer;
      66             :   NetworkPointer network;
      67             :   Terminal::Display display;
      68             : 
      69             :   std::wstring connecting_notification;
      70             :   bool repaint_requested, lf_entered, quit_sequence_started;
      71             :   bool clean_shutdown;
      72             :   unsigned int verbose;
      73             : 
      74             :   void main_init( void );
      75             :   void process_network_input( void );
      76             :   bool process_user_input( int fd );
      77             :   bool process_resize( void );
      78             : 
      79             :   void output_new_frame( void );
      80             : 
      81       12176 :   bool still_connecting( void ) const
      82             :   {
      83             :     /* Initially, network == NULL */
      84       12176 :     return network && ( network->get_remote_state_num() == 0 );
      85             :   }
      86             : 
      87             :   void resume( void ); /* restore state after SIGCONT */
      88             : 
      89             : public:
      90         448 :   STMClient( const char *s_ip, const char *s_port, const char *s_key, const char *predict_mode, unsigned int s_verbose, const char *predict_overwrite )
      91         448 :     : ip( s_ip ? s_ip : "" ), port( s_port ? s_port : "" ),
      92         448 :     key( s_key ? s_key : "" ),
      93         448 :     escape_key( 0x1E ), escape_pass_key( '^' ), escape_pass_key2( '^' ),
      94         448 :     escape_requires_lf( false ), escape_key_help( L"?" ),
      95         448 :       saved_termios(), raw_termios(),
      96         448 :       window_size(),
      97         448 :       local_framebuffer( 1, 1 ),
      98         448 :       new_state( 1, 1 ),
      99         448 :       overlays(),
     100         448 :       network(),
     101         448 :       display( true ), /* use TERM environment var to initialize display */
     102         448 :       connecting_notification(),
     103         448 :       repaint_requested( false ),
     104         448 :       lf_entered( false ),
     105         448 :       quit_sequence_started( false ),
     106         448 :       clean_shutdown( false ),
     107         448 :       verbose( s_verbose )
     108             :   {
     109         448 :     if ( predict_mode ) {
     110         448 :       if ( !strcmp( predict_mode, "always" ) ) {
     111           2 :         overlays.get_prediction_engine().set_display_preference( Overlay::PredictionEngine::Always );
     112         446 :       } else if ( !strcmp( predict_mode, "never" ) ) {
     113           0 :         overlays.get_prediction_engine().set_display_preference( Overlay::PredictionEngine::Never );
     114         446 :       } else if ( !strcmp( predict_mode, "adaptive" ) ) {
     115         446 :         overlays.get_prediction_engine().set_display_preference( Overlay::PredictionEngine::Adaptive );
     116           0 :       } else if ( !strcmp( predict_mode, "experimental" ) ) {
     117           0 :         overlays.get_prediction_engine().set_display_preference( Overlay::PredictionEngine::Experimental );
     118             :       } else {
     119           0 :         fprintf( stderr, "Unknown prediction mode %s.\n", predict_mode );
     120           0 :         exit( 1 );
     121             :       }
     122             :     }
     123         448 :     if ( predict_overwrite && !strcmp( predict_overwrite, "yes" ) ) {
     124           0 :       overlays.get_prediction_engine().set_predict_overwrite( true );
     125             :     } 
     126         448 :   }
     127             : 
     128             :   void init( void );
     129             :   void shutdown( void );
     130             :   bool main( void );
     131             : 
     132             :   /* unused */
     133             :   STMClient( const STMClient & );
     134             :   STMClient & operator=( const STMClient & );
     135             : };
     136             : 
     137             : #endif

Generated by: LCOV version 1.14