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).
7
Author and Copyright of this file and of the stellarium telescope library:
8
Johannes Gajdosik, 2006
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.
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.
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
27
//#include "Listener.hpp"
28
#include "LogFile.hpp"
30
void Server::SocketList::clear(void)
32
for (const_iterator it(begin()); it != end(); it++)
36
list<Socket*>::clear();
39
Server::Server(int port)
41
//Socket *listener = new Listener(*this, port);
42
//socket_list.push_back(listener);
45
void Server::sendPosition(unsigned int ra_int, int dec_int, int status)
47
for (SocketList::const_iterator it(socket_list.begin());
48
it != socket_list.end();
51
(*it)->sendPosition(ra_int, dec_int, status);
55
void Server::step(long long int timeout_micros)
57
fd_set read_fds, write_fds;
62
for (SocketList::const_iterator it(socket_list.begin());
63
it != socket_list.end();
66
(*it)->prepareSelectFds(read_fds, write_fds, fd_max);
70
if (timeout_micros < 0)
72
tv.tv_sec = timeout_micros / 1000000;
73
tv.tv_usec = timeout_micros % 1000000;
74
const int select_rc = select(fd_max+1, &read_fds, &write_fds, 0, &tv);
77
SocketList::iterator it(socket_list.begin());
78
while (it != socket_list.end())
80
(*it)->handleSelectFds(read_fds, write_fds);
81
if ((*it)->isClosed())
83
SocketList::iterator tmp(it);
86
socket_list.erase(tmp);
96
void Server::closeAcceptedConnections(void)
98
for (SocketList::iterator it(socket_list.begin());
99
it != socket_list.end();
102
if ((*it)->isTcpConnection())