2 * Copyright (C) 2008 OpenedHand Ltd.
3 * Copyright (C) 2009 Nokia Corporation.
5 * Author: Jorn Baayen <jorn@openedhand.com>
6 * Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
7 * <zeeshan.ali@nokia.com>
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 // Helper class for building LastChange messages
28 public class Rygel.ChangeLog : Object {
29 public unowned Service service { get; set; }
31 private string service_ns;
33 private StringBuilder str;
35 private HashMap<string, string> hash;
37 private uint timeout_id = 0;
39 public ChangeLog (Service? service, string service_ns) {
40 this.service = service;
41 this.service_ns = service_ns;
42 this.str = new StringBuilder ();
43 this.hash = new HashMap<string, string> ();
47 if (this.timeout_id != 0) {
48 Source.remove (this.timeout_id);
52 private bool timeout () {
54 this.service.notify ("LastChange", typeof (string), this.finish ());
55 debug ("LastChange sent");
59 this.str.erase (0, -1);
65 private void ensure_timeout () {
66 // Make sure we have a notification timeout
67 if (this.service != null && this.timeout_id == 0) {
68 debug (_("Setting up timeout for LastChange"));
69 this.timeout_id = Timeout.add (200, this.timeout);
73 public void log (string variable, string value) {
74 debug (@"'%s = %s' logged", variable, value);
75 this.hash.set (variable, "<%s val=\"%s\"/>".printf (variable, value));
77 this.ensure_timeout ();
80 public void log_with_channel (string variable,
83 this.hash.set (variable,
84 "<%s val=\"%s\" channel=\"%s\"/>".printf (variable,
88 this.ensure_timeout ();
91 public string finish () {
92 this.str.append ("<Event xmlns=\"" +
94 "\"><InstanceID val=\"0\">");
95 foreach (string line in this.hash.values) {
96 this.str.append (line);
98 this.str.append ("</InstanceID></Event>");