MidgardReplicator

MidgardReplicator — Object serialization and replication.

Synopsis

#include <midgard/midgard.h>

                    MidgardReplicatorPrivate;
struct              MidgardReplicator;
typedef             MidgardReplicatorClass;
gchar *             midgard_replicator_serialize        (GObject *object);
gboolean            midgard_replicator_export           (MidgardDBObject *object);
gchar *             midgard_replicator_export_purged    (MidgardConnection *mgd,
                                                         const gchar *classname,
                                                         const gchar *startdate,
                                                         const gchar *enddate);
gchar *             midgard_replicator_serialize_blob   (MidgardObject *object);
gchar *             midgard_replicator_export_blob      (MidgardObject *object);
gboolean            midgard_replicator_export_by_guid   (MidgardConnection *mgd,
                                                         const gchar *guid);
gchar *             midgard_replicator_export_media     (MidgardObject *object);
GObject **          midgard_replicator_unserialize      (MidgardConnection *mgd,
                                                         const gchar *xml,
                                                         gboolean force);
gboolean            midgard_replicator_import_object    (MidgardDBObject *object,
                                                         gboolean force);
void                midgard_replicator_import_from_xml  (MidgardConnection *mgd,
                                                         const gchar *xml,
                                                         gboolean force);

Description

MidgardReplicator lets you serialize and unserialize objects. Once transformed to string, can be sent as custom message through D_Bus services, imported to different database, stored in files, etc.

  • http://www.midgard-project.org/development/mrfc/view/0030.html

  • http://www.midgard-project.org/development/mrfc/view/0033.html

Details

MidgardReplicatorPrivate

typedef struct _MidgardReplicatorPrivate MidgardReplicatorPrivate;


struct MidgardReplicator

struct MidgardReplicator {
	GObject parent;
};


MidgardReplicatorClass

typedef struct MidgardReplicatorClass MidgardReplicatorClass;


midgard_replicator_serialize ()

gchar *             midgard_replicator_serialize        (GObject *object);

object :

GObject (or derived class) instance

Returns :

serialized objects as xml content or NULL on failure.

midgard_replicator_export ()

gboolean            midgard_replicator_export           (MidgardDBObject *object);

Given object is not serialized. Its storage record is marked as exported.

see midgard_object_update() to find out possible error codes returned in case of MidgardObject failure.

object :

MidgardDBObject instance

Returns :

TRUE on success, FALSE otherwise.

midgard_replicator_export_purged ()

gchar *             midgard_replicator_export_purged    (MidgardConnection *mgd,
                                                         const gchar *classname,
                                                         const gchar *startdate,
                                                         const gchar *enddate);

Exports all purged objects of given class. If startdate or enddate are not NULL, all objects which were purged between dates will be exported.

mgd :

MidgardConnection instance

classname :

name of MidgardObjectClass derived one

startdate :

optional start date

enddate :

optional end date

Returns :

xml buffer with serialized objects or NULL if there are no objects matching given criteria.

midgard_replicator_serialize_blob ()

gchar *             midgard_replicator_serialize_blob   (MidgardObject *object);

Serialize midgard_blob binary data.

object :

MidgardObject of MIDGARD_TYPE_ATTACHMENT type

Returns :

Newly allocated xml buffer, which holds blob data base64 encoded, or NULL.

midgard_replicator_export_blob ()

gchar *             midgard_replicator_export_blob      (MidgardObject *object);

Alias for midgard_replicator_serialize_blob().

object :

MidgardObject of MIDGARD_TYPE_ATTACHMENT type

Returns :

serialized object as xml data

midgard_replicator_export_by_guid ()

gboolean            midgard_replicator_export_by_guid   (MidgardConnection *mgd,
                                                         const gchar *guid);

Marks object's storage record as exported.

Cases to return FALSE:

  • Given guid is NULL or empty string (MGD_ERR_INVALID_PROPERTY_VALUE)

  • Object identified by given guid doesn't exist (MGD_ERR_NOT_EXISTS)

  • Object identified by given guid is purged (MGD_ERR_OBJECT_PURGED)

  • Internal storage error (MGD_ERR_INTERNAL)

mgd :

MidgardConnection instance

guid :

guid which identifies object to be exported

Returns :

TRUE on success, FALSE otherwise

midgard_replicator_export_media ()

gchar *             midgard_replicator_export_media     (MidgardObject *object);


midgard_replicator_unserialize ()

GObject **          midgard_replicator_unserialize      (MidgardConnection *mgd,
                                                         const gchar *xml,
                                                         gboolean force);

mgd :

MidgardConnection instance

xml :

xml buffer which holds serialized object

force :

toggle to force unserialization

Returns :

Newly allocated array of GObjects. [transfer full]

midgard_replicator_import_object ()

gboolean            midgard_replicator_import_object    (MidgardDBObject *object,
                                                         gboolean force);

Imports given object to underlying storage

Cases to return FALSE:

  • Given guid is NULL or empty string (MGD_ERR_INVALID_PROPERTY_VALUE)

  • Object is already imported (MGD_ERR_OBJECT_IMPORTED)

  • Object identified is deleted (MGD_ERR_OBJECT_DELETED)

  • Object doesn't provide metadata one (MGD_ERR_NO_METADATA)

Set force toggle if you want to import object even if it's already imported or deleted.

object :

MidgardDBObject instance

force :

toggle to force import

Returns :

TRUE on success, FALSE otherwise

midgard_replicator_import_from_xml ()

void                midgard_replicator_import_from_xml  (MidgardConnection *mgd,
                                                         const gchar *xml,
                                                         gboolean force);

This method tries to import all objects which could be unserialized from gievn xml. It's not atomic. Check error code returned from midgard_connection_get_error().

mgd :

MidgardConnection instance

xml :

data buffer which holds serialized object

force :

toggle to force import