[rygel/wip/track-changes: 1/6] WIP: LastChange classes.



commit 91178e254c17faa49395649363884be7aa700a41
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Tue Sep 11 16:25:00 2012 +0200

    WIP: LastChange classes.

 src/librygel-server/filelist.am                    |    6 ++
 src/librygel-server/rygel-last-change-entry.vala   |   53 ++++++++++++++
 src/librygel-server/rygel-last-change-obj-add.vala |   51 +++++++++++++
 src/librygel-server/rygel-last-change-obj-del.vala |   43 +++++++++++
 src/librygel-server/rygel-last-change-obj-mod.vala |   43 +++++++++++
 src/librygel-server/rygel-last-change-st-done.vala |   34 +++++++++
 src/librygel-server/rygel-last-change.vala         |   76 ++++++++++++++++++++
 7 files changed, 306 insertions(+), 0 deletions(-)
---
diff --git a/src/librygel-server/filelist.am b/src/librygel-server/filelist.am
index 7e01d85..1ac7b1a 100644
--- a/src/librygel-server/filelist.am
+++ b/src/librygel-server/filelist.am
@@ -49,6 +49,12 @@ LIBRYGEL_SERVER_NONVAPI_SOURCE_FILES = \
 	rygel-item-destroyer.vala \
 	rygel-item-removal-queue.vala \
 	rygel-l16-transcoder.vala \
+	rygel-last-change-entry.vala \
+	rygel-last-change-obj-add.vala \
+	rygel-last-change-obj-del.vala \
+	rygel-last-change-obj-mod.vala \
+	rygel-last-change-st-done.vala \
+	rygel-last-change.vala \
 	rygel-media-query-action.vala \
 	rygel-media-receiver-registrar.vala \
 	rygel-mp2ts-transcoder.vala \
