gui: Do not decode the pressed key multiple times.
[paraslash.git] / server.h
1 /* Copyright (C) 1997 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2
3 /** \file server.h Common server data structures. */
4
5 /** Size of the selector_info and audio_file info strings of struct misc_meta_data. */
6 #define MMD_INFO_SIZE 16384
7
8 /** Arguments for the sender command. */
9 struct sender_command_data {
10         /** Greater than zero indicates that a sender cmd is already queued. */
11         int cmd_num;
12         /** The number of the sender in question. */
13         int sender_num;
14         /** Used for the allow/deny/add/remove subcommands. */
15         char host[MAX_HOSTLEN];
16         /** Used for allow/deny. */
17         int netmask;
18         /** The port number for add/remove. */
19         int port;
20         /** Maximal slice size. */
21         uint16_t max_slice_bytes;
22         /** Number of data slices plus redundant slices. */
23         uint8_t slices_per_group;
24         /** Number of slices minus number of redundant slices. */
25         uint8_t data_slices_per_group;
26 };
27
28 /**
29  * Miscellaneous data for communication between server and command handlers.
30  *
31  * There's only one instance of this structure which lives in a shared memory
32  * area. Command handlers communicate with the server process through this
33  * area. Changes made by the command handlers stay after the command handler
34  * exits. Conversely, changes made by the server process propagate to the
35  * command handlers. Access to this area is serialized via mmd_lock() and
36  * mmd_unlock().
37  *
38  * There are two reasons for a variable to be included here: (a) at least one
39  * command handler changes its value, or (b) updates by the server must
40  * propagate to the stat command handlers.
41  */
42 struct misc_meta_data {
43         /** The "old" status flags -- commands may only read them. */
44         unsigned int vss_status_flags;
45         /** The new status flags -- commands may set them. */
46         unsigned int new_vss_status_flags;
47         /** The number of data chunks sent so far. */
48         long unsigned chunks_sent;
49         /** Set by the jmp/ff commands to the new position in chunks. */
50         long unsigned repos_request;
51         /** The number of the chunk currently being sent. */
52         long unsigned current_chunk;
53         /** The milliseconds that have been skipped of the current audio file. */
54         long offset;
55         /** The time para_server started to stream. */
56         struct timeval stream_start;
57         /**
58          * The event counter.
59          *
60          * Commands may increase this to force a status update to be sent to
61          * all connected stat clients.
62          */
63         unsigned int events;
64         /** The number of audio files already sent. */
65         unsigned int num_played;
66         /** The number of executed commands. */
67         unsigned int num_commands;
68         /** The number of connections para_server received so far. */
69         unsigned int num_connects;
70         /** The number of connections currently active. */
71         unsigned int active_connections;
72         /** This gets updated by afs and contains its current mode. */
73         char afs_mode_string[MAXLINE];
74         /** Used by the sender command. */
75         struct sender_command_data sender_cmd_data;
76         /** Describes the current audio file. */
77         struct audio_file_data afd;
78 };
79
80 extern pid_t afs_pid;
81 extern struct lls_parse_result *server_lpr;
82
83 /**
84  * Get a reference to the supercommand of para_server.
85  *
86  * This is needed for parsing the command line and for the ENUM_STRING_VAL()
87  * macro below. The latter macro is used in command.c, so CMD_PTR() can not
88  * be made local to server.c.
89  */
90 #define CMD_PTR (lls_cmd(0, server_suite))
91
92 /** Get the parse result of an option to para_server. */
93 #define OPT_RESULT(_name) (lls_opt_result( \
94                 LSG_SERVER_PARA_SERVER_OPT_ ## _name, server_lpr))
95
96 /** How many times a server option was given. */
97 #define OPT_GIVEN(_name) (lls_opt_given(OPT_RESULT(_name)))
98
99 /** The (first) argument to a server option of type string. */
100 #define OPT_STRING_VAL(_name) (lls_string_val(0, OPT_RESULT(_name)))
101
102 /** The (first) argument to a server option of type uint32. */
103 #define OPT_UINT32_VAL(_name) (lls_uint32_val(0, OPT_RESULT(_name)))
104
105 /** The (first) argument to a server option of type int32. */
106 #define OPT_INT32_VAL(_name) (lls_int32_val(0, OPT_RESULT(_name)))
107
108 /** Get the string which corresponds to an enum constant. */
109 #define ENUM_STRING_VAL(_name) (lls_enum_string_val(OPT_UINT32_VAL(_name), \
110         lls_opt(LSG_SERVER_PARA_SERVER_OPT_ ## _name, CMD_PTR)))
111
112 int handle_connect(int fd);
113 void parse_config_or_die(bool reload);
114 char *server_get_tasks(void);
115 bool process_is_command_handler(void);
116 void free_lpr(void);