Extensible Connection-oriented Messaging (XCM)
|
XCM attribute map API. More...
Go to the source code of this file.
Typedefs | |
typedef void(* | xcm_attr_map_foreach_cb) (const char *attr_name, enum xcm_attr_type attr_type, const void *attr_value, size_t attr_value_len, void *user) |
Functions | |
struct xcm_attr_map * | xcm_attr_map_create (void) |
struct xcm_attr_map * | xcm_attr_map_clone (const struct xcm_attr_map *original) |
void | xcm_attr_map_add (struct xcm_attr_map *attr_map, const char *attr_name, enum xcm_attr_type attr_type, const void *attr_value, size_t attr_value_len) |
void | xcm_attr_map_add_bool (struct xcm_attr_map *attr_map, const char *attr_name, bool attr_value) |
void | xcm_attr_map_add_int64 (struct xcm_attr_map *attr_map, const char *attr_name, int64_t attr_value) |
void | xcm_attr_map_add_double (struct xcm_attr_map *attr_map, const char *attr_name, double attr_value) |
void | xcm_attr_map_add_str (struct xcm_attr_map *attr_map, const char *attr_name, const char *attr_value) |
void | xcm_attr_map_add_bin (struct xcm_attr_map *attr_map, const char *attr_name, const void *attr_value, size_t attr_value_len) |
void | xcm_attr_map_add_all (struct xcm_attr_map *dst_map, const struct xcm_attr_map *src_map) |
const void * | xcm_attr_map_get (const struct xcm_attr_map *attr_map, const char *attr_name, enum xcm_attr_type *attr_type, size_t *attr_value_len) |
const bool * | xcm_attr_map_get_bool (const struct xcm_attr_map *attr_map, const char *attr_name) |
const int64_t * | xcm_attr_map_get_int64 (const struct xcm_attr_map *attr_map, const char *attr_name) |
const double * | xcm_attr_map_get_double (const struct xcm_attr_map *attr_map, const char *attr_name) |
const char * | xcm_attr_map_get_str (const struct xcm_attr_map *attr_map, const char *attr_name) |
const char * | xcm_attr_map_get_bin (const struct xcm_attr_map *attr_map, const char *attr_name) |
bool | xcm_attr_map_exists (const struct xcm_attr_map *attr_map, const char *attr_name) |
void | xcm_attr_map_del (struct xcm_attr_map *attr_map, const char *attr_name) |
size_t | xcm_attr_map_size (const struct xcm_attr_map *attr_map) |
void | xcm_attr_map_foreach (const struct xcm_attr_map *attr_map, xcm_attr_map_foreach_cb cb, void *user) |
bool | xcm_attr_map_equal (const struct xcm_attr_map *attr_map_a, const struct xcm_attr_map *attr_map_b) |
void | xcm_attr_map_destroy (struct xcm_attr_map *attr_map) |
XCM attribute map API.
An XCM attribute map is a set of key-value pairs. The key is an attribute name in the form of a string. One key maps to at most one value. The attribute value is either a boolean, a signed 64-bit integer, a double-precision floating point value, a string, or a variable-length binary object.
typedef void(* xcm_attr_map_foreach_cb) (const char *attr_name, enum xcm_attr_type attr_type, const void *attr_value, size_t attr_value_len, void *user) |
Callback function prototype used for iteration.
struct xcm_attr_map * xcm_attr_map_create | ( | void | ) |
Create an attribute map instance.
struct xcm_attr_map * xcm_attr_map_clone | ( | const struct xcm_attr_map * | original | ) |
Create a copy of an attribute map instance.
[in] | original | The original attribute map instance, to be copied. |
void xcm_attr_map_add | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
enum xcm_attr_type | attr_type, | ||
const void * | attr_value, | ||
size_t | attr_value_len | ||
) |
Associate a key with a value.
This function associates the attribute key attr_name
to the attribute value attr_value
in the attribute map attr_map
. If the key attr_name
already exists, its value is replaced.
Both the key and the value will be copied, and thus attr_name
and attr_value
will still be owned by the caller at call completion.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_type | The type of the value to be added. |
[in] | attr_value | The value of the attribute to be added. |
[in] | attr_value_len | The length (in bytes) of the value. |
void xcm_attr_map_add_bool | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
bool | attr_value | ||
) |
Associate a key with a boolean value.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_value | The boolean value of the attribute to be added. |
void xcm_attr_map_add_int64 | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
int64_t | attr_value | ||
) |
Associate a key with a 64-bit signed integer value.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_value | The integer value of the attribute to be added. |
void xcm_attr_map_add_double | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
double | attr_value | ||
) |
Associate a key with a double-precision floating point value.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_value | The double value of the attribute to be added. |
void xcm_attr_map_add_str | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
const char * | attr_value | ||
) |
Associate a key with a string value.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_value | The string value of the attribute to be added. |
void xcm_attr_map_add_bin | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
const void * | attr_value, | ||
size_t | attr_value_len | ||
) |
Associate a key with a byte buffer.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be added. |
[in] | attr_value | The value of the attribute to be added. |
void xcm_attr_map_add_all | ( | struct xcm_attr_map * | dst_map, |
const struct xcm_attr_map * | src_map | ||
) |
Copies all attributes of a map to another.
This function adds all the attributes of the source map to the target map. The source map remains unchanged.
[in] | dst_map | The attribute map to which the attributes will be added. |
[in] | src_map | The attribute map which attributes will be copied. |
const void * xcm_attr_map_get | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name, | ||
enum xcm_attr_type * | attr_type, | ||
size_t * | attr_value_len | ||
) |
Retrieve the value associated with a particular key.
This function retrieves the attribute value, value type and value length of the attribute attr_name
, in case it exists.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
[out] | attr_type | A pointer to a buffer where the value type will be stored, or NULL. |
[out] | attr_value_len | A pointer to a buffer where the length (in bytes) of the value will be stored, or NULL. |
const bool * xcm_attr_map_get_bool | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Retrieve the boolean value associated with a particular key.
This function retrieves the boolean attribute value of the attribute attr_name
, in case it exists and is of type xcm_attr_type_bool.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
const int64_t * xcm_attr_map_get_int64 | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Retrieve the integer value associated with a particular key.
This function retrieves the 64-bit signed integer attribute value of the attribute attr_name
, in case it exists and is of type xcm_attr_type_int64.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
const double * xcm_attr_map_get_double | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Retrieve the floating point value associated with a particular key.
This function retrieves the double-precision floating point attribute value of the attribute attr_name
, in case it exists and is of type xcm_attr_type_double.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
const char * xcm_attr_map_get_str | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Retrieve the string value associated with a particular key.
This function retrieves the NUL-terminated string attribute value of the attribute attr_name
, in case it exists and is of type xcm_attr_type_str.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
const char * xcm_attr_map_get_bin | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Retrieve the binary value associated with a particular key.
This function retrieves the attribute value, in the form of a sequence of bytes, of the attribute attr_name
, in case it exists and is of type xcm_attr_type_bin.
The value pointer returned is valid as long as the key is not removed, its value is changed, or the map is destroyed.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be retrieved. |
bool xcm_attr_map_exists | ( | const struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Check if an attribute named attr_name
exists in the attribute map.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute. |
void xcm_attr_map_del | ( | struct xcm_attr_map * | attr_map, |
const char * | attr_name | ||
) |
Removes an attribute from the attribute map.
This function deletes the attribute attr_name
, in case it exists.
[in] | attr_map | The attribute map instance. |
[in] | attr_name | The name of the attribute to be deleted. |
size_t xcm_attr_map_size | ( | const struct xcm_attr_map * | attr_map | ) |
Returns the number of attributes in the attribute map.
[in] | attr_map | The attribute map instance. |
attr_map
. void xcm_attr_map_foreach | ( | const struct xcm_attr_map * | attr_map, |
xcm_attr_map_foreach_cb | cb, | ||
void * | user | ||
) |
Iterates over all attributes in a map.
This function calls the supplied callback function cb
for each attribute in attr_map
.
The map may not be modified during iteration.
[in] | attr_map | The attribute map instance. |
[in] | cb | The callback function. |
[in] | user | An opaque pointer, supplied back to the application in every cb call. |
bool xcm_attr_map_equal | ( | const struct xcm_attr_map * | attr_map_a, |
const struct xcm_attr_map * | attr_map_b | ||
) |
Compares two attribute maps for equality (by value).
[in] | attr_map_a | An attribute map instance. |
[in] | attr_map_b | An attribute map instance. |
attr_map_a
and attr_map_a
are equal, false otherwise. void xcm_attr_map_destroy | ( | struct xcm_attr_map * | attr_map | ) |
Destroys an attribute map instance.
This function destroys the attribute map instance and frees all the resources associated with it.
[in] | attr_map | The attribute map instance, or NULL. |