00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <config.h>
00020 #include <glib.h>
00021 #include <glib-object.h>
00022 #include "midgard/types.h"
00023 #include "midgard/midgard_legacy.h"
00024
00025 gchar * midgard_object_serialize(MgdObject *mobj)
00026 {
00027
00028 GParamSpec **pspec;
00029 guint propn, i;
00030 GString *so;
00031 GValue pval = {0,};
00032 gchar *rso;
00033 const gchar *pcchar;
00034
00035
00036 if ((pspec = g_object_class_list_properties((GObjectClass *) mobj->klass, &propn)) == NULL )
00037 return NULL;
00038
00039 so = g_string_new("<type name=");
00040 g_string_append_printf(so, "\"%s\">\n", mobj->cname);
00041
00042 for (i = 0; i < propn; i++) {
00043
00044 g_value_init(&pval,pspec[i]->value_type);
00045
00046 g_string_append(so, "\t<property name=");
00047 g_string_append_printf(so, "\"%s\"", pspec[i]->name);
00048 g_string_append(so, " value=");
00049
00050 switch (pspec[i]->value_type) {
00051
00052 case G_TYPE_STRING:
00053
00054 if ((pcchar = g_strdup(g_value_get_string(&pval))) == NULL )
00055 pcchar = "";
00056 g_string_append_printf(so, "\"%s\"/>\n", pcchar);
00057 break;
00058
00059 case G_TYPE_UINT:
00060
00061 g_string_append_printf(so, "\"%d\"/>\n", g_value_get_uint(&pval));
00062 break;
00063
00064 }
00065
00066 g_value_unset(&pval);
00067
00068 }
00069
00070 g_string_append(so, "</type>\n");
00071
00072 rso = g_string_free(so, FALSE);
00073
00074 return rso;
00075 }
00076