source: BAORadio/libindi/libindi/BAOcontrol/Connection.hpp @ 689

Last change on this file since 689 was 689, checked in by frichard, 12 years ago
File size: 2.7 KB
Line 
1/*
2The stellarium telescope library helps building
3telescope server programs, that can communicate with stellarium
4by means of the stellarium TCP telescope protocol.
5It also contains smaple server classes (dummy, Meade LX200).
6
7Author and Copyright of this file and of the stellarium telescope library:
8Johannes Gajdosik, 2006
9
10This library is free software; you can redistribute it and/or
11modify it under the terms of the GNU Lesser General Public
12License as published by the Free Software Foundation; either
13version 2.1 of the License, or (at your option) any later version.
14
15This library is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public
21License along with this library; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23*/
24
25#ifndef _CONNECTION_HPP_
26#define _CONNECTION_HPP_
27
28#include "Socket2.hpp"
29
30//! TCP/IP connection to a client.
31class Connection : public Socket2
32{
33public:
34        Connection(Server2 &server, SOCKET fd);
35        long long int getServerMinusClientTime(void) const
36        {
37                return server_minus_client_time;
38        }
39       
40protected:
41        //! Receives data from a TCP/IP connection and stores it in the read buffer.
42        void performReading(void);
43        //! Sends the contents of the write buffer over a TCP/IP connection.
44        void performWriting(void);
45        void prepareSelectFds(fd_set &read_fds, fd_set &write_fds, int &fd_max);
46       
47private:
48        //! Returns true, as by default Connection implements a TCP/IP connection.
49        virtual bool isTcpConnection(void) const {return true;}
50        //! Returns false, as by default Connection implements a TCP/IP connection.
51        virtual bool isAsciiConnection(void) const {return false;}
52        void handleSelectFds(const fd_set &read_fds, const fd_set &write_fds);
53        //! Parses the read buffer and handles any messages contained within it.
54        //! If the data contains a Stellarium telescope control command,
55        //! dataReceived() calls the appropriate method of Server.
56        //! For example, "MessageGoto" (type 0) causes a call to Server::gotoReceived().
57        virtual void dataReceived(const char *&p, const char *read_buff_end);
58        //! Composes a "MessageCurrentPosition" in the write buffer.
59        //! This is a Stellarium telescope control protocol message containing
60        //! the current right ascension, declination and status of the telescope mount.
61        void sendPosition(unsigned int ra_int, int dec_int, int status);
62       
63protected:
64        char read_buff[120];
65        char *read_buff_end;
66        char write_buff[120];
67        char *write_buff_end;
68       
69private:
70        long long int server_minus_client_time;
71};
72
73#endif //_CONNECTION_HPP_
Note: See TracBrowser for help on using the repository browser.