[gxml] GomDocument: added async methods



commit bafcf63a93c66890c27cab54203cc4f3ae10b25e
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Jul 10 23:11:36 2017 -0500

    GomDocument: added async methods

 gxml/GomDocument.vala |   43 +++++++++++++++++++++++++++++++++++++++++++
 gxml/GomElement.vala  |   26 ++++++++++++++++++++++++++
 gxml/Parser.vala      |   10 ++++++++++
 3 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index 581995e..5581917 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -119,6 +119,13 @@ public class GXml.GomDocument : GomNode,
     parser.write_file (file, null);
   }
   /**
+   * Writes asynchronically a dump XML representation of document to a file.
+   */
+  public async void write_file_async (GLib.File file) throws GLib.Error {
+    var parser = new XParser (this);
+    yield parser.write_file_async (file, null);
+  }
+  /**
    * Writes a dump XML representation of document to a stream.
    */
   public void write_stream (GLib.OutputStream stream) throws GLib.Error {
@@ -126,6 +133,13 @@ public class GXml.GomDocument : GomNode,
     parser.write_stream (stream, null);
   }
   /**
+   * Writes a dump XML representation of document to a stream.
+   */
+  public async void write_stream_async (GLib.OutputStream stream) throws GLib.Error {
+    var parser = new XParser (this);
+    parser.write_stream (stream, null);
+  }
+  /**
    * Creates an {@link GLib.InputStream} to write a string representation
    * in XML of {@link GomDocument}
    */
@@ -134,6 +148,14 @@ public class GXml.GomDocument : GomNode,
     return parser.create_stream (null);
   }
   /**
+   * Creates an {@link GLib.InputStream} to write a string representation
+   * in XML of {@link GomDocument}
+   */
+  public async InputStream create_stream_async () throws GLib.Error {
+    var parser = new XParser (this);
+    return yield parser.create_stream_async (null);
+  }
+  /**
    * Serialize {@link GomDocument} to a string.
    */
   public string write_string () throws GLib.Error {
@@ -141,6 +163,13 @@ public class GXml.GomDocument : GomNode,
     return parser.write_string ();
   }
   /**
+   * Serialize {@link GomDocument} to a string.
+   */
+  public async string write_string_async () throws GLib.Error {
+    var parser = new XParser (this);
+    return yield parser.write_string_async ();
+  }
+  /**
    * Reads a file contents and parse it to document.
    */
   public void read_from_file (GLib.File file) throws GLib.Error {
@@ -148,12 +177,26 @@ public class GXml.GomDocument : GomNode,
     parser.read_file (file, null);
   }
   /**
+   * Reads a file contents and parse it to document.
+   */
+  public async void read_from_file_async (GLib.File file) throws GLib.Error {
+    var parser = new XParser (this);
+    yield parser.read_file_async (file, null);
+  }
+  /**
    * Reads a string and parse it to document.
    */
   public void read_from_string (string str) throws GLib.Error {
     var parser = new XParser (this);
     parser.read_string (str, null);
   }
+  /**
+   * Reads a string and parse it to document.
+   */
+  public async void read_from_string_async (string str) throws GLib.Error {
+    var parser = new XParser (this);
+    yield parser.read_string_async (str, null);
+  }
 
   public DomElement create_element (string local_name) throws GLib.Error {
     var e = new GomElement ();
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index 6a64113..959ca79 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -114,24 +114,50 @@ public class GXml.GomElement : GomNode,
     return parser.write_string ();
   }
   /**
+   * Serialize asinchronically {@link GomElement} to a string.
+   */
+  public async string write_string_async () throws GLib.Error {
+    var parser = new XParser (this);
+    return yield parser.write_string_async ();
+  }
+  /**
    * Uses element's {@link GomDocument} to write an XML to a file, serializing it.
    */
   public void write_file (GLib.File f) throws GLib.Error {
     (this.owner_document as GomDocument).write_file (f);
   }
   /**
+   * Uses element's {@link GomDocument} to write asynchronically an XML to a file, serializing it.
+   */
+  public async void write_file_async (GLib.File f) throws GLib.Error {
+    yield (this.owner_document as GomDocument).write_file_async (f);
+  }
+  /**
    * Uses element's {@link GomDocument} to write an XML to a stream, serializing it.
    */
   public void write_stream (GLib.OutputStream stream) throws GLib.Error {
     (this.owner_document as GomDocument).write_stream (stream);
   }
   /**
+   * Uses element's {@link GomDocument} to write an XML to a stream, serializing it.
+   */
+  public async void write_stream_async (GLib.OutputStream stream) throws GLib.Error {
+    yield (this.owner_document as GomDocument).write_stream_async (stream);
+  }
+  /**
    * Creates an {@link GLib.InputStream} to write a string representation
    * in XML of {@link GomElement} using node's {@link GomDocument}
    */
   public InputStream create_stream () throws GLib.Error {
     return (this.owner_document as GomDocument).create_stream ();
   }
+  /**
+   * Creates an {@link GLib.InputStream} to write a string representation
+   * in XML of {@link GomElement} using node's {@link GomDocument}
+   */
+  public async InputStream create_stream_async () throws GLib.Error {
+    return yield (this.owner_document as GomDocument).create_stream_async ();
+  }
   // DomNode overrides
   public new string? lookup_prefix (string? nspace) {
     if (_namespace_uri == nspace)
diff --git a/gxml/Parser.vala b/gxml/Parser.vala
index 089d250..4c0db3c 100644
--- a/gxml/Parser.vala
+++ b/gxml/Parser.vala
@@ -57,6 +57,16 @@ public interface GXml.Parser : Object {
     write_stream (ostream, cancellable);
   }
   /**
+   * Writes a {@link GXml.DomDocument} to a {@link GLib.File}
+   */
+  public virtual async void write_file_async (GLib.File file,
+                            GLib.Cancellable? cancellable)
+                            throws GLib.Error {
+    var ostream = file.replace (null, backup,
+                            GLib.FileCreateFlags.NONE, cancellable);
+    yield write_stream_async (ostream, cancellable);
+  }
+  /**
    * Writes a {@link node} to a string
    */
   public abstract string write_string () throws GLib.Error;


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