waran/DaemonLink.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of waran.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2011-11-23
00021 **  Authors:
00022 **    Marc Wathelet (ISTerre, Grenoble, France)
00023 **
00024 ***************************************************************************/
00025 
00026 #ifndef DAEMONLINK_H
00027 #define DAEMONLINK_H
00028 
00029 #include <QtNetwork>
00030 
00031 #include <QGpCoreTools.h>
00032 
00033 class Station;
00034 
00035 class DaemonLink: public QObject
00036 {
00037   Q_OBJECT
00038 public:
00039   DaemonLink(Station * station);
00040   ~DaemonLink();
00041 
00042   unsigned int port() const {return _port;}
00043   void setPort(unsigned int p) {_port=p;}
00044 
00045   bool isAvailable();
00046 
00047   void send(const char * msg);
00048   void send(const char * buf, unsigned int len);
00049 protected:
00050   Station * station() {return _station;}
00051   const Station * station() const {return _station;}
00052 
00053   virtual int bytesAvailable(const char * buffer, int bytesCount)=0;
00054   bool match(const char * buffer, int& bytesRead, int bytesCount, const char * string);
00055   int findMatch(const char * buffer, int& bytesRead, int bytesCount, const char * string);
00056   QByteArray readString(const char * buffer, int& bytesRead, int bytesCount, bool& ok);
00057   int readInteger(const char * buffer, int& bytesRead, int bytesCount, bool& ok);
00058   long int readLongInteger(const char * buffer, int& bytesRead, int bytesCount, bool& ok);
00059   double readDouble(const char * buffer, int& bytesRead, int bytesCount, bool& ok);
00060 protected slots:
00061   virtual void connected();
00062 private slots:
00063   void bytesAvailable();
00064   void hungUp();
00065   void connect();
00066 signals:
00067   void stateChanged();
00068 private:
00069   Station * _station;
00070   unsigned int _port;
00071 
00072   QTcpSocket _socket;
00073   QGpCoreTools::DynamicBuffer _buffer;
00074   QTimer _connectionTimer;
00075 };
00076 
00077 #endif // DAEMONLINK_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines