X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fovsdb-types.h;h=efd83a7916971b5aa5282d727b50b49536367fbb;hb=HEAD;hp=0eca931f2c3f3a640fea82b632111c2367f239a8;hpb=02dd3123a0e312f1d33403e744af52dd6096f12d;p=sliver-openvswitch.git diff --git a/lib/ovsdb-types.h b/lib/ovsdb-types.h index 0eca931f2..efd83a791 100644 --- a/lib/ovsdb-types.h +++ b/lib/ovsdb-types.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira Networks +/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,6 @@ #include "compiler.h" #include "uuid.h" -#ifdef HAVE_PCRE -#include -#endif - struct json; /* An atomic type: one that OVSDB regards as a single unit of data. */ @@ -48,8 +44,18 @@ struct json *ovsdb_atomic_type_to_json(enum ovsdb_atomic_type); /* An atomic type plus optional constraints. */ +enum ovsdb_ref_type { + OVSDB_REF_STRONG, /* Target must exist. */ + OVSDB_REF_WEAK /* Delete reference if target disappears. */ +}; + struct ovsdb_base_type { enum ovsdb_atomic_type type; + + /* If nonnull, a datum with keys of type 'type' that expresses all the + * valid values for this base_type. */ + struct ovsdb_datum *enum_; + union { struct ovsdb_integer_constraints { int64_t min; /* minInteger or INT64_MIN. */ @@ -64,11 +70,6 @@ struct ovsdb_base_type { /* No constraints for Boolean types. */ struct ovsdb_string_constraints { -#ifdef HAVE_PCRE - pcre *re; /* Compiled regular expression. */ -#endif - char *reMatch; /* reMatch or NULL. */ - char *reComment; /* reComment or NULL. */ unsigned int minLen; /* minLength or 0. */ unsigned int maxLen; /* maxLength or UINT_MAX. */ } string; @@ -76,6 +77,7 @@ struct ovsdb_base_type { struct ovsdb_uuid_constraints { char *refTableName; /* Name of referenced table, or NULL. */ struct ovsdb_table *refTable; /* Referenced table, if available. */ + enum ovsdb_ref_type refType; /* Reference type. */ } uuid; } u; }; @@ -86,17 +88,10 @@ struct ovsdb_base_type { #define OVSDB_BASE_REAL_INIT { .type = OVSDB_TYPE_REAL, \ .u.real = { -DBL_MAX, DBL_MAX } } #define OVSDB_BASE_BOOLEAN_INIT { .type = OVSDB_TYPE_BOOLEAN } -#ifdef HAVE_PCRE -#define OVSDB_BASE_STRING_INIT { .type = OVSDB_TYPE_STRING, \ - .u.string = { NULL, NULL, NULL, \ - 0, UINT_MAX } } -#else #define OVSDB_BASE_STRING_INIT { .type = OVSDB_TYPE_STRING, \ - .u.string = { NULL, NULL, \ - 0, UINT_MAX } } -#endif + .u.string = { 0, UINT_MAX } } #define OVSDB_BASE_UUID_INIT { .type = OVSDB_TYPE_UUID, \ - .u.uuid = { NULL, NULL } } + .u.uuid = { NULL, NULL, 0 } } void ovsdb_base_type_init(struct ovsdb_base_type *, enum ovsdb_atomic_type); void ovsdb_base_type_clone(struct ovsdb_base_type *, @@ -106,15 +101,17 @@ void ovsdb_base_type_destroy(struct ovsdb_base_type *); bool ovsdb_base_type_is_valid(const struct ovsdb_base_type *); bool ovsdb_base_type_has_constraints(const struct ovsdb_base_type *); void ovsdb_base_type_clear_constraints(struct ovsdb_base_type *); -struct ovsdb_error *ovsdb_base_type_set_regex(struct ovsdb_base_type *, - const char *reMatch, - const char *reComment) - WARN_UNUSED_RESULT; +const struct ovsdb_type *ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type); struct ovsdb_error *ovsdb_base_type_from_json(struct ovsdb_base_type *, const struct json *) WARN_UNUSED_RESULT; struct json *ovsdb_base_type_to_json(const struct ovsdb_base_type *); + +static inline bool ovsdb_base_type_is_ref(const struct ovsdb_base_type *); +static inline bool ovsdb_base_type_is_strong_ref( + const struct ovsdb_base_type *); +static inline bool ovsdb_base_type_is_weak_ref(const struct ovsdb_base_type *); /* An OVSDB type. * @@ -171,7 +168,27 @@ struct json *ovsdb_type_to_json(const struct ovsdb_type *); static inline bool ovsdb_atomic_type_is_valid(enum ovsdb_atomic_type atomic_type) { - return atomic_type >= 0 && atomic_type < OVSDB_N_TYPES; + return (int) atomic_type >= 0 && atomic_type < OVSDB_N_TYPES; +} + +static inline bool +ovsdb_base_type_is_ref(const struct ovsdb_base_type *base) +{ + return base->type == OVSDB_TYPE_UUID && base->u.uuid.refTableName; +} + +static inline bool +ovsdb_base_type_is_strong_ref(const struct ovsdb_base_type *base) +{ + return (ovsdb_base_type_is_ref(base) + && base->u.uuid.refType == OVSDB_REF_STRONG); +} + +static inline bool +ovsdb_base_type_is_weak_ref(const struct ovsdb_base_type *base) +{ + return (ovsdb_base_type_is_ref(base) + && base->u.uuid.refType == OVSDB_REF_WEAK); } static inline bool ovsdb_type_is_scalar(const struct ovsdb_type *type)