mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / server-tools / instance-manager / commands.h
blob77c1ab71f81ea317279374c41447fd8ca86d4d0a
1 #ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_COMMANDS_H
2 #define INCLUDES_MYSQL_INSTANCE_MANAGER_COMMANDS_H
3 /* Copyright (c) 2004-2006 MySQL AB
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; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
18 #include <my_global.h>
19 #include <my_sys.h>
20 #include <m_string.h>
21 #include <hash.h>
23 #include "command.h"
24 #include "instance.h"
25 #include "parse.h"
27 #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
28 #pragma interface
29 #endif
32 /**
33 Print all instances of this instance manager.
34 Grammar: SHOW INSTANCES
37 class Show_instances: public Command
39 public:
40 Show_instances()
41 { }
43 public:
44 int execute(st_net *net, ulong connection_id);
46 private:
47 int write_header(st_net *net);
48 int write_data(st_net *net);
52 /**
53 Reread configuration file and refresh internal cache.
54 Grammar: FLUSH INSTANCES
57 class Flush_instances: public Command
59 public:
60 Flush_instances()
61 { }
63 public:
64 int execute(st_net *net, ulong connection_id);
68 /**
69 Base class for Instance-specific commands
70 (commands that operate on one instance).
72 Instance_cmd extends Command class by:
73 - an attribute for storing instance name;
74 - code to initialize instance name in constructor;
75 - an accessor to get instance name.
78 class Instance_cmd : public Command
80 public:
81 Instance_cmd(const LEX_STRING *instance_name_arg);
83 protected:
84 inline const LEX_STRING *get_instance_name() const
86 return instance_name.get_str();
89 private:
90 Instance_name instance_name;
94 /**
95 Abstract class for Instance-specific commands.
97 Abstract_instance_cmd extends Instance_cmd by providing a common
98 framework for writing command-implementations. Basically, the class
99 implements Command::execute() pure virtual function in the following
100 way:
101 - Lock Instance_map;
102 - Get an instance by name. Return an error, if there is no such
103 instance;
104 - Lock the instance;
105 - Unlock Instance_map;
106 - Call execute_impl(), which should be implemented in derived class;
107 - Unlock the instance;
108 - Send response to the client and return error status.
111 class Abstract_instance_cmd: public Instance_cmd
113 public:
114 Abstract_instance_cmd(const LEX_STRING *instance_name_arg);
116 public:
117 virtual int execute(st_net *net, ulong connection_id);
119 protected:
121 This operation is intended to contain command-specific implementation.
123 MT-NOTE: this operation is called under acquired Instance's lock.
125 virtual int execute_impl(st_net *net, Instance *instance) = 0;
128 This operation is invoked on successful return of execute_impl() and is
129 intended to send closing data.
131 MT-NOTE: this operation is called under released Instance's lock.
133 virtual int send_ok_response(st_net *net, ulong connection_id) = 0;
138 Print status of an instance.
139 Grammar: SHOW INSTANCE STATUS <instance_name>
142 class Show_instance_status: public Abstract_instance_cmd
144 public:
145 Show_instance_status(const LEX_STRING *instance_name_arg);
147 protected:
148 virtual int execute_impl(st_net *net, Instance *instance);
149 virtual int send_ok_response(st_net *net, ulong connection_id);
151 private:
152 int write_header(st_net *net);
153 int write_data(st_net *net, Instance *instance);
158 Print options of chosen instance.
159 Grammar: SHOW INSTANCE OPTIONS <instance_name>
162 class Show_instance_options: public Abstract_instance_cmd
164 public:
165 Show_instance_options(const LEX_STRING *instance_name_arg);
167 protected:
168 virtual int execute_impl(st_net *net, Instance *instance);
169 virtual int send_ok_response(st_net *net, ulong connection_id);
171 private:
172 int write_header(st_net *net);
173 int write_data(st_net *net, Instance *instance);
178 Start an instance.
179 Grammar: START INSTANCE <instance_name>
182 class Start_instance: public Abstract_instance_cmd
184 public:
185 Start_instance(const LEX_STRING *instance_name_arg);
187 protected:
188 virtual int execute_impl(st_net *net, Instance *instance);
189 virtual int send_ok_response(st_net *net, ulong connection_id);
194 Stop an instance.
195 Grammar: STOP INSTANCE <instance_name>
198 class Stop_instance: public Abstract_instance_cmd
200 public:
201 Stop_instance(const LEX_STRING *instance_name_arg);
203 protected:
204 virtual int execute_impl(st_net *net, Instance *instance);
205 virtual int send_ok_response(st_net *net, ulong connection_id);
210 Create an instance.
211 Grammar: CREATE INSTANCE <instance_name> [<options>]
214 class Create_instance: public Instance_cmd
216 public:
217 Create_instance(const LEX_STRING *instance_name_arg);
219 public:
220 bool init(const char **text);
222 protected:
223 virtual int execute(st_net *net, ulong connection_id);
225 private:
226 bool parse_args(const char **text);
228 private:
229 Named_value_arr options;
234 Drop an instance.
235 Grammar: DROP INSTANCE <instance_name>
237 Operation is permitted only if the instance is stopped. On successful
238 completion the instance section is removed from config file and the instance
239 is removed from the instance map.
242 class Drop_instance: public Instance_cmd
244 public:
245 Drop_instance(const LEX_STRING *instance_name_arg);
247 protected:
248 virtual int execute(st_net *net, ulong connection_id);
253 Print requested part of the log.
254 Grammar:
255 SHOW <instance_name> LOG {ERROR | SLOW | GENERAL} size[, offset_from_end]
258 class Show_instance_log: public Abstract_instance_cmd
260 public:
261 Show_instance_log(const LEX_STRING *instance_name_arg,
262 Log_type log_type_arg, uint size_arg, uint offset_arg);
264 protected:
265 virtual int execute_impl(st_net *net, Instance *instance);
266 virtual int send_ok_response(st_net *net, ulong connection_id);
268 private:
269 int check_params(Instance *instance);
270 int write_header(st_net *net);
271 int write_data(st_net *net, Instance *instance);
273 private:
274 Log_type log_type;
275 uint size;
276 uint offset;
281 Shows the list of the log files, used by an instance.
282 Grammar: SHOW <instance_name> LOG FILES
285 class Show_instance_log_files: public Abstract_instance_cmd
287 public:
288 Show_instance_log_files(const LEX_STRING *instance_name_arg);
290 protected:
291 virtual int execute_impl(st_net *net, Instance *instance);
292 virtual int send_ok_response(st_net *net, ulong connection_id);
294 private:
295 int write_header(st_net *net);
296 int write_data(st_net *net, Instance *instance);
301 Abstract class for option-management commands.
304 class Instance_options_list;
306 class Abstract_option_cmd: public Command
308 public:
309 ~Abstract_option_cmd();
311 public:
312 bool add_option(const LEX_STRING *instance_name, Named_value *option);
314 public:
315 bool init(const char **text);
317 virtual int execute(st_net *net, ulong connection_id);
319 protected:
320 Abstract_option_cmd();
322 int correct_file(Instance *instance, Named_value *option, bool skip);
324 protected:
325 virtual bool parse_args(const char **text) = 0;
326 virtual int process_option(Instance *instance, Named_value *option) = 0;
328 private:
329 Instance_options_list *
330 get_instance_options_list(const LEX_STRING *instance_name);
332 int execute_impl(st_net *net, ulong connection_id);
334 private:
335 HASH instance_options_map;
336 bool initialized;
341 Set an option for the instance.
342 Grammar: SET instance_name.option[=option_value][, ...]
345 class Set_option: public Abstract_option_cmd
347 public:
348 Set_option()
351 protected:
352 virtual bool parse_args(const char **text);
353 virtual int process_option(Instance *instance, Named_value *option);
358 Remove option of the instance.
359 Grammar: UNSET instance_name.option[, ...]
362 class Unset_option: public Abstract_option_cmd
364 public:
365 Unset_option()
368 protected:
369 virtual bool parse_args(const char **text);
370 virtual int process_option(Instance *instance, Named_value *option);
375 Syntax error command.
377 This command is issued if parser reported a syntax error. We need it to
378 distinguish between syntax error and internal parser error. E.g. parsing
379 failed because we hadn't had enought memory. In the latter case the parser
380 just returns NULL.
383 class Syntax_error: public Command
385 public:
386 Syntax_error()
389 public:
390 int execute(st_net *net, ulong connection_id);
393 #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_COMMANDS_H */