diff --git a/src/librygel-server/rygel-last-change-entry.vala b/src/librygel-server/rygel-last-change-entry.vala
new file mode 100644
index 0000000..d547761
--- /dev/null
+++ b/src/librygel-server/rygel-last-change-entry.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+// Helper class for building ContentDirectory LastChange messages
+internal abstract class Rygel.LastChangeEntry : Object {
+    private string tag;
+    private string id;
+    private uint update_id;
+
+    public LastChangeEntry (string tag, string id, uint update_id) {
+        this.tag = tag;
+        this.id = id;
+        this.update_id = update_id;
+    }
+
+    protected abstract string additional_info ();
+
+    public string to_string () {
+        var str = new StringBuilder ();
+        var info = this.additional_info ();
+
+        str.append ("  <" + this.tag + "\n" +
+                    "   objID=\"" + this.id + "\"\n" +
+                    "   updateID=\"" + this.update_id.to_string () + "\"");
+
+        if (info.length > 0) {
+            str.append ("\n" + info);
+        }
+        str.append ("/>\n");
+
+        return str.str;
+    }
+}
diff --git a/src/librygel-server/rygel-last-change-obj-add.vala b/src/librygel-server/rygel-last-change-obj-add.vala
new file mode 100644
index 0000000..c95e120
--- /dev/null
+++ b/src/librygel-server/rygel-last-change-obj-add.vala
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+internal class Rygel.LastChangeObjAdd : Rygel.LastChangeEntry {
+    private bool sub_tree_update;
+    private string parent_id;
+    private string upnp_class;
+
+    public LastChangeObjAdd (string id,
+                             uint update_id,
+                             bool sub_tree_update,
+                             string parent_id,
+                             string upnp_class) {
+        base ("objAdd", id, update_id);
+        this.sub_tree_update = sub_tree_update;
+        this.parent_id = parent_id;
+        this.upnp_class = upnp_class;
+    }
+
+    protected override string additional_info ()
+    {
+        var str = new StringBuilder ();
+        var st_update = (this.sub_tree_update ? "1" : "0");
+
+        str.append ("   stUpdate=\"" + st_update + "\"\n" +
+                    "   objParentID=\"" + this.parent_id + "\"\n" +
+                    "   objClass=\"" + this.upnp_class + "\"");
+
+        return str.str;
+    }
+}
diff --git a/src/librygel-server/rygel-last-change-obj-del.vala b/src/librygel-server/rygel-last-change-obj-del.vala
new file mode 100644
index 0000000..6598715
--- /dev/null
+++ b/src/librygel-server/rygel-last-change-obj-del.vala
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+internal class Rygel.LastChangeObjDel : Rygel.LastChangeEntry {
+    private bool sub_tree_update;
+
+    public LastChangeObjDel (string id,
+                             uint update_id,
+                             bool sub_tree_update) {
+        base ("objDel", id, update_id);
+        this.sub_tree_update = sub_tree_update;
+    }
+
+    protected override string additional_info ()
+    {
+        var str = new StringBuilder ();
+        var st_update = (this.sub_tree_update ? "1" : "0");
+
+        str.append ("   stUpdate=\"" + st_update + "\"");
+
+        return str.str;
+    }
+}
diff --git a/src/librygel-server/rygel-last-change-obj-mod.vala b/src/librygel-server/rygel-last-change-obj-mod.vala
new file mode 100644
index 0000000..80e4db6
--- /dev/null
+++ b/src/librygel-server/rygel-last-change-obj-mod.vala
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+internal class Rygel.LastChangeObjMod : Rygel.LastChangeEntry {
+    private bool sub_tree_update;
+
+    public LastChangeObjMod (string id,
+                             uint update_id,
+                             bool sub_tree_update) {
+        base ("objMod", id, update_id);
+        this.sub_tree_update = sub_tree_update;
+    }
+
+    protected override string additional_info ()
+    {
+        var str = new StringBuilder ();
+        var st_update = (this.sub_tree_update ? "1" : "0");
+
+        str.append ("   stUpdate=\"" + st_update + "\"");
+
+        return str.str;
+    }
+}
diff --git a/src/librygel-server/rygel-last-change-st-done.vala b/src/librygel-server/rygel-last-change-st-done.vala
new file mode 100644
index 0000000..e685d10
--- /dev/null
+++ b/src/librygel-server/rygel-last-change-st-done.vala
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+internal class Rygel.LastChangeStDone : Rygel.LastChangeEntry {
+    public LastChangeStDone (string id,
+                             uint update_id) {
+        base ("stDone", id, update_id);
+    }
+
+    protected override string additional_info ()
+    {
+        return "";
+    }
+}
diff --git a/src/librygel-server/rygel-last-change.vala b/src/librygel-server/rygel-last-change.vala
new file mode 100644
index 0000000..312ba3f
--- /dev/null
+++ b/src/librygel-server/rygel-last-change.vala
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+using Gee;
+
+// Helper class for building ContentDirectory LastChange messages
+internal class Rygel.LastChange : Object {
+    private const string HEADER =
+        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+        "<StateEvent\n" +
+        " xmlns=\"urn:schemas-upnp-org:av:cds-event\"\n" +
+        " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"; +
+        " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; +
+        " xsi:schemaLocation=\"\n" +
+        "   urn:schemas-upnp-org:av:cds-event\n" +
+        "   http://www.upnp.org/schemas/av/cds-events.xsd\";>\n";
+
+    private const string FOOTER = "</StateEvent>\n";
+
+    private LinkedList<LastChangeEntry> entries;
+    private StringBuilder str;
+    private bool update;
+    private bool clear_on_add;
+
+    public LastChange () {
+        this.entries = new LinkedList<LastChangeEntry> ();
+        this.str = new StringBuilder ();
+        this.update = true;
+        this.clear_on_add = false;
+    }
+
+    public void add_event (LastChangeEntry entry) {
+        if (this.clear_on_add) {
+            this.entries.clear ();
+        }
+        this.entries.add (entry);
+        this.update = true;
+    }
+
+    public void clear_on_new_event () {
+        this.clear_on_add = true;
+    }
+
+    public string get_log () {
+        if (this.update) {
+            this.str.erase ();
+
+            this.str.append (HEADER);
+            foreach (LastChangeEntry entry in this.entries) {
+                str.append (entry.to_string ());
+            }
+            this.str.append (FOOTER);
+            this.update = false;
+        }
+
+        return this.str.str;
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]