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 _SERVER_HPP_ |
---|
26 | #define _SERVER_HPP_ |
---|
27 | |
---|
28 | #include <list> |
---|
29 | using namespace std; |
---|
30 | |
---|
31 | class Socket2; |
---|
32 | |
---|
33 | //! Base class for telescope server classes. A true telescope server class |
---|
34 | //! should inherit Server and implement device-specific functions. |
---|
35 | //! The class makes heavy use of polymorphism to perform all its work |
---|
36 | //! by maintaining a list of connections in the form of Socket pointers. |
---|
37 | //! The list actually contains objects of classes that inherit Socket, including |
---|
38 | //! one Listener object, created in the constructor, and one or more |
---|
39 | //! Connection objects, each representing a TCP/IP connection to a client. |
---|
40 | //! Classes that inherit Server (such as ServerLx200) also have a special |
---|
41 | //! device-specific connection object (such as Lx200Connection) that represents |
---|
42 | //! a serial connection to the device. The step() method calls |
---|
43 | //! Socket::prepareSelectFds() and Socket::handleSelectFds() for each connection |
---|
44 | //! in the list. These methods are reimplemented for each class. |
---|
45 | class Server2 |
---|
46 | { |
---|
47 | public: |
---|
48 | Server2(void) {} |
---|
49 | Server2(int port); |
---|
50 | virtual ~Server2(void) {} |
---|
51 | virtual void step(long long int timeout_micros); |
---|
52 | |
---|
53 | protected: |
---|
54 | void sendPosition(unsigned int ra_int, int dec_int, int status); |
---|
55 | //! Adds this object to the list of connections maintained by this server. |
---|
56 | //! This method is called by Listener. |
---|
57 | //! @param s can be anything that inherits Socket, including Listener, |
---|
58 | //! Connection or any custom class that implements a serial port |
---|
59 | //! connection (such as Lx200Connection and NexStarConnection). |
---|
60 | void addConnection(Socket2 *s) |
---|
61 | { |
---|
62 | if (s) |
---|
63 | socket_list.push_back(s); |
---|
64 | } |
---|
65 | void closeAcceptedConnections(void); |
---|
66 | friend class Listener; |
---|
67 | |
---|
68 | private: |
---|
69 | // called by Connection: |
---|
70 | virtual void gotoReceived(unsigned int ra_int, int dec_int) = 0; |
---|
71 | friend class Connection; |
---|
72 | |
---|
73 | class SocketList : public list<Socket2*> |
---|
74 | { |
---|
75 | public: |
---|
76 | ~SocketList(void) { clear(); } |
---|
77 | void clear(void); |
---|
78 | }; |
---|
79 | //! A list of the connections maintained by the server. |
---|
80 | SocketList socket_list; |
---|
81 | }; |
---|
82 | |
---|
83 | #endif |
---|