| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Core Definitions for QAPI/QMP Dispatch | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright IBM, Corp. 2011 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: | 
					
						
							|  |  |  |  *  Anthony Liguori   <aliguori@us.ibm.com> | 
					
						
							|  |  |  |  *  Michael Roth      <mdroth@us.ibm.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. | 
					
						
							|  |  |  |  * See the COPYING.LIB file in the top-level directory. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:49:57 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:19:43 +01:00
										 |  |  | #include "qapi/qmp/dispatch.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  | void qmp_register_command(QmpCommandList *cmds, const char *name, | 
					
						
							| 
									
										
										
										
											2021-10-28 12:25:17 +02:00
										 |  |  |                           QmpCommandFunc *fn, QmpCommandOptions options, | 
					
						
							|  |  |  |                           unsigned special_features) | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-20 22:09:37 -05:00
										 |  |  |     QmpCommand *cmd = g_malloc0(sizeof(*cmd)); | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-05 17:58:50 +02:00
										 |  |  |     /* QCO_COROUTINE and QCO_ALLOW_OOB are incompatible for now */ | 
					
						
							|  |  |  |     assert(!((options & QCO_COROUTINE) && (options & QCO_ALLOW_OOB))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  |     cmd->name = name; | 
					
						
							|  |  |  |     cmd->fn = fn; | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |     cmd->enabled = true; | 
					
						
							| 
									
										
										
										
											2012-05-08 14:24:44 -03:00
										 |  |  |     cmd->options = options; | 
					
						
							| 
									
										
										
										
											2021-10-28 12:25:17 +02:00
										 |  |  |     cmd->special_features = special_features; | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  |     QTAILQ_INSERT_TAIL(cmds, cmd, node); | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 18:18:24 +01:00
										 |  |  | const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name) | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |     QmpCommand *cmd; | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  |     QTAILQ_FOREACH(cmd, cmds, node) { | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |         if (strcmp(cmd->name, name) == 0) { | 
					
						
							|  |  |  |             return cmd; | 
					
						
							| 
									
										
										
										
											2011-07-19 14:50:36 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  | static void qmp_toggle_command(QmpCommandList *cmds, const char *name, | 
					
						
							| 
									
										
										
										
											2021-02-19 12:28:14 +04:00
										 |  |  |                                bool enabled, const char *disable_reason) | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  | { | 
					
						
							|  |  |  |     QmpCommand *cmd; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  |     QTAILQ_FOREACH(cmd, cmds, node) { | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |         if (strcmp(cmd->name, name) == 0) { | 
					
						
							| 
									
										
										
										
											2012-04-17 19:01:45 -05:00
										 |  |  |             cmd->enabled = enabled; | 
					
						
							| 
									
										
										
										
											2021-02-19 12:28:14 +04:00
										 |  |  |             cmd->disable_reason = disable_reason; | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 12:28:14 +04:00
										 |  |  | void qmp_disable_command(QmpCommandList *cmds, const char *name, | 
					
						
							|  |  |  |                          const char *disable_reason) | 
					
						
							| 
									
										
										
										
											2012-04-17 19:01:45 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-19 12:28:14 +04:00
										 |  |  |     qmp_toggle_command(cmds, name, false, disable_reason); | 
					
						
							| 
									
										
										
										
											2012-04-17 19:01:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  | void qmp_enable_command(QmpCommandList *cmds, const char *name) | 
					
						
							| 
									
										
										
										
											2012-04-17 19:01:45 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-19 12:28:14 +04:00
										 |  |  |     qmp_toggle_command(cmds, name, true, NULL); | 
					
						
							| 
									
										
										
										
											2012-04-17 19:01:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 11:25:07 +08:00
										 |  |  | bool qmp_command_is_enabled(const QmpCommand *cmd) | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:43 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-09 11:25:07 +08:00
										 |  |  |     return cmd->enabled; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:43 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 11:25:07 +08:00
										 |  |  | const char *qmp_command_name(const QmpCommand *cmd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return cmd->name; | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:43 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 10:37:26 +08:00
										 |  |  | bool qmp_has_success_response(const QmpCommand *cmd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return !(cmd->options & QCO_NO_SUCCESS_RESP); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 18:18:24 +01:00
										 |  |  | void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn, | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  |                           void *opaque) | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-16 18:18:24 +01:00
										 |  |  |     const QmpCommand *cmd; | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 13:32:25 +01:00
										 |  |  |     QTAILQ_FOREACH(cmd, cmds, node) { | 
					
						
							| 
									
										
										
										
											2013-10-09 11:25:07 +08:00
										 |  |  |         fn(cmd, opaque); | 
					
						
							| 
									
										
										
										
											2011-12-06 22:03:42 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | } |