mateconf-backend

## mateconf-backend mateconf-backend |

## Synopsis

                        MateConfBackendVTable;
                        MateConfBackend;
    gchar *             mateconf_address_backend               (const gchar *address);
    gchar *             mateconf_address_resource              (const gchar *address);
    gchar *             mateconf_backend_file                  (const gchar *address);
    MateConfBackend *      mateconf_get_backend                   (const gchar *address,
                                                             GError **err);
    void                mateconf_backend_ref                   (MateConfBackend *backend);
    void                mateconf_backend_unref                 (MateConfBackend *backend);
    MateConfSource *       mateconf_backend_resolve_address       (MateConfBackend *backend,
                                                             const gchar *address,
                                                             GError **err);

## Description

## Details

### MateConfBackendVTable

    typedef struct {
      /* Set to sizeof (MateConfBackendVTable) - used for future proofing */
      gsize                  vtable_size;

      void                (* shutdown)        (GError** err);

      MateConfSource*        (* resolve_address) (const gchar* address,
                                               GError** err);

      /* Thread locks. If the backend is thread-safe, then these
       * can be NULL. If per-source locks are needed, then these
       * calls should lock a mutex stored in the MateConfSource.
       * If a per-backend lock is needed, then the calls can ignore
       * their source argument and lock the whole backend.
       */
      void                (* lock)            (MateConfSource* source,
                                               GError** err);

      void                (* unlock)          (MateConfSource* source,
                                               GError** err);

      /* Report whether a given key (and its subkeys) can be read/written.
       * Sources may not permit reading/writing from/to /foo but forbid
       * writing to /foo/bar; if a key can be read or written then its
       * subkeys may also be read/written.
       *
       * This field allows backends to be configured so that they only
       * store certain kinds of data in certain sections of the MateConf
       * namespace.
       *
       * If these functions return an error, they MUST return FALSE as
       * well.
       */

      gboolean           (* readable)         (MateConfSource* source,
                                               const gchar* key,
                                               GError** err);

      gboolean           (* writable)        (MateConfSource* source,
                                               const gchar* key,
                                               GError** err);

      /* schema_name filled if NULL or MATECONF_VALUE_IGNORE_SUBSEQUENT returned.
         if schema_name is NULL, it isn't filled */
      MateConfValue*         (* query_value)     (MateConfSource* source,
                                               const gchar* key,
                                               const gchar** locales,
                                               gchar** schema_name,
                                               GError** err);

      MateConfMetaInfo*      (* query_metainfo)  (MateConfSource* source,
                                               const gchar* key,
                                               GError** err);

      void                (* set_value)       (MateConfSource* source,
                                               const gchar* key,
                                               const MateConfValue* value,
                                               GError** err);

      /* Returns list of MateConfEntry with key set to a relative
       * pathname. In the public client-side API the key
       * is always absolute though.
       */
      GSList*             (* all_entries)     (MateConfSource* source,
                                               const gchar* dir,
                                               const gchar** locales,
                                               GError** err);

      /* Returns list of allocated strings, relative names */
      GSList*             (* all_subdirs)     (MateConfSource* source,
                                               const gchar* dir,
                                               GError** err);

      void                (* unset_value)     (MateConfSource* source,
                                               const gchar* key,
                                               const gchar* locale,
                                               GError** err);

      gboolean            (* dir_exists)      (MateConfSource* source,
                                               const gchar* dir,
                                               GError** err);

      void                (* remove_dir)      (MateConfSource* source,
                                               const gchar* dir,
                                               GError** err);

      void                (* set_schema)      (MateConfSource* source,
                                               const gchar* key,
                                               const gchar* schema_key,
                                               GError** err);

      gboolean            (* sync_all)        (MateConfSource* source,
                                               GError** err);

      void                (* destroy_source)  (MateConfSource* source);

      /* This is basically used by the test suite */
      void                (* clear_cache)     (MateConfSource* source);

      /* used by mateconf-sanity-check */
      void                (* blow_away_locks) (const char *address);

      void                (* set_notify_func) (MateConfSource           *source,
    					   MateConfSourceNotifyFunc  notify_func,
    					   gpointer               user_data);

      void                (* add_listener)    (MateConfSource           *source,
    					   guint                  id,
    					   const gchar           *namespace_section);

      void                (* remove_listener) (MateConfSource           *source,
    					   guint                  id);
    } MateConfBackendVTable;

The MateConfBackendVTable is a table of methods that any MateConf backend must implement. The dynamically loaded library module should export a function called `mateconf_backend_get_vtable()` that returns a pointer to a MateConfBackendVTable.

Here is the specification of the vtable members:

