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

Last change on this file since 689 was 689, checked in by frichard, 12 years ago
File size: 2.9 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 _SERVER_HPP_
26#define _SERVER_HPP_
27
28#include <list>
29using namespace std;
30
31class 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.
45class Server2
46{
47public:
48        Server2(void) {}
49        Server2(int port);
50        virtual ~Server2(void) {}
51        virtual void step(long long int timeout_micros);
52       
53protected:
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       
68private:
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
Note: See TracBrowser for help on using the repository browser.