Annotation of qemu/qapi/qmp-registry.c, revision 1.1.1.3

1.1       root        1: /*
                      2:  * Core Definitions for QAPI/QMP Dispatch
                      3:  *
                      4:  * Copyright IBM, Corp. 2011
                      5:  *
                      6:  * Authors:
                      7:  *  Anthony Liguori   <[email protected]>
                      8:  *  Michael Roth      <[email protected]>
                      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: 
                     15: #include "qapi/qmp-core.h"
                     16: 
1.1.1.3 ! root       17: static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
1.1       root       18:     QTAILQ_HEAD_INITIALIZER(qmp_commands);
                     19: 
1.1.1.3 ! root       20: void qmp_register_command(const char *name, QmpCommandFunc *fn,
        !            21:                           QmpCommandOptions options)
1.1       root       22: {
1.1.1.2   root       23:     QmpCommand *cmd = g_malloc0(sizeof(*cmd));
1.1       root       24: 
                     25:     cmd->name = name;
                     26:     cmd->type = QCT_NORMAL;
                     27:     cmd->fn = fn;
1.1.1.3 ! root       28:     cmd->enabled = true;
        !            29:     cmd->options = options;
1.1       root       30:     QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
                     31: }
                     32: 
                     33: QmpCommand *qmp_find_command(const char *name)
                     34: {
1.1.1.3 ! root       35:     QmpCommand *cmd;
1.1       root       36: 
1.1.1.3 ! root       37:     QTAILQ_FOREACH(cmd, &qmp_commands, node) {
        !            38:         if (strcmp(cmd->name, name) == 0) {
        !            39:             return cmd;
1.1       root       40:         }
                     41:     }
                     42:     return NULL;
                     43: }
1.1.1.3 ! root       44: 
        !            45: static void qmp_toggle_command(const char *name, bool enabled)
        !            46: {
        !            47:     QmpCommand *cmd;
        !            48: 
        !            49:     QTAILQ_FOREACH(cmd, &qmp_commands, node) {
        !            50:         if (strcmp(cmd->name, name) == 0) {
        !            51:             cmd->enabled = enabled;
        !            52:             return;
        !            53:         }
        !            54:     }
        !            55: }
        !            56: 
        !            57: void qmp_disable_command(const char *name)
        !            58: {
        !            59:     qmp_toggle_command(name, false);
        !            60: }
        !            61: 
        !            62: void qmp_enable_command(const char *name)
        !            63: {
        !            64:     qmp_toggle_command(name, true);
        !            65: }
        !            66: 
        !            67: bool qmp_command_is_enabled(const char *name)
        !            68: {
        !            69:     QmpCommand *cmd;
        !            70: 
        !            71:     QTAILQ_FOREACH(cmd, &qmp_commands, node) {
        !            72:         if (strcmp(cmd->name, name) == 0) {
        !            73:             return cmd->enabled;
        !            74:         }
        !            75:     }
        !            76: 
        !            77:     return false;
        !            78: }
        !            79: 
        !            80: char **qmp_get_command_list(void)
        !            81: {
        !            82:     QmpCommand *cmd;
        !            83:     int count = 1;
        !            84:     char **list_head, **list;
        !            85: 
        !            86:     QTAILQ_FOREACH(cmd, &qmp_commands, node) {
        !            87:         count++;
        !            88:     }
        !            89: 
        !            90:     list_head = list = g_malloc0(count * sizeof(char *));
        !            91: 
        !            92:     QTAILQ_FOREACH(cmd, &qmp_commands, node) {
        !            93:         *list = strdup(cmd->name);
        !            94:         list++;
        !            95:     }
        !            96: 
        !            97:     return list_head;
        !            98: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.