From 246736ad18fe0b76d4b04043223df134bf186ce4 Mon Sep 17 00:00:00 2001 From: Michael 'Mickey' Lauer Date: Sun, 24 Jan 2010 20:33:11 +0100 Subject: [PATCH] remove dual-thread-based architecture; now that we have mainloop integration, we can simplify this a lot --- .gitignore | 8 ++ configure.ac | 8 +- eflvala/Makefile.am | 8 +- eflvala/application.vala | 79 +++-------------- eflvala/genlist.vala | 18 ++++ eflvala/notificationqueue.vala | 74 ---------------- eflvala/objects.vala | 134 ---------------------------- eflvala/thread.vala | 197 ----------------------------------------- examples/library/Makefile.am | 5 +- 9 files changed, 50 insertions(+), 481 deletions(-) create mode 100644 eflvala/genlist.vala delete mode 100644 eflvala/notificationqueue.vala delete mode 100644 eflvala/objects.vala delete mode 100644 eflvala/thread.vala diff --git a/.gitignore b/.gitignore index 5ad0022..9a35bbc 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,11 @@ stamp-h1 *.o *.vala.stamp +examples/ecore-glib/ecore-glib +examples/ecore-signals/ecore_signals +examples/ecore/ecore +examples/edje/edje +examples/eina/eina +examples/elementary/elementary-vapi +examples/elementary/note.txt +examples/library/viewstates/viewstates diff --git a/configure.ac b/configure.ac index 0c4fd03..5860534 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([libeflvala], [0.0.2.0], [mlauer@vanille-media.de], [libeflvala]) +AC_INIT([libeflvala], [0.1.0.0], [mlauer@vanille-media.de], [libeflvala]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS(config.h) AM_INIT_AUTOMAKE([dist-bzip2]) @@ -16,13 +16,14 @@ AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS) -VALA_REQUIRED=0.7.7 +VALA_REQUIRED=0.7.9 EINA_REQUIRED=0.0.0 EVAS_REQUIRED=0.0.0 ECORE_REQUIRED=0.0.0 +EDJE_REQUIRED=0.0.0 ELM_REQUIRED=0.0.0 GLIB_REQUIRED=2.18.0 -DBUS_REQUIRED=1.1.1 +DBUS_REQUIRED=1.2.1 DBUS_GLIB_REQUIRED=0.74 PKG_CHECK_MODULES(VALA, @@ -34,6 +35,7 @@ PKG_CHECK_MODULES(DEPS, eina-0 >= $EINA_REQUIRED evas >= $EVAS_REQUIRED ecore >= $ECORE_REQUIRED + edje >= $EDJE_REQUIRED elementary >= $ELM_REQUIRED glib-2.0 >= $GLIB_REQUIRED gobject-2.0 >= $GLIB_REQUIRED) diff --git a/eflvala/Makefile.am b/eflvala/Makefile.am index e405ac5..8abd15c 100644 --- a/eflvala/Makefile.am +++ b/eflvala/Makefile.am @@ -10,12 +10,11 @@ VALAC_ARGS = \ --pkg eina \ --pkg evas \ --pkg ecore \ + --pkg edje \ --pkg elm \ - --pkg posix \ --header eflvala.h \ --library eflvala-1.0 \ --save-temps \ - --thread \ --basedir $(top_srcdir) vapidir = $(datadir)/vala/vapi @@ -43,15 +42,12 @@ lib_LTLIBRARIES = \ libeflvala_la_VALASOURCES = \ application.vala \ - notificationqueue.vala \ - objects.vala \ - thread.vala \ + genlist.vala \ statemachine.vala \ $(NULL) libeflvala_la_SOURCES = \ $(libeflvala_la_VALASOURCES:.vala=.c) \ - $(libeflvala_la_VALASOURCES:.vala=.h) \ \ $(NULL) diff --git a/eflvala/application.vala b/eflvala/application.vala index 337e5ac..36d06dd 100644 --- a/eflvala/application.vala +++ b/eflvala/application.vala @@ -1,5 +1,5 @@ /** - * Copyright (C) 2009 Michael 'Mickey' Lauer + * Copyright (C) 2009-2010 Michael 'Mickey' Lauer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,95 +24,42 @@ public abstract interface EflVala.IApplication : GLib.Object //======================================================================= { public abstract int run(); - public abstract void setupFrontend(); - public abstract void setupBackend(); public abstract void quit(); - - public abstract void handleCommandFromFrontend( EflVala.Command command ); - public abstract void handleCommandFromBackend( EflVala.Command command ); - public abstract void sendCommandToFrontend( EflVala.Command command ); - public abstract void sendCommandToBackend( EflVala.Command command ); } //======================================================================= public class EflVala.Application : EflVala.IApplication, GLib.Object //======================================================================= { - private EflVala.EThread _ethread; - private EflVala.GThread _gthread; - // - // public + // public API // - public Application( string[] args ) { debug( "Application()" ); Elm.init( args ); //FIXME: might be better done elsewhere (i.e. from within the E thread?) assert ( theApp == null ); theApp = this; - _createThreads(); } public int run() { - _ethread.run(); - _gthread.run(); - _ethread.join(); - _gthread.join(); + GLib.MainLoop gmain = new GLib.MainLoop( null, false ); + if ( Ecore.MainLoop.glib_integrate() ) + { + debug( "GLib mainloop integration successfully completed" ); + } + else + { + critical( "Could not integrate glib mainloop. This library needs ecore compiled with glib mainloop support" ); + } + Ecore.MainLoop.begin(); return 0; } public void quit() { - _ethread.quit(); - _gthread.quit(); + Ecore.MainLoop.quit(); } - public virtual void setupFrontend() - { - } - - public virtual void setupBackend() - { - } - - public virtual void sendCommandToFrontend( EflVala.Command command ) - { - _gthread.send( command ); - } - - public virtual void sendCommandToBackend( EflVala.Command command ) - { - _ethread.send( command ); - } - - /** - * called within the context of the frontend (E) thread - **/ - public virtual void handleCommandFromBackend( EflVala.Command command ) - { - } - - /** - * called within the context of the backend (G) thread - **/ - public virtual void handleCommandFromFrontend( EflVala.Command command ) - { - } - - // - // private - // - - private void _createThreads() - { - if ( !GLib.Thread.supported() ) - { - error( "Cannot run without threads!" ); - } - - _ethread = new EflVala.EThread(); - _gthread = new EflVala.GThread(); - } } diff --git a/eflvala/genlist.vala b/eflvala/genlist.vala new file mode 100644 index 0000000..1772259 --- /dev/null +++ b/eflvala/genlist.vala @@ -0,0 +1,18 @@ +/** + * Copyright (C) 2009-2010 Michael 'Mickey' Lauer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + **/ diff --git a/eflvala/notificationqueue.vala b/eflvala/notificationqueue.vala deleted file mode 100644 index da3c8af..0000000 --- a/eflvala/notificationqueue.vala +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2009 Michael 'Mickey' Lauer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - **/ - -//======================================================================= -public class EflVala.QueueWithNotifier : GLib.Object -//======================================================================= -{ - private GLib.Queue q; - private static int counter = 0; - private int readfd = -1; - private int writefd = -1; - - public QueueWithNotifier() - { - q = new GLib.Queue(); - int[] fds = { 0, 0 }; - var ok = Posix.pipe( fds ); - if ( ok == -1 ) - critical( "could not create posix pipes: %s", Posix.strerror( Posix.errno ) ); - debug( "fds = %d, %d", fds[0], fds[1] ); - readfd = fds[0]; - writefd = fds[1]; - } - - ~QueueWithNotifier() - { - if ( readfd != -1 ) - Posix.close( readfd ); - if ( writefd != -1 ) - Posix.close( writefd ); - } - - public T read() - { - char[] dot = { '.' }; - var number = Posix.read( readfd, dot, 1 ); - assert ( number == 1 ); - return q.pop_tail(); - } - - public void write( T message ) - { - q.push_head( message ); - char[] dot = { '.' }; - var number = Posix.write( writefd, dot, 1 ); - assert ( number == 1 ); - } - - public int getReadFd() - { - return readfd; - } - - public int getWriteFd() - { - return writefd; - } -} diff --git a/eflvala/objects.vala b/eflvala/objects.vala deleted file mode 100644 index eb62ced..0000000 --- a/eflvala/objects.vala +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Copyright (C) 2009 Michael 'Mickey' Lauer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - **/ - -// misc objects that need to get categorized - -//======================================================================= -public class EflVala.Command : GLib.Object -//======================================================================= -{ - public string command; - - public Command( string command ) - { - this.command = command; - debug( "creating command '%s' (%p)", command, this ); - } - - ~Command() - { - debug( "destructing command '%s' (%p)", this.command, this ); - } -} - -//======================================================================= -public class EflVala.BidirectionalThreadQueue : GLib.Object -//======================================================================= -{ - public enum Identifier - { - COMMUNICATION_THREAD, - GUI_THREAD; - } - private static EflVala.QueueWithNotifier toGuiQ; - private static EflVala.QueueWithNotifier toCommQ; - - private Identifier owner; - - public BidirectionalThreadQueue( Identifier id ) - { - owner = id; - switch ( id ) - { - case Identifier.COMMUNICATION_THREAD: - assert ( toGuiQ == null ); - toGuiQ = new EflVala.QueueWithNotifier(); - break; - case Identifier.GUI_THREAD: - assert ( toCommQ == null ); - toCommQ = new EflVala.QueueWithNotifier(); - break; - default: - assert_not_reached(); - } - } - - public void getFds( out int readfd, out int writefd ) - { - switch ( owner ) - { - case Identifier.COMMUNICATION_THREAD: - readfd = toCommQ.getReadFd(); - writefd = toGuiQ.getWriteFd(); - break; - case Identifier.GUI_THREAD: - readfd = toGuiQ.getReadFd(); - writefd = toCommQ.getWriteFd(); - break; - default: - assert_not_reached(); - } - } - - public int getReadFd() - { - switch ( owner ) - { - case Identifier.COMMUNICATION_THREAD: - return toCommQ.getReadFd(); - break; - case Identifier.GUI_THREAD: - return toGuiQ.getReadFd(); - break; - default: - assert_not_reached(); - } - } - - public Command? read() - { - switch ( owner ) - { - case Identifier.COMMUNICATION_THREAD: - return toCommQ.read(); - break; - case Identifier.GUI_THREAD: - return toGuiQ.read(); - break; - default: - assert_not_reached(); - } - } - - public void write( Command command ) - { - switch ( owner ) - { - case Identifier.COMMUNICATION_THREAD: - toGuiQ.write( command ); - break; - case Identifier.GUI_THREAD: - toCommQ.write( command ); - break; - default: - assert_not_reached(); - } - } - -} diff --git a/eflvala/thread.vala b/eflvala/thread.vala deleted file mode 100644 index 2cdf203..0000000 --- a/eflvala/thread.vala +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Copyright (C) 2009 Michael 'Mickey' Lauer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - **/ - -public delegate bool EflVala.FdCallback( int fd ); - -//======================================================================= -public class EflVala.Thread : GLib.Object -//======================================================================= -{ - private unowned GLib.Thread _thread; - protected EflVala.BidirectionalThreadQueue q; - - public Thread() - { - debug( "constructing thread (%p)", this ); - } - - ~Thread() - { - debug( "destructing thread (%p)", this ); - } - - public void run() - { - assert ( _thread == null ); - _thread = GLib.Thread.create( _run, true ); - } - - public void join() - { - assert ( _thread != null ); - _thread.join(); - } - - public virtual void mainfunc() - { - } - - public virtual void quit() - { - } - - public virtual bool command( EflVala.Command cmd ) - { - return false; - } - - public virtual void send( EflVala.Command cmd ) - { - q.write( cmd ); - } - - // - // internal - // - - private void* _run() - { - mainfunc(); - return null; - } -} - -//======================================================================= -public class EflVala.GThread : EflVala.Thread -//======================================================================= -{ - private GLib.MainLoop mainloop; - private GLib.IOChannel iochannel; - - public GThread() - { - debug( "constructing G thread" ); - // create mainloop - mainloop = new GLib.MainLoop( null, false ); - // create commqueue - q = new EflVala.BidirectionalThreadQueue( EflVala.BidirectionalThreadQueue.Identifier.COMMUNICATION_THREAD ); - } - - public override void mainfunc() - { - debug( "G mainfunc" ); - // give app a chance to init its backend - theApp.setupBackend(); - // setup debug watcher - Timeout.add_seconds( 1, _secondsTimeout ); - // hook q into mainloop - iochannel = new GLib.IOChannel.unix_new( q.getReadFd() ); - iochannel.add_watch( GLib.IOCondition.IN, _canReadFromQueue ); - // and run - mainloop.run(); - } - - public override void quit() - { - mainloop.quit(); - } - - public override bool command( EflVala.Command cmd ) - { - debug( "G Thread got command: '%s'", cmd.command ); - theApp.handleCommandFromFrontend( cmd ); - return true; - } - - // - // internal - // - private bool _canReadFromQueue( GLib.IOChannel source, GLib.IOCondition condition ) - { - return command( q.read() ); - } - - private bool _secondsTimeout() - { - debug( "G still running" ); - return true; - } -} - -//======================================================================= -public class EflVala.EThread : EflVala.Thread -//======================================================================= -{ - private Ecore.Timer timer; - private Ecore.FdHandler fdhandler; - - public EThread() - { - debug( "constructing E thread" ); - // create mainloop - //Elm.init( theApp.args() ); - // create commqueue - q = new EflVala.BidirectionalThreadQueue( EflVala.BidirectionalThreadQueue.Identifier.GUI_THREAD ); - } - - ~EThread() - { - Elm.shutdown(); - } - - public override void mainfunc() - { - debug( "E mainfunc" ); - // give app a chance to init its frontend - theApp.setupFrontend(); - // setup debug watcher - timer = new Ecore.Timer( 1.0, _secondsTimeout ); - // hook q into mainloop - fdhandler = new Ecore.FdHandler( q.getReadFd(), Ecore.FdHandlerFlags.READ, _canReadFromQueue, null ); - // and run - Elm.run(); - } - - public override void quit() - { - Elm.exit(); - } - - public override bool command( EflVala.Command cmd ) - { - debug( "E Thread got command: '%s'", cmd.command ); - theApp.handleCommandFromBackend( cmd ); - return true; - } - - // - // internal - // - - private bool _canReadFromQueue( Ecore.FdHandler fdhandler ) - { - return command( q.read() ); - } - - private bool _secondsTimeout() - { - debug( "E still running" ); - return true; - } -} diff --git a/examples/library/Makefile.am b/examples/library/Makefile.am index 2671fe0..368640a 100644 --- a/examples/library/Makefile.am +++ b/examples/library/Makefile.am @@ -1,3 +1,6 @@ -SUBDIRS = mainloops viewstates +SUBDIRS = \ + viewstates + +# mainloops is broken atm. MAINTAINERCLEANFILES = Makefile.in -- 2.11.4.GIT