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 USER_HPP 34 : #define USER_HPP 35 : 36 : #include <deque> 37 : #include <list> 38 : #include <string> 39 : #include <assert.h> 40 : 41 : #include "parseraction.h" 42 : 43 : namespace Network { 44 : using std::deque; 45 : using std::list; 46 : using std::string; 47 : 48 : enum UserEventType { 49 : UserByteType = 0, 50 : ResizeType = 1 51 : }; 52 : 53 19997 : class UserEvent 54 : { 55 : public: 56 : UserEventType type; 57 : Parser::UserByte userbyte; 58 : Parser::Resize resize; 59 : 60 3545 : UserEvent( const Parser::UserByte & s_userbyte ) : type( UserByteType ), userbyte( s_userbyte ), resize( -1, -1 ) {} 61 1484 : UserEvent( const Parser::Resize & s_resize ) : type( ResizeType ), userbyte( 0 ), resize( s_resize ) {} 62 : 63 : private: 64 : UserEvent(); 65 : 66 : public: 67 8773 : bool operator==( const UserEvent &x ) const { return ( type == x.type ) && ( userbyte == x.userbyte ) && ( resize == x.resize ); } 68 : }; 69 : 70 26766 : class UserStream 71 : { 72 : private: 73 : deque<UserEvent> actions; 74 : 75 : public: 76 2846 : UserStream() : actions() {} 77 : 78 1183 : void push_back( const Parser::UserByte & s_userbyte ) { actions.push_back( UserEvent( s_userbyte ) ); } 79 492 : void push_back( const Parser::Resize & s_resize ) { actions.push_back( UserEvent( s_resize ) ); } 80 : 81 1946 : bool empty( void ) const { return actions.empty(); } 82 4119 : size_t size( void ) const { return actions.size(); } 83 : const Parser::Action &get_action( unsigned int i ) const; 84 : 85 : /* interface for Network::Transport */ 86 : void subtract( const UserStream *prefix ); 87 : string diff_from( const UserStream &existing ) const; 88 0 : string init_diff( void ) const { return diff_from( UserStream() ); }; 89 : void apply_string( const string &diff ); 90 31242 : bool operator==( const UserStream &x ) const { return actions == x.actions; } 91 : 92 : bool compare( const UserStream & ) { return false; } 93 : }; 94 : } 95 : 96 : #endif