Skip to content

Commit

Permalink
Give IOQueue an error signal
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperair committed Jan 8, 2010
1 parent 6be8275 commit 1cf068b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
22 changes: 15 additions & 7 deletions src/yatta/curl/ioqueue.cc
Expand Up @@ -32,7 +32,8 @@ namespace Yatta
filename (filename),
queue (),
handle (),
loop (Glib::MainLoop::create ())
loop (Glib::MainLoop::create ()),
signal_error ()
{}

struct Item
Expand All @@ -51,11 +52,12 @@ namespace Yatta
size_t size;
};

std::string dirname;
std::string filename;
std::queue<Item> queue;
std::string dirname;
std::string filename;
std::queue<Item> queue;
Glib::RefPtr<Gio::FileOutputStream> handle;
Glib::RefPtr<Glib::MainLoop> loop;
Glib::RefPtr<Glib::MainLoop> loop;
sigc::signal<void, Gio::Error> signal_error;
};

IOQueue::IOQueue (const std::string &dirname,
Expand Down Expand Up @@ -122,14 +124,20 @@ namespace Yatta
_priv->filename = filename;
}

sigc::connection
IOQueue::connect_signal_error (sigc::slot<void, Gio::Error> slot)
{
return _priv->signal_error.connect (slot);
}

void
IOQueue::create_file_finish (Glib::RefPtr<Gio::File> file,
Glib::RefPtr<Gio::AsyncResult> &result)
{
try {
_priv->handle = file->create_file_finish (result);
} catch (Gio::Error &e) {
g_critical ("%s: %s", __PRETTY_FUNCTION__, e.what ().c_str ());
_priv->signal_error.emit (e);
}

// if perform was waiting, then start the chain
Expand All @@ -149,7 +157,7 @@ namespace Yatta
perform ();
} catch (Gio::Error &e)
{
g_critical ("%s:%s", __PRETTY_FUNCTION__, e.what ().c_str ());
_priv->signal_error.emit (e);
}
}
};
Expand Down
40 changes: 23 additions & 17 deletions src/yatta/curl/ioqueue.hh
Expand Up @@ -20,13 +20,16 @@

#include <tr1/memory>
#include <string>

#include <sigc++/slot.h>
#include <glibmm/refptr.h>

// some forward decls
namespace Gio
{
class File;
class AsyncResult;
class Error;
};

namespace Yatta
Expand All @@ -35,23 +38,26 @@ namespace Yatta
{
class IOQueue
{
public:
IOQueue (const std::string &dirname,
const std::string &filename = "");
void write (size_t offset, void *data, size_t size);
void perform ();
void filename (const std::string &filename);
virtual ~IOQueue ();

protected:
void create_file_finish
(Glib::RefPtr<Gio::File> gfile,
Glib::RefPtr<Gio::AsyncResult> &result);
void perform_finish (Glib::RefPtr<Gio::AsyncResult> &result);

private:
struct Private;
std::tr1::shared_ptr<Private> _priv;
public:
IOQueue (const std::string &dirname,
const std::string &filename = "");
virtual ~IOQueue ();

void write (size_t offset, void *data, size_t size);
void perform ();
void filename (const std::string &filename);

sigc::connection
connect_signal_error (sigc::slot<void, Gio::Error> slot);

protected:
void create_file_finish (Glib::RefPtr<Gio::File> gfile,
Glib::RefPtr<Gio::AsyncResult> &result);
void perform_finish (Glib::RefPtr<Gio::AsyncResult> &result);

private:
struct Private;
std::tr1::shared_ptr<Private> _priv;
};
};
};
Expand Down

0 comments on commit 1cf068b

Please sign in to comment.