From: <svn...@op...> - 2009-03-31 11:29:18
|
Author: bellmich Date: Tue Mar 31 13:29:05 2009 New Revision: 5480 URL: http://www.opensync.org/changeset/5480 Log: - renamed OSyncAnchor to OSyncSinkStateDB - renamed some functions because of the getter/setter pattern Modified: trunk/opensync/helper/opensync_sink_state_db.c trunk/opensync/helper/opensync_sink_state_db.h trunk/opensync/helper/opensync_sink_state_db_internals.h trunk/opensync/helper/opensync_sink_state_db_private.h Modified: trunk/opensync/helper/opensync_sink_state_db.c ============================================================================== --- trunk/opensync/helper/opensync_sink_state_db.c Tue Mar 31 11:28:47 2009 (r5479) +++ trunk/opensync/helper/opensync_sink_state_db.c Tue Mar 31 13:29:05 2009 (r5480) @@ -27,15 +27,17 @@ #include "opensync_sink_state_db_internals.h" #include "opensync_sink_state_db_private.h" -osync_bool osync_anchor_create(OSyncAnchor *anchor, OSyncError **error) +static osync_bool osync_sink_states_table_create( + OSyncSinkStateDB *sinkStateDB, + OSyncError **error) { char *query = NULL; - osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, anchor, error); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, sinkStateDB, error); /* TODO: How portable to other databes is UNIQUE? */ - query = osync_strdup("CREATE TABLE tbl_anchor (id INTEGER PRIMARY KEY, key VARCHAR UNIQUE, value VARCHAR, objtype VARCHAR)"); + query = osync_strdup("CREATE TABLE tbl_sink_states (id INTEGER PRIMARY KEY, key VARCHAR UNIQUE, value VARCHAR, objtype VARCHAR)"); - if (!osync_db_query(anchor->db, query, error)) { + if (!osync_db_query(sinkStateDB->db, query, error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); osync_free(query); return FALSE; @@ -47,133 +49,143 @@ return TRUE; } -OSyncAnchor *osync_anchor_new(const char *filename, const char *objtype, OSyncError **error) +OSyncSinkStateDB *osync_sink_state_db_new( + const char *filename, + const char *objtype, + OSyncError **error) { - OSyncAnchor *anchor = NULL; + OSyncSinkStateDB *sinkStateDB = NULL; int ret = 0; osync_trace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, __NULLSTR(filename), __NULLSTR(objtype), error); - anchor = osync_try_malloc0(sizeof(OSyncAnchor), error); - if (!anchor) + sinkStateDB = osync_try_malloc0(sizeof(OSyncSinkStateDB), error); + if (!sinkStateDB) goto error; - anchor->ref_count = 1; + sinkStateDB->ref_count = 1; /* Could be NULL, which means object type neutral * or data for the main-sink. */ if (objtype) - anchor->objtype = osync_strdup(objtype); + sinkStateDB->objtype = osync_strdup(objtype); - anchor->db = osync_db_new(error); - if (!anchor->db) - goto error_free_anchor; + sinkStateDB->db = osync_db_new(error); + if (!sinkStateDB->db) + goto error; - if (!osync_db_open(anchor->db, filename, error)) { + if (!osync_db_open(sinkStateDB->db, filename, error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - goto error_free_db; + goto error; } - ret = osync_db_table_exists(anchor->db, "tbl_anchor", error); + ret = osync_db_table_exists(sinkStateDB->db, "tbl_sink_states", error); if (ret > 0) { - osync_trace(TRACE_EXIT, "%s: %p", __func__, anchor->db); - return anchor; + osync_trace(TRACE_EXIT, "%s: %p", __func__, sinkStateDB->db); + return sinkStateDB; /* error if ret == -1 */ } else if (ret < 0) { - goto error_free_db; + goto error; } /* ret equal 0 means table does not exist yet. continue and create one. */ - if (!osync_anchor_create(anchor, error)) - goto error_free_db; + if (!osync_sink_states_table_create(sinkStateDB, error)) + goto error; - osync_trace(TRACE_EXIT, "%s: %p", __func__, anchor); - return anchor; + osync_trace(TRACE_EXIT, "%s: %p", __func__, sinkStateDB); + return sinkStateDB; - error_free_db: - osync_free(anchor->db); - error_free_anchor: - osync_anchor_unref(anchor); error: + if (sinkStateDB && sinkStateDB->db) + osync_free(sinkStateDB->db); + if (sinkStateDB) + osync_sink_state_db_unref(sinkStateDB); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; } -OSyncAnchor *osync_anchor_ref(OSyncAnchor *anchor) +OSyncSinkStateDB *osync_sink_state_db_ref(OSyncSinkStateDB *sinkStateDB) { - osync_return_val_if_fail(anchor, NULL); + osync_return_val_if_fail(sinkStateDB, NULL); - g_atomic_int_inc(&(anchor->ref_count)); + g_atomic_int_inc(&(sinkStateDB->ref_count)); - return anchor; + return sinkStateDB; } -void osync_anchor_unref(OSyncAnchor *anchor) +void osync_sink_state_db_unref(OSyncSinkStateDB *sinkStateDB) { - osync_return_if_fail(anchor); + osync_return_if_fail(sinkStateDB); - if (g_atomic_int_dec_and_test(&(anchor->ref_count))) { + if (g_atomic_int_dec_and_test(&(sinkStateDB->ref_count))) { - if (!osync_db_close(anchor->db, NULL)) + if (!osync_db_close(sinkStateDB->db, NULL)) osync_trace(TRACE_INTERNAL, "Can't close database"); - if (anchor->objtype) - osync_free(anchor->objtype); + if (sinkStateDB->objtype) + osync_free(sinkStateDB->objtype); - osync_free(anchor->db); + osync_free(sinkStateDB->db); - osync_free(anchor); + osync_free(sinkStateDB); } } -char *osync_anchor_retrieve(OSyncAnchor *anchor, const char *key, OSyncError **error) +char *osync_sink_state_get( + OSyncSinkStateDB *sinkStateDB, + const char *key, + OSyncError **error) { - char *retanchor = NULL; + char *value = NULL; char *query = NULL, *escaped_key; - osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, anchor, error); - osync_assert(anchor); - osync_assert(anchor->db); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, sinkStateDB, error); + osync_assert(sinkStateDB); + osync_assert(sinkStateDB->db); osync_assert(key); escaped_key = osync_db_sql_escape(key); - query = osync_strdup_printf("SELECT value FROM tbl_anchor WHERE key='%s' AND objtype='%s'", - escaped_key, anchor->objtype ? anchor->objtype : ""); + query = osync_strdup_printf("SELECT value FROM tbl_sink_states WHERE key='%s' AND objtype='%s'", + escaped_key, sinkStateDB->objtype ? sinkStateDB->objtype : ""); osync_free(escaped_key); - retanchor = osync_db_query_single_string(anchor->db, query, error); + value = osync_db_query_single_string(sinkStateDB->db, query, error); osync_free(query); if (osync_error_is_set(error)) goto error; - if (!retanchor) - retanchor = osync_strdup(""); + if (!value) + value = osync_strdup(""); - osync_trace(TRACE_EXIT, "%s: %s", __func__, retanchor); - return retanchor; + osync_trace(TRACE_EXIT, "%s: %s", __func__, value); + return value; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; } -osync_bool osync_anchor_update(OSyncAnchor *anchor, const char *key, const char *value, OSyncError **error) +osync_bool osync_sink_state_set( + OSyncSinkStateDB *sinkStateDB, + const char *key, + const char *value, + OSyncError **error) { char *escaped_value = NULL, *escaped_key = NULL; char *query = NULL; - osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, anchor, __NULLSTR(value), error); - osync_assert(anchor); - osync_assert(anchor->db); + osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, sinkStateDB, __NULLSTR(value), error); + osync_assert(sinkStateDB); + osync_assert(sinkStateDB->db); osync_assert(key); osync_assert(value); escaped_key = osync_db_sql_escape(key); escaped_value = osync_db_sql_escape(value); - query = osync_strdup_printf("REPLACE INTO tbl_anchor (objtype, key, value) VALUES('%s', '%s', '%s')", - anchor->objtype ? anchor->objtype : "", escaped_key, escaped_value); + query = osync_strdup_printf("REPLACE INTO tbl_sink_states (objtype, key, value) VALUES('%s', '%s', '%s')", + sinkStateDB->objtype ? sinkStateDB->objtype : "", escaped_key, escaped_value); osync_free(escaped_value); osync_free(escaped_key); - if (!osync_db_query(anchor->db, query, error)) + if (!osync_db_query(sinkStateDB->db, query, error)) goto error; osync_free(query); @@ -186,16 +198,21 @@ return FALSE; } -osync_bool osync_anchor_compare(OSyncAnchor *anchor, const char *key, const char *value, osync_bool *same, OSyncError **error) +osync_bool osync_sink_state_equal( + OSyncSinkStateDB *sinkStateDB, + const char *key, + const char *value, + osync_bool *same, + OSyncError **error) { char *old_value = NULL; - osync_trace(TRACE_ENTRY, "%s(%p, %s, %s, %p, %p)", __func__, anchor, __NULLSTR(key), __NULLSTR(value), same, error); - osync_assert(anchor); + osync_trace(TRACE_ENTRY, "%s(%p, %s, %s, %p, %p)", __func__, sinkStateDB, __NULLSTR(key), __NULLSTR(value), same, error); + osync_assert(sinkStateDB); osync_assert(key); osync_assert(value); - old_value = osync_anchor_retrieve(anchor, key, error); + old_value = osync_sink_state_get(sinkStateDB, key, error); if (!old_value) goto error; Modified: trunk/opensync/helper/opensync_sink_state_db.h ============================================================================== --- trunk/opensync/helper/opensync_sink_state_db.h Tue Mar 31 11:28:47 2009 (r5479) +++ trunk/opensync/helper/opensync_sink_state_db.h Tue Mar 31 13:29:05 2009 (r5480) @@ -18,18 +18,18 @@ * */ -#ifndef OPENSYNC_ANCHOR_H_ -#define OPENSYNC_ANCHOR_H_ +#ifndef OPENSYNC_SINK_STATE_DB_H_ +#define OPENSYNC_SINK_STATE_DB_H_ /** * @defgroup OSyncHelper OpenSync Helper Module * @ingroup OSyncPublic - * @defgroup OSyncAnchorAPI OpenSync Anchor + * @defgroup OSyncSinkStateDatabaseAPI OpenSync Sink State Database * @ingroup OSyncHelper * @brief Functions to deal with anchors * * The Anchor module stores anchors and peer states from the Member in a - * persistent database (which can be flushed by the Engien anytime!). + * persistent database (which can be flushed by the Engine anytime!). * This "anchor" shoudl get updated once on each sync. * * Example: @@ -49,41 +49,54 @@ */ /*@{*/ -/** @brief Compares the anchor value of key with the supplied value +/** @brief Compares the anchor/state value of key with the supplied value * - * @param anchor Pointer to the anchor object + * @param sinkStateDB Pointer to the sink state database object * @param key the key of the value to compare - * @param value the value to compare with the stored anchor value + * @param value the value to compare with the stored anchor/state value * @param issame Pointer to osync_bool to determine the comaprsion result * @param error Pointer to error struct, which get set on any error - * @returns TRUE if the anchor compare completed successful, FALSE on error. Not the return value of the comparsion! + * @returns TRUE if the anchor/state compare completed successful, FALSE on error. Not the return value of the comparsion! * */ -OSYNC_EXPORT osync_bool osync_anchor_compare(OSyncAnchor *anchor, const char *key, const char *value, osync_bool *issame, OSyncError **error); +OSYNC_EXPORT osync_bool osync_sink_state_equal( + OSyncSinkStateDB *sinkStateDB, + const char *key, + const char *value, + osync_bool *issame, + OSyncError **error); -/** @brief Updates the anchor value of the key +/** @brief Sets the anchor/state value of the key * - * @param anchor Pointer to the anchor object + * @param sinkStateDB Pointer to the sink state database object * @param key the key of the value to set * @param value the new value to set * @param error Pointer to error struct, which get set on any error - * @returns TRUE if anchor update completed successful, FALSE on error. + * @returns TRUE if anchor/state update completed successful, FALSE on error. * */ -OSYNC_EXPORT osync_bool osync_anchor_update(OSyncAnchor *anchor, const char *key, const char *value, OSyncError **error); +OSYNC_EXPORT osync_bool osync_sink_state_set( + OSyncSinkStateDB *sinkStateDB, + const char *key, + const char *value, + OSyncError **error); -/** @brief Retrieves the anchor value of the supplied key +/** @brief Gets the anchor/state value of the supplied key * - * @param anchor Pointer to the anchor object - * @param key The key as string of the anchor value to retrieve + * @param sinkStateDB Pointer to the sink state database object + * @param key The key as string of the anchor/state value to retrieve * @param error Pointer to error struct, which get set on any error - * @returns the value of the anchor if it was found, otherwise an empty string get retruned. + * @returns the value of the anchor/state if it was found, + * otherwise an empty string get returned. * Caller is responsible for freeing the return value with osync_free(). - * NULL on error of retrieving the anchor information. + * NULL on error of retrieving the anchor/state information. * */ -OSYNC_EXPORT char *osync_anchor_retrieve(OSyncAnchor *anchor, const char *key, OSyncError **error); +OSYNC_EXPORT char *osync_sink_state_get( + OSyncSinkStateDB *sinkStateDB, + const char *key, + OSyncError **error); /*@}*/ -#endif /* OPENSYNC_ANCHOR_H_ */ +#endif /* OPENSYNC_SINK_STATE_DB_H_ */ Modified: trunk/opensync/helper/opensync_sink_state_db_internals.h ============================================================================== --- trunk/opensync/helper/opensync_sink_state_db_internals.h Tue Mar 31 11:28:47 2009 (r5479) +++ trunk/opensync/helper/opensync_sink_state_db_internals.h Tue Mar 31 13:29:05 2009 (r5480) @@ -18,52 +18,45 @@ * */ -#ifndef OPENSYNC_ANCHOR_INTERNALS_H_ -#define OPENSYNC_ANCHOR_INTERNALS_H_ +#ifndef OPENSYNC_SINK_STATE_DB_INTERNALS_H_ +#define OPENSYNC_SINK_STATE_DB_INTERNALS_H_ /** - * @defgroup OSyncAnchorInternalAPI OpenSync Anchor Internals + * @defgroup OSyncSinkStateDatabaseInternalAPI OpenSync Sink State Database Internals * @ingroup OSyncHelperPrivate - * @brief Internal functions to deal with anchors + * @brief Internal functions to deal with anchors and other sink related state informations */ /** - * @brief Create the anchor table in the specified database - * - * @param anchor Pointer to the anchor - * @param error Pointer to an error struct - * @returns TRUE if the table was created successfully, FALSE otherwise - * - */ -osync_bool osync_anchor_create(OSyncAnchor *anchor, OSyncError **error); - -/** - * @brief Create an anchor database + * @brief Create an sink state database * * @param filename the full path to the database file to create - * @param objtype Object Type to assoicate this anchor, NULL for main-sink. + * @param objtype Object Type to associate this anchor or state, NULL for main-sink. * @param error Pointer to an error struct * @returns a pointer to the new database, NULL on error * */ -OSyncAnchor *osync_anchor_new(const char *filename, const char *objtype, OSyncError **error); +OSyncSinkStateDB *osync_sink_state_db_new( + const char *filename, + const char *objtype, + OSyncError **error); /** - * @brief Increase the reference count on an anchor + * @brief Increase the reference count on a database * - * @param anchor Pointer to the anchor + * @param sinkStateDB Pointer to the database * */ -OSyncAnchor *osync_anchor_ref(OSyncAnchor *anchor); +OSyncSinkStateDB *osync_sink_state_db_ref(OSyncSinkStateDB *sinkStateDB); /** - * @brief Decrease the reference count on an anchor + * @brief Decrease the reference count on a database * - * @param anchor Pointer to the anchor + * @param sinkStateDB Pointer to the database * */ -void osync_anchor_unref(OSyncAnchor *anchor); +void osync_sink_state_db_unref(OSyncSinkStateDB *sinkStateDB); /*@}*/ -#endif /* OPENSYNC_ANCHOR_INTERNALS_H_ */ +#endif /* OPENSYNC_SINK_STATE_DB_INTERNALS_H_ */ Modified: trunk/opensync/helper/opensync_sink_state_db_private.h ============================================================================== --- trunk/opensync/helper/opensync_sink_state_db_private.h Tue Mar 31 11:28:47 2009 (r5479) +++ trunk/opensync/helper/opensync_sink_state_db_private.h Tue Mar 31 13:29:05 2009 (r5480) @@ -18,23 +18,23 @@ * */ -#ifndef OPENSYNC_ANCHOR_PRIVATE_H_ -#define OPENSYNC_ANCHOR_PRIVATE_H_ +#ifndef OPENSYNC_SINK_STATE_DB_PRIVATE_H_ +#define OPENSYNC_SINK_STATE_DB_PRIVATE_H_ /** * @defgroup OSyncHelperPrivate OpenSync Helper Module Private * @ingroup OSyncPrivate - * @defgroup OSyncAnchorPrivateAPI OpenSync Anchor Private + * @defgroup OSyncSinkStateDatabasePrivateAPI OpenSync Sink State Database Private * @ingroup OSyncHelperPrivate - * @brief Internal functions to deal with anchors + * @brief Internal functions to deal with anchors and other sink related state informations */ /*@{*/ /** - * @brief OSyncAnchor struct + * @brief OSyncSinkStateDB struct */ -struct OSyncAnchor { +struct OSyncSinkStateDB { /* Reference counting */ int ref_count; /* Pointer to the OSyncDatabase */ @@ -45,4 +45,4 @@ /*@}*/ -#endif /* OPENSYNC_ANCHOR_PRIVATE_H_ */ +#endif /* OPENSYNC_SINK_STATE_DB_PRIVATE_H_ */ |