Beispiel #1
0
int
vr_message_response(unsigned int object_type, void *object, int ret)
{
    char *buf = NULL;
    unsigned int len = 0;
    struct vr_mproto *proto;
    struct vr_mtransport *trans;

    proto = message_h.vm_proto;
    trans = message_h.vm_trans;
    if (!proto || !trans)
        return 0;


    len = proto->mproto_buf_len(object_type, object);
    len += proto->mproto_buf_len(VR_RESPONSE_OBJECT_ID, NULL);

    buf = trans->mtrans_alloc(len);
    if (!buf)
        return -ENOMEM;

    ret = proto->mproto_encode_response(buf, len, object_type,
            object, ret);
    if (ret < 0)
        goto response_fail;

    return vr_message_queue_response(buf, ret);

response_fail:
    if (buf)
        trans->mtrans_free(buf);

    vr_send_response(ret);
    return ret;
}
Beispiel #2
0
void
vr_message_dump_exit(void *context, int ret)
{
    struct vr_mproto *proto;
    struct vr_mtransport *trans;
    struct vr_message_dumper *dumper = (struct vr_message_dumper *)context;

    proto = message_h.vm_proto;
    trans = message_h.vm_trans;
    if (!proto || !trans)
        return;

    if (dumper)
        ret = dumper->dump_num_dumped;

    vr_send_response(ret);

    if (dumper) {
        if (!dumper->dump_offset) {
            if (dumper->dump_buffer)
                trans->mtrans_free(dumper->dump_buffer);
        } else
            vr_message_queue_response(dumper->dump_buffer,
                    dumper->dump_offset);

        vr_free(dumper);
    }

    return;
}
Beispiel #3
0
int
vr_message_multi_response(struct vr_message_multi *objects)
{
    char *buf = NULL;
    int ret = 0;
    unsigned int i, buf_len = 0, len = 0;
    struct vr_mproto *proto = NULL;
    struct vr_mtransport *trans = NULL;

    if ((!objects) ||
            (objects->vr_mm_object_count >= VR_MESSAGE_MULTI_MAX_OBJECTS))
        goto response_fail;

    proto = message_h.vm_proto;
    trans = message_h.vm_trans;
    if (!proto || !trans)
        goto response_fail;


    for (i = 0; i < objects->vr_mm_object_count; i++) {
        buf_len += proto->mproto_buf_len(objects->vr_mm_object_type[i],
                objects->vr_mm_object[i]);
    }

    if (!buf_len)
        goto response_fail;

    buf = trans->mtrans_alloc(buf_len);
    if (!buf) {
        ret = -ENOMEM;
        goto response_fail;
    }

    for (i = 0; i < objects->vr_mm_object_count; i++) {
        ret = proto->mproto_encode(buf + len, buf_len - len, objects->vr_mm_object_type[i],
                            objects->vr_mm_object[i], VR_MESSAGE_TYPE_RESPONSE);
        if (ret < 0)
            goto response_fail;

        len += ret;
    }

    return vr_message_queue_response(buf, len, false);

response_fail:
    if (trans && buf)
        trans->mtrans_free(buf);
    vr_send_response(ret);

    return ret;

}