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