[glibmm] File: Added create_file_readwrite() and creat_file_readwrite_async().



commit b95b7b023c1f14da32ffe50ba4e096b7cc4160f5
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Jan 28 13:06:03 2010 +0100

    File: Added create_file_readwrite() and creat_file_readwrite_async().
    
    * gio/src/file.[hg|ccg]: Added create_file_readwrite(),
    create_file_readwrite_async() and create_file_readwrite_finish().

 ChangeLog        |   11 ++++-
 gio/src/file.ccg |   71 +++++++++++++++++++++++++++++++++
 gio/src/file.hg  |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 189 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5f78d25..4bd9920 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
-2010-01-28  Murray Cumming  <murrayc murraycv>
+2010-01-28  Murray Cumming  <murrayc murrayc com>
+
+	File: Added create_file_readwrite() and creat_file_readwrite_async().
+
+	* gio/src/file.[hg|ccg]: Added create_file_readwrite(), 
+	create_file_readwrite_async() and create_file_readwrite_finish().
+
+2010-01-28  Murray Cumming  <murrayc murrayc com>
 
-	unmount_mountable(), eject_mountable(): Add overrides with MountOperation.
+	File: unmount_mountable(), eject_mountable(): Add overrides with MountOperation.
 
 	* gio/src/file.[hg|ccg]: unmount_mountable(), eject_mountable(): 
 	Reimplement these with the new *_with_operation functions.
diff --git a/gio/src/file.ccg b/gio/src/file.ccg
index bede099..48187ab 100644
--- a/gio/src/file.ccg
+++ b/gio/src/file.ccg
@@ -235,6 +235,39 @@ File::create_file_async(const SlotAsyncReady& slot, FileCreateFlags flags, int i
 }
 
 void
