server: add server_preinit which is called before config file is parsed.
[openocd.git] / src / server / server.h
bloba25920ed0d6495f6a759b0ed7820aa52c618a5c8
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 * Copyright (C) 2008 by Spencer Oliver *
9 * spen@spen-soft.co.uk *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 ***************************************************************************/
26 #ifndef SERVER_H
27 #define SERVER_H
29 #include <helper/log.h>
31 #ifdef HAVE_NETINET_IN_H
32 #include <netinet/in.h>
33 #endif
35 enum connection_type
37 CONNECTION_TCP,
38 CONNECTION_PIPE
41 struct connection
43 int fd;
44 struct sockaddr_in sin;
45 struct command_context *cmd_ctx;
46 struct service *service;
47 int input_pending;
48 void *priv;
49 struct connection *next;
52 typedef int (*new_connection_handler_t)(struct connection *connection);
53 typedef int (*input_handler_t)(struct connection *connection);
54 typedef int (*connection_closed_handler_t)(struct connection *connection);
56 struct service
58 char *name;
59 enum connection_type type;
60 unsigned short port;
61 int fd;
62 struct sockaddr_in sin;
63 int max_connections;
64 struct connection *connections;
65 new_connection_handler_t new_connection;
66 input_handler_t input;
67 connection_closed_handler_t connection_closed;
68 void *priv;
69 struct service *next;
72 int add_service(char *name, enum connection_type type, unsigned short port,
73 int max_connections, new_connection_handler_t new_connection_handler,
74 input_handler_t in_handler, connection_closed_handler_t close_handler,
75 void *priv);
77 int server_preinit(void);
78 int server_init(struct command_context *cmd_ctx);
79 int server_quit(void);
81 int server_loop(struct command_context *command_context);
83 int server_register_commands(struct command_context *context);
85 /**
86 * Used by server_loop(), defined in server_stubs.c, httpd.c, or ecosboard.c
88 void openocd_sleep_prelude(void);
89 /**
90 * Used by server_loop(), defined in server_stubs.c, httpd.c, or ecosboard.c
92 void openocd_sleep_postlude(void);
94 /**
95 * Defines an extended command handler function declaration to enable
96 * access to (and manipulation of) the server port number.
97 * Call server_port like a normal COMMAND_HANDLER with an extra @a out parameter
98 * to receive the specified port number.
100 #define SERVER_PORT_COMMAND() \
101 COMMAND_HELPER(server_port_command, unsigned short *out)
103 SERVER_PORT_COMMAND();
105 extern int server_use_pipes;
107 #define ERROR_SERVER_REMOTE_CLOSED (-400)
108 #define ERROR_CONNECTION_REJECTED (-401)
110 #endif /* SERVER_H */