1 | /* |
---|
2 | The stellarium telescope library helps building |
---|
3 | telescope server programs, that can communicate with stellarium |
---|
4 | by means of the stellarium TCP telescope protocol. |
---|
5 | It also contains smaple server classes (dummy, Meade LX200). |
---|
6 | |
---|
7 | Author and Copyright of this file and of the stellarium telescope library: |
---|
8 | Johannes Gajdosik, 2006 |
---|
9 | |
---|
10 | This library is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU Lesser General Public |
---|
12 | License as published by the Free Software Foundation; either |
---|
13 | version 2.1 of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | This library is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | Lesser General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU Lesser General Public |
---|
21 | License along with this library; if not, write to the Free Software |
---|
22 | Foundation, 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. |
---|
31 | class Connection : public Socket2 |
---|
32 | { |
---|
33 | public: |
---|
34 | Connection(Server2 &server, SOCKET fd); |
---|
35 | long long int getServerMinusClientTime(void) const |
---|
36 | { |
---|
37 | return server_minus_client_time; |
---|
38 | } |
---|
39 | |
---|
40 | protected: |
---|
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 | |
---|
47 | private: |
---|
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 | |
---|
63 | protected: |
---|
64 | char read_buff[120]; |
---|
65 | char *read_buff_end; |
---|
66 | char write_buff[120]; |
---|
67 | char *write_buff_end; |
---|
68 | |
---|
69 | private: |
---|
70 | long long int server_minus_client_time; |
---|
71 | }; |
---|
72 | |
---|
73 | #endif //_CONNECTION_HPP_ |
---|