`vtable_size` | The size of the vtable structure. This is used by the daemon to ensure that a mismatch between the version of MateConf the backend was compiled against and the version the daemon was compiled against can be handled gracefully. Set this field to sizeof (MateConfBackendVtable).
`shutdown` | Called prior to unloading the dynamic module. Should ensure that no functions or static/global variables from the module will ever be accessed again. Should free any memory that the backend no longer needs.
`resolve_address` | Should create a MateConfSource for accessing the supplied address. Should set the `MATECONF_SOURCE_ALL_READABLE` and `MATECONF_SOURCE_ALL_WRITEABLE` flags if appropriate. If these are not set, the backend must implement the `writable` and `readable` methods. If NULL is returned, then the error should be set.
`lock` | If the backend is thread safe (does its own locking or whatever), then `lock` and `unlock` can be NULL. If the backend requires a lock for each source, then `lock` and `unlock` should lock/unlock that lock. If the backend has a global lock for all uses of the backend, then `lock` and `unlock` should ignore their arguments and lock the entire backend.
`unlock` | See description of `lock`.
`readable` | If the `MATECONF_SOURCE_ALL_READABLE` flag is set, this method is never called and may be NULL. If `MATECONF_SOURCE_ALL_READABLE` is unset, and this method is NULL, then the source is write-only. If this method is implemented, it should return TRUE if the given key could be read from the given source. TRUE should be returned even if the key is unset; this function returns something similar to permissions, it is not asking whether the key exists. If an error is set, then FALSE must be returned.
`writable` | Analagous to `readable`, but for writing.
`query_value` | This method must be implemented if the source is readable. It returns the value of a key. The "locales" argument is a NULL-terminated vector of locale names, where the first locale in the vector is the preferred locale, the next is the second choice, etc. if the "schema_name" argument is non-NULL, then it should be filled with an allocated string giving the name of the schema attached to the key, if and only if NULL is returned. This is an optimization to avoid looking up the same key again in the database if it's unset and we need to ask for its default value from the schema. If NULL is returned, indicating that the key is unset, then schema_name should not be filled in. If this method sets an error, NULL must be returned. It may not set an error while also returning a value. The returned value will be destroyed by the caller, so should be a copy of the backend's internal data.
`query_metainfo` | This method must be implemented. If any metainfo is available about a key, it returns a MateConfMetaInfo with that metainfo set. If none is available, NULL is returned. NULL should also be returned if an error is set.
`set_value` | This method must be implemented if the source is writable. It sets the value of a key. If the key is already set, its value should be replaced. Setting a value should update the modification time of the key.
`all_entries` | This method must be implemented. It returns a list of all keys in the given directory for which some information is available (metainfo or values). The returned list should contain MateConfEntry objects. On error, NULL should be returned and the error set. Subdirectories should not be included in the returned list. The list and the MateConfEntry objects will be freed by the caller.
`all_subdirs` | This method must be implemented. It returns a list of all the subdirectories in a given directory. It should return the subdirectories as relative paths, i.e. there should not be any slashes in the subdirectory name. Each subdirectory in the list should be an allocated string; the list and the strings will be freed by the caller.
`unset_value` | If the given key has a value, then this method should unset the value. If a value is unset, subsequent calls to `query_value` should return NULL. If the locale string passed in to `unset_value` is non-NULL, then only the value for that locale should be unset. If NULL, the value should be globally unset for all locales.
`dir_exists` | Determines whether a directory exists. Should return TRUE if there is a directory with the given name.
`remove_dir` | Should remove a directory, recursively: including all its subdirectories and all the values and keys inside the directory.
`set_schema` | Should associate a schema name with a key.
`sync_all` | Should ensure that all data is stored on permanent media, or whatever makes sense for the backend. Called periodically by the MateConf daemon.
`destroy_source` | Should destroy a source obtained with `resolve_address`.
`clear_cache` | Discard any cached data after saving the data to permanent storage.
`blow_away_locks` | Unconditionally discard any locks whether they are stale or otherwise in order to force the backend to be able to obtain access to its data store.
`set_notify_func` | If the backend wishes to notify the daemon of changes in the value of keys it must implement this method. In order to notify the daemon of a change, the backend should invoke the supplied `notify_func` with `user_data`. Backends must not notify the daemon of changes which the daemon has not expressed interest in by adding a listener with `add_listener`. Also, the backend must make every effort to minimise the number of notifications it emits. For example, if the daemon has added a listener for /apps and another for /apps/foo and the value of /apps/foo/bar changes, the backend should only emit a single notification.
`add_listener` | If it is possible for entries to be changed concurrently by another daemon, the backend may support notifying the daemon (and any listening clients) of such changes. This function should add a listener to a section of the tree and when any of the following events occur, the backend should invoke the notify function with the key that has changed: If the entry is set or unset If the entry's value changes If the entry's schema name changes If the entry is a schema and its value in any locale changes Note, the backend should not notify the daemon of any changes that originated from the daemon itself.
`remove_listener` | Remove a listener added with `add_listener`. The listener is identified by the integer supplied.

### MateConfBackend

    typedef struct {
      const gchar* name;
      guint refcount;
      MateConfBackendVTable vtable;
      GModule* module;
    } MateConfBackend;

### mateconf_address_backend ()

    gchar *             mateconf_address_backend               (const gchar *address);

`address` : |
Returns : |

### mateconf_address_resource ()

    gchar *             mateconf_address_resource              (const gchar *address);

`address` : |
Returns : |

### mateconf_backend_file ()

    gchar *             mateconf_backend_file                  (const gchar *address);

`address` : |
Returns : |

### mateconf_get_backend ()

    MateConfBackend *      mateconf_get_backend                   (const gchar *address,
                                                             GError **err);

`address` : |
`err` : |
Returns : |

### mateconf_backend_ref ()

    void                mateconf_backend_ref                   (MateConfBackend *backend);

`backend` : |

### mateconf_backend_unref ()

    void                mateconf_backend_unref                 (MateConfBackend *backend);

`backend` : |

### mateconf_backend_resolve_address ()

    MateConfSource *       mateconf_backend_resolve_address       (MateConfBackend *backend,
                                                             const gchar *address,
                                                             GError **err);

`backend` : |
`address` : |
`err` : |
Returns : |