2012-08-20

[GNOME] GXml 0.3.0

update: thanks to Marcus Lundblad for pointing out issues with the examples

 

The Google Summer of Code 2012 now comes to a close, so to celebrate, GXml 0.3.0 has been tagged with GObject Serialization as its big feature.



The last few days have had been trying to find a clever way to reliably identify some types of collections, but that's not finished, so they're not being automatically serialized in this release.



I've also bravely fought against autotools to try to figure out how to minimise the number of places where I have to update a version number.  Too much of autotools remain a mystery to me, sadly, but I think I got it?  It works for me: hopefully someone will file a bug if something doesn't work for them.



Summary


  • Serialization class


    • that can automatically handle many types

    • that can deserialise to types known on the local system and distinguish multiple references to the same object.  I have some future plans to remove redundant XML that gets generated, too.


  • Serializable interface


    • allows classes to override default serialization and serialize non-public properties too.  Yay!

    • follows json-glib so that a common serialization interface can be defined in the future


  • Documentation


    • successfully got Valadoc to generate GtkDoc (and fixed a lot of documentation in GXml from before)


  • Testing


    • created test suites for serialization features


  • API breakage


    • namespaces were changed, in part to reduce the amount of code C programmers have to write.



Vala Example



Automatic serialization


GXml.DomNode xml = GXml.Serialization.serialize_object (banana);
...
banana = GXml.Serialization.deserialize_object (xml);



Implementing the interface: overriding how a property is serialized


public class Banana : GLib.Object, GXml.Serializable {
public int weight { get; set; }

public GXml.DomNode? serialize_property (string prop_name, GLib.ParamSpec spec,
GXml.Document doc) {
switch (prop_name) {
case "weight":
return doc.create_text_node ("%d".printf (weight * 1000));
default:
return null;
}
}

public bool deserialize_property (string prop_name, GLib.ParamSpec spec,
GXml.DomNode prop_node) {
GLib.Value outvalue = GLib.Value (typeof (int));

switch (prop_name) {
case "weight":
int64.try_parse (((GXml.Element)prop_node).content, out outvalue);
this.weight = (int)outvalue.get_int64 () / 1000;
return true;
default:
return false;
}
}
}



Implementing the interface: override view of properties


using GXml;

public class Plantain : GLib.Object, GXml.Serializable {
private int weight { get; set; }

private ParamSpec[] _props = null;
public unowned ParamSpec[] list_properties () {
if (this._props == null) {
this._props = new ParamSpec[1];
this._props[0] = new ParamSpecInt ("weight", "weight", "weight",
0, 200, 0, ParamFlags.READABLE);
}
return this._props;
}

private ParamSpec prop;
public unowned ParamSpec? find_property (string prop_name) {
ParamSpec[] props = this.list_properties ();
foreach (ParamSpec prop in props) {
if (prop.name == prop_name) {
this.prop = prop;
return this.prop;
}
}
return null;
}

public new void get_property (ParamSpec spec, ref Value str_value) {
Value value = Value (typeof (int));

if (spec.name == "weight")
value.set_int (this.weight);
else {
((GLib.Object)this).get_property (spec.name, ref str_value);
return;
}


value.transform (ref str_value);
return;
}

public new void set_property (ParamSpec spec, Value value) {
if (spec.name == "weight")
this.weight = value.get_int ();
else {
((GLib.Object)this).set_property (spec.name, value);
}
}
}

 

... 

Challenges



These are the greatest challenges I've dealt with



  • my masters: there's a lot of pressure to hurry up and finish; ideally, a GSOC should be the sole or primary focus of my summer, but I don't have much opportunity to take a summer off right now.  Going to GUADEC was amazing, but consequently made my masters a bigger part of these past two weeks.

  • autotools: a lot of feedback centred on people wanting autotools instead of WAF, so now you have and now I cry myself to sleep at night.  I just need to make it a bigger part of my life.

  • valadoc: I was having issues getting valadoc to correctly generate GtkDoc last year and this year until Philip Withnall directed me to libfolks.


Future


  • want to support automatic serialization of more complex types; I've been working on collections but there are problems with it that prevent me from committing it.

  • two projects approached me at GUADEC suggesting GXml for saving data to disk, so I am going to write patches for them. :D

  • examples in other languages


Download tar ball: http://ftp.gnome.org/pub/GNOME/sources/gxml/0.3/

Keine Kommentare:

Kommentar veröffentlichen

Blog Archive

Dieses Blog durchsuchen

Labels

#Technology #GNOME gnome gxml fedora bugs linux vala google #General firefox security gsoc GUADEC android bug xml fedora 18 javascript libxml2 programming web blogger encryption fedora 17 gdom git emacs libgdata memory mozilla open source serialisation upgrade web development API Spain containers design evolution fedora 16 fedora 20 fedora 22 fedup file systems friends future glib gnome shell internet luks music performance phone photos php podman preupgrade tablet testing typescript yum #Microblog Network Manager adb apache art automation bash brno catastrophe css data loss debian debugging deja-dup disaster docker emusic errors ext4 facebook fedora 19 gee gir gitlab gitorious gmail gobject google talk google+ gtk html libxml mail microsoft mtp mysql namespaces nautilus nextcloud owncloud picasaweb pitivi ptp python raspberry pi resizing rpm school selinux signal sms speech dispatcher systemd technology texting time management uoguelph usability video web design youtube #Tech Air Canada C Electron Element Empathy Europe GError GNOME 3 GNOME Files Go Google Play Music Grimes IRC Mac OS X Mario Kart Memento Nintendo Nintendo Switch PEAP Selenium Splatoon UI VPN Xiki accessibility advertising ai albums anaconda anonymity apple ask asus eee top automake autonomous automobiles b43 backup battery berlin bit rot broadcom browsers browsing canada canadian english cars chrome clarity comments communication compiler complaints computer computers configuration console constructive criticism cron cropping customisation dataloss dconf debug symbols design patterns desktop summit development discoverability distribution diy dnf documentation drm duplicity e-mail efficiency email english environment estate experimenting ext3 fedora 11 festival file formats firejail flac flatpak forgottotagit freedom friendship fuse galaxy nexus galton gay rights gdb german germany gimp gio gjs gnome software gnome-control-center google assistant google calendar google chrome google hangouts google reader gqe graphviz growth gtest gtg gvfs gvfs metadata hard drive hard drives hardware help hp humour ide identity instagram installation instant messaging integration intel interactivity introspection jabber java java 13 jobs kernel keyboard language language servers languages law learning lenovo letsencrypt libreoffice librpm life livecd liveusb login lsp macbook maintainership mariadb mario matrix memory leaks messaging mounting mouse netflix new zealand node nodelist numix obama oci ogg oggenc oh the humanity open open standards openoffice optimisation org-mode organisation package management packagekit paint shedding parallelism pdo perl pipelight privacy productivity progress progressive web apps pumpkin pwa pyright quality recursion redhat refactoring repairs report rhythmbox rust sandboxes scheduling screenshots self-navigating car shell sleep smartphones software software engineering speed sql ssd synergy tabs test tests themes thesis tracker travel triumf turtles tv tweak twist typing university update usb user experience valadoc video editing volunteering vpnc waf warm wayland weather web apps website wifi wiki wireless wishes work xinput xmpp xorg xpath
Powered by Blogger.