GTK-server

Last updated
GTK-server
Original author(s) Peter van Eerten
Developer(s) Peter van Eerten
Initial release2003;20 years ago (2003)
Stable release
2.4.6 / October 11, 2022;11 months ago (2022-10-11)
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, and GTK 3.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

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

<span class="mw-page-title-main">PHP</span> Scripting language created in 1994

PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor.

VBScript is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment.

ScriptBasic is a scripting language variant of BASIC. The source of the interpreter is available as a C program under the LGPL license.

<span class="mw-page-title-main">Library (computing)</span> Collection of non-volatile resources used by computer programs

In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and subroutines, classes, values or type specifications. In IBM's OS/360 and its successors they are referred to as partitioned data sets.

In computer programming, standard streams are interconnected 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.

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>

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 or C++ languages.

<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 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 the 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 standard for software components introduced by Microsoft in 1993. It is used to enable inter-process communication object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, Browser Helper Object, ActiveX, COM+, DCOM, the Windows shell, DirectX, UMDF and Windows Runtime. The essence of COM is a language-neutral way of implementing objects that can be used in environments different from the one in which they were created, even across machine boundaries. For well-authored components, COM allows reuse of objects with no knowledge of their internal implementation, as it forces component implementers to provide well-defined interfaces that are separated from the implementation. The different allocation semantics of languages are accommodated by making objects responsible for their own creation and destruction through reference-counting. Type conversion casting between different interfaces of an object is achieved through the QueryInterface method. The preferred method of "inheritance" within COM is the creation of sub-objects to which method "calls" are delegated.

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 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 systems 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