00001 // -*- C++ -*- 00002 // Definitions for the bidirectional connection to a TTY 00003 // 00004 // ***** BEGIN LICENSE BLOCK ***** 00005 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00006 // 00007 // The contents of this file are subject to the Mozilla Public License 00008 // Version 1.1 (the "License"); you may not use this file except in 00009 // compliance with the License. You may obtain a copy of the License at 00010 // http://www.mozilla.org/MPL/ 00011 // 00012 // Software distributed under the License is distributed on an "AS IS" 00013 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00014 // the License for the specific language governing rights and limitations 00015 // under the License. 00016 // 00017 // The Original Code is the consmgr network/serial-line monitoring package. 00018 // 00019 // The Initial Developer of the Original Code is Chris P. Ross. 00020 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00021 // the Initial Developer. All Rights Reserved. 00022 // 00023 // Contributor(s): 00024 // 00025 // Alternatively, the contents of this file may be used under the terms of 00026 // either the GNU General Public License Version 2 or later (the "GPL"), or 00027 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00028 // in which case the provisions of the GPL or the LGPL are applicable instead 00029 // of those above. If you wish to allow use of your version of this file only 00030 // under the terms of either the GPL or the LGPL, and not to allow others to 00031 // use your version of this file under the terms of the MPL, indicate your 00032 // decision by deleting the provisions above and replace them with the notice 00033 // and other provisions required by the GPL or the LGPL. If you do not delete 00034 // the provisions above, a recipient may use your version of this file under 00035 // the terms of any one of the MPL, the GPL or the LGPL. 00036 // 00037 // ***** END LICENSE BLOCK ***** 00038 00039 #ifndef __TTYCONN_H 00040 #define __TTYCONN_H 00041 00042 extern "C" { 00043 #include <sys/types.h> 00044 #include <termios.h> 00045 } 00046 00047 // Get the base class 00048 #include "connector.h" 00049 00056 class TTYConnector : public Connector { 00057 public: 00058 // Constructors: 00059 // std::string - a device name to open 00060 // int,int - read and write fd's 00061 TTYConnector(const std::string&); 00062 TTYConnector(const int,const int); // Used only by UserTTYConn at the moment 00063 virtual ~TTYConnector() throw(); 00064 00065 #if 0 00066 virtual void notify_on_disconnect(const Messageable *owner); 00067 #endif 00068 00069 // Read a blob of data from the underlying connection. 00070 virtual Data *read(); 00071 00073 virtual ssize_t write(const Data &b); 00074 00075 protected: 00076 // Check the input fd to see if it's a TTY, so we can configure it 00077 // to be RAW state. Call inherited methods to save fd values. 00078 void setup_fds(int, int); 00079 00080 // Open a tty device for reading and writing, calling set_fds() to 00081 // set that up. connect() can later be called on this object. 00082 void open_device(string); 00083 00084 public: 00085 // Generate an ID string to indicate what we're connected to... 00086 string get_id(void) const; 00087 00089 virtual bool connected(void) const; 00090 00091 private: 00093 void connect(void); 00095 void disconnect(void); 00096 00098 struct termios *saved_state; 00099 00100 protected: 00101 int read_fd; 00102 int write_fd; 00103 pthread_mutex_t mutex; 00104 }; 00105 00106 #endif /* __TTYCONN_H */