- prepare OpenOCD for branching, created ./trunk/
[fw/openocd] / src / server / server.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef SERVER_H
21 #define SERVER_H
22
23 #include "command.h"
24 #include "binarybuffer.h"
25
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29
30 enum connection_type
31 {
32         CONNECTION_GDB,
33         CONNECTION_TELNET,
34 };
35
36 typedef struct connection_s
37 {
38         int fd;
39         struct sockaddr_in sin;
40         command_context_t *cmd_ctx;
41         struct service_s *service;
42         int input_pending;
43         void *priv;
44         struct connection_s *next;
45 } connection_t;
46
47 typedef int (*new_connection_handler_t)(connection_t *connection);
48 typedef int (*input_handler_t)(connection_t *connection);
49 typedef int (*connection_closed_handler_t)(connection_t *connection);
50
51 typedef struct service_s
52 {
53         char *name;
54         enum connection_type type;
55         unsigned short port;
56         int fd;
57         struct sockaddr_in sin;
58         int max_connections;
59         connection_t *connections;
60         new_connection_handler_t new_connection;
61         input_handler_t input;
62         connection_closed_handler_t connection_closed;
63         void *priv;
64         struct service_s *next;
65 } service_t;
66
67 extern int add_service(char *name, enum connection_type type, unsigned short port, int max_connections, new_connection_handler_t new_connection_handler, input_handler_t input_handler, connection_closed_handler_t connection_closed_handler, void *priv);
68 extern int server_init();
69 extern int server_loop(command_context_t *command_context);
70 extern int server_register_commands(command_context_t *context);
71
72 #define ERROR_SERVER_REMOTE_CLOSED      (-400)
73 #define ERROR_CONNECTION_REJECTED       (-401)
74
75 #endif /* SERVER_H */