GTK-server

GTK-server

Infobox programming language
name = GTK-server
logo =
paradigm =
year = 2003
designer = Peter van Eerten
developer = Peter van Eerten
latest_release_version = 2.2.8
latest_release_date = September 29, 2008
typing =
implementations =
dialects =
influenced_by =
influenced =
operating_system = Cross-platform
license = GNU General Public License
website = [http://www.gtk-server.org www.gtk-server.org]

GTK-server is an open source project released under the GNU General Public License. The GTK-server project aims to bring Graphical User Interface programming to any interpreted language using the GIMP Tool Kit (GTK) or XForms (toolkit).

Philosophy

The GTK-server provides a stream-oriented interface to GTK. If the GTK-server is compiled as a standalone binary, it allows five different interfaces: stdin, fifo (named pipe), ipc (message queue), tcp or udp. Any interpreted language or shellscript with I/O capabilities can start the GTK-server with an argument specifying the type of interface, and can start sending GTK function calls in S-Expression format. After each request, the GTK-server returns a result, depending on the type of GTK function invoked.

If the GTK-server is compiled as a shared object, it exports the function 'gtk', which must be imported in the client program first. After that, the client program can start sending GTK function calls in S-Expression format as argument to the imported 'gtk' function.

Before the GTK-server actually can execute GTK functions, it has to read a configuration file in which the prototypes of the GTK functions are described. Since version 2.2.3 this also can be done on-the-fly, allowing the GTK-server to run without configuration file.

Implementation

Implementing the GTK-server leads to the followig considerations.

1) Accessing foreign functions is only possible when the accessed libraries are created with a non object oriented programming language like C or Pascal. Libraries created with C++ for example, use name mangling in order to unify overloaded functions. This means that the actual functionname in a C++ library cannot be known once the shared library has been compiled. Hence the functions in such a library cannot be accessed. Therefore, libraries like wxWidgets, the Qt toolkit, FLTK which are programmed in C++, cannot be accessed with the GTK-server concept. More on this matter is explained [http://www.isotton.com/devel/docs/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html here] .

2) The GTK library was implemented in the C programming language. Since C is a strongly typed programming language, the interpreted program needs to know the type of arguments and the type of the return value for each GTK function during runtime. These can be defined on-the-fly or in a configuration file, which is parsed by the GTK-server during startup. However, the GTK-server does not know the actual functions which are going to be used by the interpreted client program, so for GTK-server all arguments and return values for each GTK function are variable types.

This leads to a problem for the implementation, because the GTK functions and the corresponding arguments and return values cannot be hardcoded into the GTK-server binary.

The way to resolve this is by using a foreign function interface. Currently, four external foreign function interfaces are supported by GTK-server: [http://sourceware.org/libffi libFFI] , [http://www.haible.de/bruno/packages-ffcall.html FFCALL] , [http://www.nongnu.org/cinvoke C/Invoke] and [http://www.dyncall.org DynCall] . One of these libraries should be available on the target system, in order to compile the GTK-server successfully.

Example

The following Kornshell script starts the GTK-server in stdin mode, and creates a simple window with an exit button:

#!/bin/ksh

# Start GTK-servergtk-server -stdin |&

# Communicate with GTK-server and assign functionfunction gtk { print -p $1; read -p GTK; }function define { $2 "$3"; eval $1="$GTK"; }

# Setup GUIgtk "gtk_init NULL NULL"define WINDOW gtk "gtk_window_new 0"gtk "gtk_window_set_title $WINDOW 'Korn GTK-server demo'"gtk "gtk_window_set_default_size $WINDOW 400 200"define TABLE gtk "gtk_table_new 10 10 1"gtk "gtk_container_add $WINDOW $TABLE"define BUTTON gtk "gtk_button_new_with_label 'Click to Quit'"gtk "gtk_table_attach_defaults $TABLE $BUTTON 5 9 5 9"gtk "gtk_widget_show_all $WINDOW"

# Mainloopuntil | $EVENT = $WINDOW do define EVENT gtk "gtk_server_callback wait"done

# Exit GTK-servergtk "gtk_server_exit"

Advantages and limitations

Although GTK was meant to be used with the C programming language, it is now possible to use GTK from any interpreted language without changing the actual implementation of the interpreter. Also both GTK 1.x and GTK 2.x can be reached. Optionally, any other shared library can be used, like OpenGL related libraries, Poppler, Mozilla, but also libc and a music library like MikMod.

When using the GTK-server as a standalone binary, it inevitably creates an additional process in the processlist. Also, GTK functions defined as a macro cannot be reached by a client program.

External links

* [http://www.gtk-server.org GTK-server homepage]
* [http://www.gtk.org/ GTK+ homepage]
* [http://www.haible.de/bruno/packages-ffcall.html FFCALL]
* [http://www.nongnu.org/cinvoke/ C/Invoke]
* [http://sourceware.org/libffi/ libFFI]
* [http://www.dyncall.org DynCall]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • GTK+ — Infobox software name = GTK+ developer = GNOME Foundation latest release version = 2.14.3 latest release date = release date|2008|09|24 latest preview version = latest preview date = programming language = C operating system = Cross platform… …   Wikipedia

  • GTK+ — Entwickler Das GTK+ Team[1] Aktuelle Version 3.2.2 (12. November 2011) …   Deutsch Wikipedia

  • Gtk Sharp — infobox software name = Gtk# developer = Novell latest release version = 2.10.4 latest release date = February 27 2008 operating system = Cross platform genre = Widget toolkit license = GNU Lesser General Public License website = http://gtk sharp …   Wikipedia

  • X-Server — Logo des X Window Systems GNOME 2.18.1 …   Deutsch Wikipedia

  • X Server — Logo des X Window Systems GNOME 2.18.1 …   Deutsch Wikipedia

  • X.Org Server — Тип X server Разработчик X.Org Foundation …   Википедия

  • Ubuntu home server — Ubuntu  Cet article concerne le système d exploitation. Pour les autres significations, voir Ubuntu (homonymie) …   Wikipédia en Français

  • SUSE Linux Enterprise Server — SuSE Pour les articles homonymes, voir Suse. Famille GNU/Linux …   Wikipédia en Français

  • newLISP — Paradigm(s) Multi paradigm Appeared in 1991 Designed by Lutz Mueller Developer Lutz Mueller of Nuevatec …   Wikipedia

  • NewLISP — Infobox programming language name = Newlisp paradigm = Multi paradigm year = 1991 designer = Lutz Mueller developer = Lutz Mueller of Nuevatec latest release version = 9.4 latest release date = July 1, 2008 typing = implementations = dialects =… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”