Ejemplo n.º 1
0
static struct json *
jsonrpc_create_id(void)
{
    static atomic_count next_id = ATOMIC_COUNT_INIT(0);
    unsigned int id;

    id = atomic_count_inc(&next_id);
    return json_integer_create(id);
}
Ejemplo n.º 2
0
static struct json *
jsonrpc_create_id(void)
{
    static atomic_uint next_id = ATOMIC_VAR_INIT(0);
    unsigned int id;

    atomic_add(&next_id, 1, &id);
    return json_integer_create(id);
}
struct json *
ovsdb_type_to_json(const struct ovsdb_type *type)
{
    if (ovsdb_type_is_scalar(type)
        && !ovsdb_base_type_has_constraints(&type->key)) {
        return ovsdb_base_type_to_json(&type->key);
    } else {
        struct json *json = json_object_create();
        json_object_put(json, "key", ovsdb_base_type_to_json(&type->key));
        if (type->value.type != OVSDB_TYPE_VOID) {
            json_object_put(json, "value",
                            ovsdb_base_type_to_json(&type->value));
        }
        if (type->n_min != 1) {
            json_object_put(json, "min", json_integer_create(type->n_min));
        }
        if (type->n_max == UINT_MAX) {
            json_object_put_string(json, "max", "unlimited");
        } else if (type->n_max != 1) {
            json_object_put(json, "max", json_integer_create(type->n_max));
        }
        return json;
    }
}
struct json *
ovsdb_base_type_to_json(const struct ovsdb_base_type *base)
{
    struct json *json;

    if (!ovsdb_base_type_has_constraints(base)) {
        return json_string_create(ovsdb_atomic_type_to_string(base->type));
    }

    json = json_object_create();
    json_object_put_string(json, "type",
                           ovsdb_atomic_type_to_string(base->type));

    if (base->enum_) {
        const struct ovsdb_type *type;

        type = ovsdb_base_type_get_enum_type(base->type);
        json_object_put(json, "enum", ovsdb_datum_to_json(base->enum_, type));
    }

    switch (base->type) {
    case OVSDB_TYPE_VOID:
        NOT_REACHED();

    case OVSDB_TYPE_INTEGER:
        if (base->u.integer.min != INT64_MIN) {
            json_object_put(json, "minInteger",
                            json_integer_create(base->u.integer.min));
        }
        if (base->u.integer.max != INT64_MAX) {
            json_object_put(json, "maxInteger",
                            json_integer_create(base->u.integer.max));
        }
        break;

    case OVSDB_TYPE_REAL:
        if (base->u.real.min != -DBL_MAX) {
            json_object_put(json, "minReal",
                            json_real_create(base->u.real.min));
        }
        if (base->u.real.max != DBL_MAX) {
            json_object_put(json, "maxReal",
                            json_real_create(base->u.real.max));
        }
        break;

    case OVSDB_TYPE_BOOLEAN:
        break;

    case OVSDB_TYPE_STRING:
        if (base->u.string.minLen != 0) {
            json_object_put(json, "minLength",
                            json_integer_create(base->u.string.minLen));
        }
        if (base->u.string.maxLen != UINT_MAX) {
            json_object_put(json, "maxLength",
                            json_integer_create(base->u.string.maxLen));
        }
        break;

    case OVSDB_TYPE_UUID:
        if (base->u.uuid.refTableName) {
            json_object_put_string(json, "refTable",
                                   base->u.uuid.refTableName);
            if (base->u.uuid.refType == OVSDB_REF_WEAK) {
                json_object_put_string(json, "refType", "weak");
            }
        }
        break;

    case OVSDB_N_TYPES:
        NOT_REACHED();

    default:
        NOT_REACHED();
    }

    return json;
}
Ejemplo n.º 5
0
static struct json *
jsonrpc_create_id(void)
{
    static unsigned int id;
    return json_integer_create(id++);
}