Revision 25b422eb monitor.c

b/monitor.c
267 267
    QDECREF(json);
268 268
}
269 269

  
270
static void monitor_protocol_emitter(Monitor *mon, QObject *data)
271
{
272
    QDict *qmp;
273

  
274
    qmp = qdict_new();
275

  
276
    if (!monitor_has_error(mon)) {
277
        /* success response */
278
        if (data) {
279
            qobject_incref(data);
280
            qdict_put_obj(qmp, "return", data);
281
        } else {
282
            qdict_put(qmp, "return", qstring_from_str("OK"));
283
        }
284
    } else {
285
        /* error response */
286
        qdict_put(qmp, "error", mon->error->error);
287
        QINCREF(mon->error->error);
288
        QDECREF(mon->error);
289
        mon->error = NULL;
290
    }
291

  
292
    monitor_json_emitter(mon, QOBJECT(qmp));
293
    QDECREF(qmp);
294
}
295

  
270 296
static int compare_cmd(const char *name, const char *list)
271 297
{
272 298
    const char *p, *pstart;
......
354 380

  
355 381
    if (monitor_handler_ported(cmd)) {
356 382
        cmd->mhandler.info_new(mon, ret_data);
357
        if (*ret_data)
358
            cmd->user_print(mon, *ret_data);
383

  
384
        if (!monitor_ctrl_mode(mon)) {
385
            /*
386
             * User Protocol function is called here, Monitor Protocol is
387
             * handled by monitor_call_handler()
388
             */
389
            if (*ret_data)
390
                cmd->user_print(mon, *ret_data);
391
        }
359 392
    } else {
360 393
        cmd->mhandler.info(mon);
361 394
    }
......
3250 3283
    QObject *data = NULL;
3251 3284

  
3252 3285
    cmd->mhandler.cmd_new(mon, params, &data);
3253
    if (data)
3254
        cmd->user_print(mon, data);
3286

  
3287
    if (monitor_ctrl_mode(mon)) {
3288
        /* Monitor Protocol */
3289
        monitor_protocol_emitter(mon, data);
3290
    } else {
3291
        /* User Protocol */
3292
         if (data)
3293
            cmd->user_print(mon, data);
3294
    }
3255 3295

  
3256 3296
    qobject_decref(data);
3257 3297
}

Also available in: Unified diff