Author: toshok
Date: 2007-06-14 13:25:58 -0400 (Thu, 14 Jun 2007)
New Revision: 79580
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/demo.cpp
trunk/moon/src/runtime.cpp
trunk/moon/src/runtime.h
trunk/moon/src/type.cpp
trunk/moon/src/value.cpp
trunk/moon/src/value.h
Log:
2007-06-14 Chris Toshok <[EMAIL PROTECTED]>
* runtime.h, runtime.cpp: remove the hack UnmanagedDownloader from
here, and made Downloader pluggable with a set of functions.
* demo.cpp: use the pluggable nature of Downloader to put
UnmanagedDownloader here (and call it FileDownloadState).
* value.cpp, value.h, type.cpp: resync.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/ChangeLog 2007-06-14 17:25:58 UTC (rev 79580)
@@ -1,3 +1,13 @@
+2007-06-14 Chris Toshok <[EMAIL PROTECTED]>
+
+ * runtime.h, runtime.cpp: remove the hack UnmanagedDownloader from
+ here, and made Downloader pluggable with a set of functions.
+
+ * demo.cpp: use the pluggable nature of Downloader to put
+ UnmanagedDownloader here (and call it FileDownloadState).
+
+ * value.cpp, value.h, type.cpp: resync.
+
2007-06-14 Jeffrey Stedfast <[EMAIL PROTECTED]>
* text.cpp: Fixed Brush accessors for the NULL case.
Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/demo.cpp 2007-06-14 17:25:58 UTC (rev 79580)
@@ -6,6 +6,7 @@
#include <glib.h>
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include <sys/time.h>
#include "runtime.h"
#include "transform.h"
@@ -114,6 +115,14 @@
// sb->Seek ((TimeSpan)e->x * 100000);
}
+static gpointer downloader_create_state (Downloader* dl);
+static void downloader_destroy_state (gpointer data);
+static void downloader_open (char *verb, char *uri, bool async, gpointer
state);
+static void downloader_send (gpointer state);
+static void downloader_abort (gpointer state);
+static void downloader_abort (gpointer state);
+static char* downloader_get_response_text (char *part, gpointer state);
+
int
main (int argc, char *argv [])
{
@@ -127,6 +136,13 @@
gdk_threads_init ();
runtime_init ();
+ downloader_set_functions (downloader_create_state,
+ downloader_destroy_state,
+ downloader_open,
+ downloader_send,
+ downloader_abort,
+ downloader_get_response_text);
+
w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (w), "delete_event", G_CALLBACK
(delete_event), NULL);
Surface *t = surface_new (600, 600);
@@ -211,7 +227,7 @@
panel_child_add (canvas, r);
- UnmanagedDownloader *dl = new UnmanagedDownloader ();
+ Downloader *dl = new Downloader ();
Image *i = image_new ();
i->SetSource (dl, "/tmp/mono.png");
i->SetValue (Canvas::LeftProperty, Value (100.0));
@@ -383,3 +399,96 @@
gtk_widget_show_all (w);
gtk_main ();
}
+
+
+
+
+class FileDownloadState {
+ public:
+ FileDownloadState (Downloader *dl) : downloader(dl), fd (-1),
async_idle (-1) { }
+
+ virtual ~FileDownloadState () { Close (); }
+
+ void Abort () { Close (); }
+ char* GetResponseText (char* PartName) { return NULL; } // XXX
+ void Open (char *verb, char *uri, bool async)
+ {
+ fd = open (uri, O_RDONLY);
+ if (fd == -1) {
+ printf ("failed open\n");
+ return;
+ }
+
+ if (async)
+ async_idle = g_idle_add (async_fill_buffer, this);
+ }
+
+ void Send () { }
+
+ void Close ()
+ {
+ if (fd != -1) {
+ close (fd);
+ fd = -1;
+ }
+ if (async_idle != -1) {
+ g_source_remove (async_idle);
+ async_idle = -1;
+ }
+ }
+ private:
+ int fd;
+ int async_idle;
+ Downloader *downloader;
+
+ gboolean AsyncFillBuffer ()
+ {
+ guchar buf[1024];
+
+ int n = read (fd, buf, sizeof (buf));
+
+ downloader->Write (buf, n);
+ }
+
+ static gboolean async_fill_buffer (gpointer cb_data)
+ {
+ return ((FileDownloadState*)cb_data)->AsyncFillBuffer ();
+ }
+};
+
+static gpointer
+downloader_create_state (Downloader *dl)
+{
+ return new FileDownloadState (dl);
+}
+
+static void
+downloader_destroy_state (gpointer data)
+{
+ delete ((FileDownloadState*)data);
+}
+
+static void
+downloader_open (char *verb, char *uri, bool async, gpointer state)
+{
+ ((FileDownloadState*)state)->Open (verb, uri, async);
+}
+
+static void
+downloader_send (gpointer state)
+{
+ ((FileDownloadState*)state)->Send ();
+}
+
+static void
+downloader_abort (gpointer state)
+{
+ ((FileDownloadState*)state)->Abort ();
+}
+
+static char*
+downloader_get_response_text (char *part, gpointer state)
+{
+ return ((FileDownloadState*)state)->GetResponseText (part);
+}
+
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/runtime.cpp 2007-06-14 17:25:58 UTC (rev 79580)
@@ -15,8 +15,6 @@
#include <malloc.h>
#include <glib.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#define Visual _XVisual
#include <gdk/gdkx.h>
#if AGG
@@ -2034,102 +2032,99 @@
// Downloader
//
+downloader_create_state_func Downloader::create_state;
+downloader_destroy_state_func Downloader::destroy_state;
+downloader_open_func Downloader::open;
+downloader_send_func Downloader::send;
+downloader_abort_func Downloader::abort;
+downloader_get_response_text_func Downloader::get_response_text;
+
+Downloader::Downloader ()
+{
+ downloader_state = Downloader::create_state (this);
+}
+
+Downloader::~Downloader ()
+{
+ Downloader::destroy_state (downloader_state);
+}
+
void
Downloader::Abort ()
{
+ Downloader::abort (downloader_state);
}
char*
Downloader::GetResponseText (char* PartName)
{
- return NULL;
+ return Downloader::get_response_text (PartName, downloader_state);
}
void
Downloader::Open (char *verb, char *URI, bool Async)
{
+ Downloader::open (verb, URI, Async, downloader_state);
}
void
Downloader::Send ()
{
+ Downloader::send (downloader_state);
}
void
-Downloader::SetWriteFunc (downloader_write_func write,
- gpointer data)
+Downloader::Write (guchar *buf, gsize n)
{
- this->write = write;
- this->write_data = data;
-}
-
-//
-// UnmanagedDownloader hack
-//
-
-
-UnmanagedDownloader::UnmanagedDownloader ()
- : fd (-1),
- async_idle (-1)
-{
-}
-
-UnmanagedDownloader::~UnmanagedDownloader ()
-{
- Close ();
-}
-
-gboolean
-UnmanagedDownloader::async_fill_buffer (gpointer cb_data)
-{
- return ((UnmanagedDownloader*)cb_data)->AsyncFillBuffer ();
-}
-
-gboolean
-UnmanagedDownloader::AsyncFillBuffer ()
-{
- guchar buf[1024];
-
- int n = read (fd, buf, sizeof (buf));
-
this->write (buf, n, write_data);
}
void
-UnmanagedDownloader::Open (char *verb, char *uri, bool async)
+Downloader::SetWriteFunc (downloader_write_func write,
+ gpointer data)
{
- fd = open (uri, O_RDONLY);
- if (fd == -1) {
- printf ("failed open\n");
- return;
- }
-
- if (async)
- async_idle = g_idle_add (async_fill_buffer, this);
+ this->write = write;
+ this->write_data = data;
}
void
-UnmanagedDownloader::Send ()
+Downloader::SetFunctions (downloader_create_state_func create_state,
+ downloader_destroy_state_func destroy_state,
+ downloader_open_func open,
+ downloader_send_func send,
+ downloader_abort_func abort,
+ downloader_get_response_text_func get_response)
{
+ Downloader::create_state = create_state;
+ Downloader::destroy_state = destroy_state;
+ Downloader::open = open;
+ Downloader::send = send;
+ Downloader::abort = abort;
+ Downloader::get_response_text = get_response;
}
-void
-UnmanagedDownloader::Abort ()
+Downloader*
+downloader_new ()
{
- Close ();
+ return new Downloader ();
}
-void
-UnmanagedDownloader::Close ()
+void downloader_set_functions (downloader_create_state_func create_state,
+ downloader_destroy_state_func destroy_state,
+ downloader_open_func open,
+ downloader_send_func send,
+ downloader_abort_func abort,
+ downloader_get_response_text_func get_response)
{
- if (fd != -1)
- close (fd);
- if (async_idle != -1)
- g_source_remove (async_idle);
+ Downloader::SetFunctions (create_state,
+ destroy_state,
+ open,
+ send,
+ abort,
+ get_response);
}
-
//
// UIElement
//
@@ -2228,12 +2223,6 @@
}
-Downloader*
-downloader_new ()
-{
- return new Downloader ();
-}
-
Type* Type::types [];
GHashTable* Type::types_by_name = NULL;
Modified: trunk/moon/src/runtime.h
===================================================================
--- trunk/moon/src/runtime.h 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/runtime.h 2007-06-14 17:25:58 UTC (rev 79580)
@@ -299,20 +299,28 @@
GHashTable *names;
};
+class Downloader;
+
typedef void (*downloader_write_func)(guchar *buf, gsize n, gpointer cb_data);
+typedef gpointer (*downloader_create_state_func) (Downloader* dl);
+typedef void (*downloader_destroy_state_func) (gpointer state);
+typedef void (*downloader_open_func)(char *verb, char *uri, bool async,
gpointer state);
+typedef void (*downloader_send_func)(gpointer state);
+typedef void (*downloader_abort_func)(gpointer state);
+typedef char* (*downloader_get_response_text_func)(char *part, gpointer state);
class Downloader : public DependencyObject {
public:
- Downloader () {};
+ Downloader ();
+ virtual ~Downloader ();
+
virtual Value::Kind GetObjectType () { return Value::DOWNLOADER; };
- virtual void Abort ();
- virtual char* GetResponseText (char* PartName);
- virtual void Open (char *verb, char *URI, bool Async);
- virtual void Send ();
+ void Abort ();
+ char* GetResponseText (char* PartName);
+ void Open (char *verb, char *URI, bool Async);
+ void Send ();
- void SetWriteFunc (downloader_write_func write,
- gpointer data);
static DependencyProperty *DownloadProgressProperty;
static DependencyProperty *ResponseTextProperty;
@@ -320,31 +328,46 @@
static DependencyProperty *StatusTextProperty;
static DependencyProperty *UriProperty;
+
+ void Write (guchar *buf, gsize n);
+
+ // This is called by the consumer of the downloaded data (the
+ // Image class for instance)
+ void SetWriteFunc (downloader_write_func write,
+ gpointer data);
+
+ // This is called by the supplier of the downloaded data (the
+ // managed framework, the browser plugin, the demo test)
+ static void SetFunctions (downloader_create_state_func create_state,
+ downloader_destroy_state_func destroy_state,
+ downloader_open_func open,
+ downloader_send_func send,
+ downloader_abort_func abort,
+ downloader_get_response_text_func
get_response_text);
+
protected:
downloader_write_func write;
gpointer write_data;
-};
-Downloader* downloader_new ();
-class UnmanagedDownloader : public Downloader {
- public:
- UnmanagedDownloader ();
- virtual ~UnmanagedDownloader ();
- Value::Kind GetObjectType () { return Value::UNMANAGEDDOWNLOADER; };
+ gpointer downloader_state;
- virtual void Abort ();
- //virtual char* GetResponseText (char* PartName);
- virtual void Open (char *verb, char *URI, bool Async);
- virtual void Send ();
+ static downloader_create_state_func create_state;
+ static downloader_destroy_state_func destroy_state;
+ static downloader_open_func open;
+ static downloader_send_func send;
+ static downloader_abort_func abort;
+ static downloader_get_response_text_func get_response_text;
- void Close ();
- private:
- gboolean AsyncFillBuffer ();
- static gboolean async_fill_buffer (gpointer cb_data);
- int fd;
- int async_idle;
};
+Downloader* downloader_new ();
+void downloader_set_functions (downloader_create_state_func create_state,
+ downloader_destroy_state_func destroy_state,
+ downloader_open_func open,
+ downloader_send_func send,
+ downloader_abort_func abort,
+ downloader_get_response_text_func get_response);
+
class Visual : public DependencyObject {
public:
Visual () {};
Modified: trunk/moon/src/type.cpp
===================================================================
--- trunk/moon/src/type.cpp 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/type.cpp 2007-06-14 17:25:58 UTC (rev 79580)
@@ -162,7 +162,6 @@
Type::RegisterType ("TriggerActionCollection",
Value::TRIGGERACTION_COLLECTION, Value::COLLECTION);
Type::RegisterType ("TriggerCollection", Value::TRIGGER_COLLECTION,
Value::COLLECTION);
Type::RegisterType ("UIElement", Value::UIELEMENT, Value::VISUAL);
- Type::RegisterType ("UnmanagedDownloader", Value::UNMANAGEDDOWNLOADER,
Value::DOWNLOADER);
Type::RegisterType ("VideoBrush", Value::VIDEOBRUSH, Value::TILEBRUSH);
Type::RegisterType ("Visual", Value::VISUAL, Value::DEPENDENCY_OBJECT);
Type::RegisterType ("VisualCollection", Value::VISUAL_COLLECTION,
Value::COLLECTION);
Modified: trunk/moon/src/value.cpp
===================================================================
--- trunk/moon/src/value.cpp 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/value.cpp 2007-06-14 17:25:58 UTC (rev 79580)
@@ -596,12 +596,6 @@
checked_get_subclass (UIELEMENT, UIElement);
}
-UnmanagedDownloader*
-Value::AsUnmanagedDownloader ()
-{
- checked_get_subclass (UNMANAGEDDOWNLOADER, UnmanagedDownloader);
-}
-
VideoBrush*
Value::AsVideoBrush ()
{
Modified: trunk/moon/src/value.h
===================================================================
--- trunk/moon/src/value.h 2007-06-14 17:23:19 UTC (rev 79579)
+++ trunk/moon/src/value.h 2007-06-14 17:25:58 UTC (rev 79580)
@@ -121,7 +121,6 @@
class TriggerActionCollection;
class TriggerCollection;
class UIElement;
-class UnmanagedDownloader;
class VideoBrush;
class Visual;
class VisualCollection;
@@ -247,7 +246,6 @@
TRIGGERACTION_COLLECTION,
TRIGGER_COLLECTION,
UIELEMENT,
- UNMANAGEDDOWNLOADER,
VIDEOBRUSH,
VISUAL,
VISUAL_COLLECTION,
@@ -420,7 +418,6 @@
TriggerActionCollection* AsTriggerActionCollection ();
TriggerCollection* AsTriggerCollection ();
UIElement* AsUIElement ();
- UnmanagedDownloader* AsUnmanagedDownloader ();
VideoBrush* AsVideoBrush ();
Visual* AsVisual ();
VisualCollection* AsVisualCollection ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches