1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * Copyright (C) 2008 by Spencer Oliver *
9 * spen@spen-soft.co.uk *
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. *
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. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
23 ***************************************************************************/
25 #ifndef OPENOCD_SERVER_SERVER_H
26 #define OPENOCD_SERVER_SERVER_H
32 #include <helper/log.h>
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
38 enum connection_type
{
44 #define CONNECTION_LIMIT_UNLIMITED (-1)
48 int fd_out
; /* When using pipes we're writing to a different fd */
49 struct sockaddr_in sin
;
50 struct command_context
*cmd_ctx
;
51 struct service
*service
;
54 struct connection
*next
;
57 typedef int (*new_connection_handler_t
)(struct connection
*connection
);
58 typedef int (*input_handler_t
)(struct connection
*connection
);
59 typedef int (*connection_closed_handler_t
)(struct connection
*connection
);
63 enum connection_type type
;
65 unsigned short portnumber
;
67 struct sockaddr_in sin
;
69 struct connection
*connections
;
70 new_connection_handler_t new_connection
;
71 input_handler_t input
;
72 connection_closed_handler_t connection_closed
;
77 int add_service(char *name
, const char *port
,
78 int max_connections
, new_connection_handler_t new_connection_handler
,
79 input_handler_t in_handler
, connection_closed_handler_t close_handler
,
81 int remove_service(const char *name
, const char *port
);
83 int server_preinit(void);
84 int server_init(struct command_context
*cmd_ctx
);
85 int server_quit(void);
86 void server_free(void);
87 void exit_on_signal(int);
89 int server_loop(struct command_context
*command_context
);
91 int server_register_commands(struct command_context
*context
);
93 int connection_write(struct connection
*connection
, const void *data
, int len
);
94 int connection_read(struct connection
*connection
, void *data
, int len
);
97 * Used by server_loop(), defined in server_stubs.c
99 void openocd_sleep_prelude(void);
101 * Used by server_loop(), defined in server_stubs.c
103 void openocd_sleep_postlude(void);
106 * Defines an extended command handler function declaration to enable
107 * access to (and manipulation of) the server port number.
108 * Call server_port like a normal COMMAND_HANDLER with an extra @a out parameter
109 * to receive the specified port number.
111 COMMAND_HELPER(server_pipe_command
, char **out
);
113 COMMAND_HELPER(server_port_command
, unsigned short *out
);
115 #define ERROR_SERVER_REMOTE_CLOSED (-400)
116 #define ERROR_CONNECTION_REJECTED (-401)
118 #endif /* OPENOCD_SERVER_SERVER_H */