Included is API proposal for replacement of objdb/confdb API. It should
keep all good things there (triggers, ...), remove hard to use bits
(like whole object idea) and improve existing things (like typing)

Even I wrote it before, also configuration file will need change.

Proposed change is

ht_key value
ht_key. {
        ht_subkey value2
}

which is (internally) converted to
ht_key value
ht_key.ht_subkey value2

Also value should become typed, so
value ~= ^-?[0-9]+$ = integer 32 bits, with modificators like l, ll, ...
value ~= ^-?[0-9]*.[0-9]*$ = float (or double) (also should handle all
variants with E .. basically C format)
value = "[:alpha:]*" = string
value = bin:base64 encoded binary data

Regards,
  Honza
/*
 * Configuration hash table - API DRAFT v1
 *
 * Public (service) API. Internal API has different names (beginning with i?) 
and also function
 * for set part of tree not vivisible and writable from service
 */

#ifndef COROSYNC_CHT_H_DEFINED
#define COROSYNC_CHT_H_DEFINED

#include <corosync/corotypes.h>
#include <corosync/hdb.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup cht_corosync
 *
 * @{
 */
typedef uint64_t cht_handle_t;
typedef uint64_t cht_iter_handle_t;
typedef uint64_t cht_track_handle_t;

#define CHT_KEYNAME_MAXLEN      256

typedef enum {
        CHT_VALUETYPE_INT16,
        CHT_VALUETYPE_UINT16,
        CHT_VALUETYPE_INT32,
        CHT_VALUETYPE_UINT32,
        CHT_VALUETYPE_INT64,
        CHT_VALUETYPE_UINT64,
        CHT_VALUETYPE_FLOAT,
        CHT_VALUETYPE_DOUBLE,
        CHT_VALUETYPE_STRING,
        CHT_VALUETYPE_BINARY,
} cht_value_types_t;

#define CHT_TRACK_ADD            1
#define CHT_TRACK_DELETE         2
#define CHT_TRACK_MODIFY         4

typedef enum {
        CHT_RELOAD_NOTIFY_START,
        CHT_RELOAD_NOTIFY_END,
        CHT_RELOAD_NOTIFY_FAILED
} cht_reload_type_t;
                        
typedef void (*cht_notify_fn_t) (
        cht_track_handle_t handle,
        unsigned int track_type,
        const char *key_name);

typedef void (*cht_reload_notify_fn_t) (
        cht_track_handle_t handle,
        cht_reload_type_t reload_type);

/** @} */


/*
 * Create a new cht connection
 * @param handle will be filled with handle to be used for all following
 * operations with cht.
 * @param callbacks callbacks for cht or NULL
 */
cs_error_t cht_initialize (
        cht_handle_t *handle);

/*
 * Close the cht handle
 * @param handle cht handle
 */
cs_error_t cht_finalize (
        cht_handle_t handle);

/*
 * Get a file descriptor on which to poll.  cht_handle_t is NOT a
 * file descriptor and may not be used directly.
 * @param handle cht handle initialized by cht_initialize
 * @param fd file descriptor for poll
 */
cs_error_t cht_fd_get (
        cht_handle_t handle,
        int *fd);

/*
 * Dispatch changes
 */
cs_error_t cht_dispatch (
        cgt_handle_t handle,
        cs_dispatch_flags_t dispatch_types);

/*
 * Manipulate keys.
 *
 * key_name is string ending by \0, which can contain characters
 * [a-z][A-Z][0-9]._-/
 * maximum key_name length is CHT_KEYNAME_MAXLEN
 */

/*
 * Set value of cht. If key doesn't exist yet, it's created, otherwise it's
 * replaced by new value.
 * @param handle cht handle
 * @param value pointer to value
 * @param value_len length of value data
 * @param type type to store.
 */
cs_error_t cht_set (
        cht_handle_t handle,
        const char *key_name,
        const void *value,
        size_t value_len,
        cht_value_types_t type);

/*
 * Shortcut for cht_set with int16 type
 */
cs_error_t cht_set_int16 (
    cht_handle_t handle,
    const char *key_name,
    int16_t value);

/*
 * Shortcut for cht_set with uint16 type
 */
cs_error_t cht_set_uint16 (
    cht_handle_t handle,
    const char *key_name,
    uint16_t value);

/*
 * Shortcut for cht_set with int32 type
 */
cs_error_t cht_set_int32 (
    cht_handle_t handle,
    const char *key_name,
    int32_t value);

/*
 * Shortcut for cht_set with uint32 type
 */
cs_error_t cht_set_uint32 (
    cht_handle_t handle,
    const char *key_name,
    uint32_t value);

/*
 * Shortcut for cht_set with int64 type
 */
cs_error_t cht_set_int64 (
    cht_handle_t handle,
    const char *key_name,
    int64_t value);

/*
 * Shortcut for cht_set with uint64 type
 */
cs_error_t cht_set_uint64 (
    cht_handle_t handle,
    const char *key_name,
    uint64_t value);

/*
 * Shortcut for cht_set with float type
 */
cs_error_t cht_set_float (
    cht_handle_t handle,
    const char *key_name,
    float value);

/*
 * Shortcut for cht_set with double type
 */
cs_error_t cht_set_double (
    cht_handle_t handle,
    const char *key_name,
    double value);

/*
 * Shortcut for cht_set with string type
 */
cs_error_t cht_set_string (
    cht_handle_t handle,
    const char *key_name,
    char *value);

/*
 * Delete key from cht
 */
cs_error_t cht_delete (
        cht_handle_t handle,
        const char *key_name);

/*
 * Get value from cht. value_len is checked with real size of value in cht and
 * if is smaller, error code is returned. On the end of call, value_len is
 * filled by real size of value in cht. value also can be NULL and then only
 * type (if not NULL) and len (if not NULL) is returned.
 */
cs_error_t cht_get (
        cht_handle_t handle,
        const char *key_name,
        void *value,
        size_t *value_len,
        cht_value_types_t *type);

/*
 * Shortcut functions.
 *
 * Simple and well defined conversions are made automatically so:
 * real_value           conversion to
 * ----------           -------------
 * int16                int[32,64], double, float
 * uint16               [u]int[32,64], double, float
 * int32                int64, double, float
 * uint32               [u]int[64], double, float
 * int64                double, float
 * uint64               double, float
 * float                double
 */

/*
 * Shortcut for cht_get for int16. Err can be 
 */
int16_t cht_get_int16 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for uint16
 */
uint16_t cht_get_uint16 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for int32
 */
int32_t cht_get_int32 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for uint32
 */
uint32_t cht_get_uint32 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for int64
 */
int64_t cht_get_int64 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for uint64
 */
uint64_t cht_get_uint64 (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for float 
 */
float cht_get_float (
    cht_handle_t handle,
    const char *key_name,
    cs_error_t *err);

/*
 * Shortcut for cht_get for double
 */
double cht_get_double (
        cht_handle_t handle,
        const char *key_name,
        cs_error_t *err);

/*
 * Increment key. Operation is defined only for int* and uint* types.
 */
cs_error_t cht_increment (
        cht_handle_t handle,
        const char *key_name);

cs_error_t cht_decrement (
        cht_handle_t handle,
        const char *key_name);

/*
 * Reload the configuration
 */
cs_error_t cht_reload (
    cht_handle_t handle);

/*
 * Iteration
 */

/* Initialize iterator.
 *
 * @param prefix is prefix of key_name of keys to iterate. It can be NULL or
 * empty string and then whole HT is iterated.
 *
 * There are no quaranties for order of items and also behavior for items added
 * and/or deleted after start of iteration is undefined.
 */
cs_error_t cht_iter_init (
        cht_handle_t handle,
        const char *prefix,
        cht_iter_handle_t *cht_iter_handle);

cs_error_t cht_iter_next (
        cht_iter_handle_t handle,
        char key_name[CHT_KEYNAME_MAXLEN]);

cs_error_t cht_iter_finalize (
        cht_iter_handle_t handle);

/*
 * Track changes
 */

/*
 * Track changes on key. Track is bitfield of CHT_TRACK_*
 */
cs_error_t cht_track_add (
        cht_handle_t handle,
        const char *key_name,
        unsigned int track_type
        cht_notify_fn_t notify_fn,
        cht_track_handle_t *handle);

/*
 * Track changes on prefix. key_prefix can be NULL or 0 and then all changes are
 * tracked
 */
cs_error_t cht_track_prefix_add (
        cht_handle_t handle,
        const char *key_prefix,
        unsigned int track_type,
        cht_notify_fn_t notify_fn,
        cht_track_handle_t *handle);

/*
 * Track reload configurations
 */
cs_error_t cht_track_reload_add (
        cht_handle_t handle,
        cht_reload_notify_fn_t notify_fn,
        cht_track_handle_t *handle);

/*
 * Delete tracker from system
 */
cs_error_t cht_track_delete (
        cht_track_handle_t handle);

/*
 * Get/set context variable
 */

cs_error_t cht_context_get (
        cht_handle_t handle,
        const void **context);

cs_error_t cht_context_set (
        cht_handle_t handle,
        const void *context);

#ifdef __cplusplus
}
#endif

#endif /* COROSYNC_CHT_H_DEFINED */
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to