GTK-server

Last updated
GTK-server
Original author(s) Peter van Eerten
Developer(s) Peter van Eerten
Initial release2003;21 years ago (2003)
Stable release
2.4.6 / November 1, 2024;4 days ago (2024-11-01)
Operating system Cross-platform
License GNU General Public License
Website www.gtk-server.org

The GTK-server project aims to bring graphical user interface (GUI) programming to any interpreted language using the GNU Image Manipulation Program (GIMP) ToolKit (GTK) or XForms. It releases free and open-source software under the GNU General Public License.

Contents

Philosophy

The GTK-server provides a stream-oriented interface to GTK. If the GTK-server is compiled as a standalone program binary, it allows five different interfaces: standard input (stdin), first in, first out (FIFO) (named pipe), inter-process communication (IPC) (message queue), Transmission Control Protocol (TCP), or User Datagram Protocol (UDP). Any interpreted language or shell script with input/output (I/O) abilities 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 can execute GTK functions, it must 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 following considerations.

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: libffi, FFCALL, [2] C/Invoke [3] and dyncall. [4] One of these libraries should be available on the target system, 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-server gtk-server-stdin|&# Communicate with GTK-server and assign functionfunctiongtk{print-p$1;read-pGTK;}functiondefine{$2"$3";eval$1="$GTK";}# Setup GUI gtk"gtk_init NULL NULL" defineWINDOWgtk"gtk_window_new 0" gtk"gtk_window_set_title $WINDOW 'Korn GTK-server demo'" gtk"gtk_window_set_default_size $WINDOW 400 200" defineTABLEgtk"gtk_table_new 10 10 1" gtk"gtk_container_add $WINDOW$TABLE" defineBUTTONgtk"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=$BUTTON||$EVENT=$WINDOW]]dodefineEVENTgtk"gtk_server_callback wait"done# Exit GTK-server gtk"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 implementation of the interpreter. Also, GTK 1.x, GTK2.x, GTK 3.x and GTK 4.x can be reached. Optionally, any other shared library can be used, like OpenGL related libraries, Poppler, Mozilla, but also libc, sqlite 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.

Related Research Articles

<span class="mw-page-title-main">Common Gateway Interface</span> Interface between Web servers and external programs

In computing, Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program to process HTTP or HTTPS user requests.

VBScript is a deprecated programming language for scripting on Microsoft Windows using Component Object Model (COM) based on classic Visual Basic and Active Scripting.

In computing, cross-platform software is computer software that is designed to work in several computing platforms. Some cross-platform software requires a separate build for each platform, but some can be directly run on any platform without special preparation, being written in an interpreted language or compiled to portable bytecode for which the interpreters or run-time packages are common or standard components of all supported platforms.

In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console, but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.

<span class="mw-page-title-main">DIGITAL Command Language</span> Command language adopted by several operating systems (OSs)

DIGITAL Command Language (DCL) is the standard command language adopted by many of the operating systems created by Digital Equipment Corporation. DCL had its roots in IAS, TOPS-20, and RT-11 and was implemented as a standard across most of Digital's operating systems, notably RSX-11 and RSTS/E, but took its most powerful form in VAX/VMS. DCL continues to be developed by VSI as part of OpenVMS.

<span class="mw-page-title-main">IBM System Object Model</span> Programming framework

The System Object Model (SOM) is an object-oriented shared library technology developed by IBM that supports defining an interface to an object so that its interface is separate from its implementation.

In computing, late binding or dynamic linkage—though not an identical process to dynamically linking imported code libraries—is a computer programming mechanism in which the method being called upon an object, or the function being called with arguments, is looked up by name at runtime. In other words, a name is associated with a particular operation or object at runtime, rather than during compilation. The name dynamic binding is sometimes used, but is more commonly used to refer to dynamic scope.

<span class="mw-page-title-main">GObject</span> Free software library

The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C programs to provide object-oriented C-based APIs and through bindings to other languages to provide transparent cross-language interoperability, e.g. PyGObject.

<span class="mw-page-title-main">X Toolkit Intrinsics</span>

X Toolkit Intrinsics is a library that implements an API to facilitate the development of programs with a graphical user interface (GUI) for the X Window System. It can be used in the C language. Design took place late 1980s to early 1990s.

A user interface markup language is a markup language that renders and describes graphical user interfaces and controls. Many of these markup languages are dialects of XML and are dependent upon a pre-existing scripting language engine, usually a JavaScript engine, for rendering of controls and extra scriptability.

<span class="mw-page-title-main">Xlib</span> Client library for the X Window System

Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the X protocol.

A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using checkboxes, radio buttons, or text fields. For example, forms can be used to enter shipping or credit card data to order a product, or can be used to retrieve search results from a search engine.

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into a binary dynamic-link library.

Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under an MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.

<span class="mw-page-title-main">Vala (programming language)</span> Programming language

Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject system.

This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.

Component Object Model (COM) is a binary-interface technology for software components from Microsoft that enables using objects in a language-neutral way between different programming languages, programming contexts, processes and machines.

Racket has been under active development as a vehicle for programming language research since the mid-1990s, and has accumulated many features over the years. This article describes and demonstrates some of these features. Note that one of Racket's main design goals is to accommodate creating new programming languages, both domain-specific languages and completely new languages. Therefore, some of the following examples are in different languages, but they are all implemented in Racket. Please refer to the main article for more information.

<span class="mw-page-title-main">Elm (programming language)</span> Functional programming language

Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness. It advertises "no runtime exceptions in practice", made possible by the Elm compiler's static type checking.

<span class="mw-page-title-main">Nim (programming language)</span> Programming language

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level system programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

References

  1. Isotton, Aaron (2006-03-16), "C++ dlopen mini HOWTO", The Linux Documentation Project , archived from the original on 2021-08-12, retrieved 2021-09-07
  2. FFCALL Libraries, archived from the original on 2021-07-01, retrieved 2021-09-07
  3. C/Invoke, archived from the original on 2021-08-20, retrieved 2021-09-07
  4. dyncall.org – calling C functions dynamically, archived from the original on 2021-04-16, retrieved 2021-09-07