+File::create_file_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags, int io_priority)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_file_create_async(gobj(),
+                      static_cast<GFileCreateFlags>(flags),
+                      io_priority,
+                      cancellable->gobj(),
+                      &SignalProxy_async_callback,
+                      slot_copy);
+}
+
+void
+File::create_file_readwrite_async(const SlotAsyncReady& slot, FileCreateFlags flags, int io_priority)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_file_create_readwrite_async(gobj(),
+                      static_cast<GFileCreateFlags>(flags),
+                      io_priority,
+                      NULL, // cancellable
+                      &SignalProxy_async_callback,
+                      slot_copy);
+}
+
+
+void
 File::replace_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, const std::string& etag, bool make_backup, FileCreateFlags flags, int io_priority)
 {
   // Create a copy of the slot.
@@ -2044,6 +2077,44 @@ Glib::RefPtr<FileOutputStream> File::create_file(FileCreateFlags flags, std::aut
 }
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<FileIOStream> File::create_file_readwrite(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags)
+#else
+Glib::RefPtr<FileIOStream> File::create_file_readwrite(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  Glib::RefPtr<FileIOStream> retvalue = Glib::wrap(g_file_create_readwrite(gobj(), ((GFileCreateFlags)(flags)), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror)));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<FileIOStream> File::create_file_readwrite(FileCreateFlags flags)
+#else
+Glib::RefPtr<FileIOStream> File::create_file_readwrite(FileCreateFlags flags, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  Glib::RefPtr<FileIOStream> retvalue = Glib::wrap(g_file_create_readwrite(gobj(), ((GFileCreateFlags)(flags)), NULL, &(gerror)));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
 bool File::remove()
 #else
 bool File::remove(std::auto_ptr<Glib::Error>& error)
diff --git a/gio/src/file.hg b/gio/src/file.hg
index 93a4504..6dfa16d 100644
--- a/gio/src/file.hg
+++ b/gio/src/file.hg
@@ -269,11 +269,11 @@ public:
 #endif //GLIBMM_EXCEPTIONS_ENABLED
   _IGNORE(g_file_append_to)
 
-  //We renamed this to create_file from (g_file_create()), to avoid confusion with static create() methods, 
+  //We renamed this to create_file from (g_file_create() and g_file_create_readwrite), to avoid confusion with static create() methods, 
   //but I would still like to choose a different word, but can't think of a good one. murrayc.
 
   /** Creates a new file and returns an output stream for writing to it.
-   * The file must not already exists.
+   * The file must not already exist.
    * 
    * By default files created are generally readable by everyone,
    * but if you pass FILE_CREATE_PRIVATE in @a flags the file
@@ -304,7 +304,7 @@ public:
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 
   /** Creates a new file and returns an output stream for writing to it.
-   * The file must not already exists.
+   * The file must not already exist.
    * 
    * By default files created are generally readable by everyone,
    * but if you pass FILE_CREATE_PRIVATE in @a flags the file
@@ -331,6 +331,74 @@ public:
 #endif //GLIBMM_EXCEPTIONS_ENABLED
   _IGNORE(g_file_create)
 
+  /** Creates a new file and returns a stream for reading and writing to it.
+   * The file must not already exist.
+   * 
+   * By default files created are generally readable by everyone,
+   * but if you pass FILE_CREATE_PRIVATE in @a flags the file
+   * will be made readable only to the current user, to the level that
+   * is supported on the target filesystem.
+   * 
+   * The operation can be cancelled by triggering the cancellable object from another thread. 
+   * If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.
+   * 
+   * If a file with this name already exists a Gio::Error with EXISTS 
+   * will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY
+   * will be thrown.
+   *
+   * Some filesystems don't allow all filenames, and may
+   * throw a Gio::Error with INVALID_FILENAME, and if the name
+   * is to longa Gio::Error with FILENAME_TOO_LONG will be thrown.
+   * Other errors are possible too, and depend on what kind of
+   * filesystem the file is on.
+   *
+   * Note that in many non-local file cases read and write streams are not
+   * supported, so make sure you really need to do read and write streaming,
+   * rather than just opening for reading or writing.
+   *
+   * @param cancellable A Cancellable object which can be used to cancel the operation.
+   * @param flags a set of FileCreateFlags.
+   * @return A FileOutputStream for the newly created file.
+   */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  Glib::RefPtr<FileIOStream> create_file_readwrite(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags = FILE_CREATE_NONE);
+#else
+  Glib::RefPtr<FileIOStream> create_file_readwrite(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  /** Creates a new file and returns a stream for reading and writing to it.
+   * The file must not already exist.
+   * 
+   * By default files created are generally readable by everyone,
+   * but if you pass FILE_CREATE_PRIVATE in @a flags the file
+   * will be made readable only to the current user, to the level that
+   * is supported on the target filesystem.
+   * 
+   * If a file with this name already exists a Gio::Error with EXISTS 
+   * will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY
+   * will be thrown.
+   *
+   * Some filesystems don't allow all filenames, and may
+   * throw a Gio::Error with INVALID_FILENAME, and if the name
+   * is to longa Gio::Error with FILENAME_TOO_LONG will be thrown.
+   * Other errors are possible too, and depend on what kind of
+   * filesystem the file is on.
+   *
+   * Note that in many non-local file cases read and write streams are not
+   * supported, so make sure you really need to do read and write streaming,
+   * rather than just opening for reading or writing.
+   *
+   * @param flags a set of FileCreateFlags.
+   * @return A FileOutputStream for the newly created file.
+   */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  Glib::RefPtr<FileIOStream> create_file_readwrite(FileCreateFlags flags = FILE_CREATE_NONE);
+#else
+  Glib::RefPtr<FileIOStream> create_file_readwrite(FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+  _IGNORE(g_file_create)
+
+
 
   /** Returns an output stream for overwriting the file, possibly creating a backup copy of the file first.
    * This will try to replace the file in the safest way possible so that any errors during the writing will 
@@ -438,7 +506,7 @@ public:
                refreturn, errthrow)
 
 
-  //We renamed this to create_file_async from (g_file_create_async()), to avoid confusion with static create() methods, 
+  //We renamed this to create_file_async from (g_file_create_async() and g_file_create_readwrite_async), to avoid confusion with static create() methods, 
   //but I would still like to choose a different word, but can't think of a good one. murrayc. See also create_file().
 
   /** Asynchronously creates a new file and returns an output stream for writing to it. The file must not already exist.
@@ -446,10 +514,10 @@ public:
    *
    * When the operation is finished, @a slot will be called. You can then call create_file_finish() to get the result of the operation.
    * 
+   * @param slot A callback slot which will be called when the request is satisfied.
+   * @param cancellable A Cancellable object which can be used to cancel the operation.
    * @param flags a set of FileCreateFlags.
    * @param io_priority The I/O priority of the request.
-   * @param cancellable A Cancellable object which can be used to cancel the operation.
-   * @param slot A callback slot which will be called when the request is satisfied.
    */
   void create_file_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
 
@@ -458,9 +526,9 @@ public:
    *
    * When the operation is finished, @a slot will be called. You can then call create_file_finish() to get the result of the operation.
    * 
+   * @param slot A callback slot which will be called when the request is satisfied.
    * @param flags a set of FileCreateFlags.
    * @param io_priority The I/O priority of the request.
-   * @param slot A callback slot which will be called when the request is satisfied.
    */
   void create_file_async(const SlotAsyncReady& slot, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
   _IGNORE(g_file_create_async)
@@ -469,6 +537,40 @@ public:
                g_file_create_finish,
                refreturn, errthrow)
 
+
+  /** Asynchronously creates a new file and returns a stream for reading and
+   * writing to it. The file must not already exist.
+   *
+   * For more details, see create_file_readwrite() which is the synchronous version of this call.
+   *
+   * When the operation is finished, @a slot will be called. You can then call create_file_readwrite_finish() to get the result of the operation.
+   * 
+   * @param slot A callback slot which will be called when the request is satisfied.
+   * @param cancellable A Cancellable object which can be used to cancel the operation.
+   * @param flags a set of FileCreateFlags.
+   * @param io_priority The I/O priority of the request.
+   */
+  void create_file_readwrite_async(const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
+
+  /** Asynchronously creates a new file and returns a stream for reading and
+   * writing to it. The file must not already exist.
+   *
+   * For more details, see create_file_readwrite() which is the synchronous version of this call.
+   *
+   * When the operation is finished, @a slot will be called. You can then call create_file_readwrite_finish() to get the result of the operation.
+   * 
+   * @param slot A callback slot which will be called when the request is satisfied.
+   * @param flags a set of FileCreateFlags.
+   * @param io_priority The I/O priority of the request.
+   */
+  void create_file_readwrite_async(const SlotAsyncReady& slot, FileCreateFlags flags = FILE_CREATE_NONE, int io_priority = Glib::PRIORITY_DEFAULT);
+  _IGNORE(g_file_create_readwrite_async)
+
+  _WRAP_METHOD(Glib::RefPtr<FileIOStream> create_file_readwrite_finish(const Glib::RefPtr<AsyncResult>& result),
+               g_file_create_readwrite_finish,
+               refreturn, errthrow)
+
+
   /** Asyncronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.
    * For more details, see replace() which is the synchronous version of this call.
    * When the operation is finished, @a slot will be called. You can then call replace_finish() to get the result of the operation.



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