qmp-registry.c 896 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Core Definitions for QAPI/QMP Dispatch
  3. *
  4. * Copyright IBM, Corp. 2011
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. * Michael Roth <mdroth@us.ibm.com>
  9. *
  10. * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
  11. * See the COPYING.LIB file in the top-level directory.
  12. *
  13. */
  14. #include "qapi/qmp-core.h"
  15. static QTAILQ_HEAD(, QmpCommand) qmp_commands =
  16. QTAILQ_HEAD_INITIALIZER(qmp_commands);
  17. void qmp_register_command(const char *name, QmpCommandFunc *fn)
  18. {
  19. QmpCommand *cmd = qemu_mallocz(sizeof(*cmd));
  20. cmd->name = name;
  21. cmd->type = QCT_NORMAL;
  22. cmd->fn = fn;
  23. QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
  24. }
  25. QmpCommand *qmp_find_command(const char *name)
  26. {
  27. QmpCommand *i;
  28. QTAILQ_FOREACH(i, &qmp_commands, node) {
  29. if (strcmp(i->name, name) == 0) {
  30. return i;
  31. }
  32. }
  33. return NULL;
  34. }