Mono: Rapid GUI Application Development On Linux

Karl Bunnell

Software Engineer Consultant, Novell Inc.

kbunnell@novell.com

Agenda

.NET Overview

Mono Overview

Lab Exercises that implement simple technologies on Linux Platform

What is .NET?

Microsoft .NET is a “vision”, or marketing strategy, as well as new technologies

A brand applied to:

Several new technologies

.NET Framework – Mono is an implementation of the .NET Framework

New releases of old technologies

Several old technologies

Most significant new technologies

Common Language Runtime (CLR) / Common Language Infrastructure (CLI)

Web Services

.NET Platform

Visual Studio .NET

.NET

Enterprise

Servers

.NET Framework

.NET

Services

Operating Systems, desktops and devices

The .NET Framework

Managed, type–safe environment for the development and execution of applications.

Previously only available on Windows, now available on Linux. The .NET Framework consists of the following two components:

Common Language Runtime (CLR)

Manages code execution

Provides core services

Enforces safety and security restrictions

.NET Framework class library

Collection of useful and reusable types that integrate with CLR

.NET Framework

Web Services

Windows Forms

Web Forms

Data and XML Classes

Framework Base Classes

Common Language Runtime

Windows/Linux Platform

The .NET Framework Benefits

Language Independence

Write an application in any supported language (C#, Monobasic, etc) and its classes can be shared with an application written in any other supported language.

Platform Independence

Like Java, .NET code is not compiled to machine code but to an intermediate byte format (CIL). Hence, anywhere the interpretive engine exists the application can run.

Class Library

Extensive class library that includes support for many/most of the tasks needed for application development.

The .NET Framework Benefits (cont.)

C# Language

Effective language patterned after Java, so it contains many of the strengths of both Java and C++

VB.NET Language

More full-featured than previous versions of Basic. Basic classes can be used from other languages like C#

Web Applications

ASP.NET delivers on the promise of Web Services with implementation of technologies such as WSDL, SOAP, etc.

The .NET Framework Class Library

Object-oriented collection of reusable classes that provide many of the services needed to write an application

All Framework classes are under the “System” namespace

System.Collections

System.Data – database access and manipulation

System.Data.SQLClient – MS SQL Server specific

System.IO – File system handling

System.Security – permissions, cryptography, etc.

System.Windows.Forms – types for windows apps.

The .NET Framework Namespace

Logical, Hierarchical grouping of related classes

Similar to a ‘package’ in Java

Access namespaces with:

Imports – Visual Basic .NET

using – C#

using System.Windows.Forms

Assemblies

Physical packaging of the class libraries

Typically built as a ‘.dll’ file.

However, don’t confuse them as being a Win32 shared library

An Assembly Manifest is Metadata that contains information about what an assembly contains

Assemblies name and version

Types exposed by the assembly

Other assemblies required by the assembly

Security instructions (permissions required and denied)

.NET runtime, tools, compilers etc. can all use this ‘Metadata’ to find out all they need to know about .NET resources.

Used for Reflection

Common Language Runtime (CLR)

Provides services to .NET applications (similar to JVM in Java)

A set of libraries available to all .NET applications

Manages memory

Thread execution

Code execution

Type safety verification

Compilation (Just In-time Compiler)

Common Language Infrastructure (CLI)

Subset of the CLR submitted to the European Computer Manufacturers Association (ECMA) standards organization so that a third-party vendor could implement a CLR for a platform other than Windows.

Shared Source CLI (SSCLI) is a working implementation of the ECMA CLI.

Submitted for standardization:

C#

Semantics for metadata

Microsoft Intermediate Language (MSIL)

Parts of the .NET framework class library

Managed Code

Code that is executed by the CLR. Managed code provides information (i.e., metadata) to allow the CLR to locate methods encoded in assembly modules, store and retrieve security information, handle exceptions, and walk the program stack. Managed code can access both managed data and unmanaged data. Managed data—Memory that is allocated and released by the CLR using Garbage Collection. Managed data can only be accessed by managed code.

Web Definition:

.NET Portable Execution File

Executable files must conform to the publicly available file format called the “PE file format”, which is a derivative of the Microsoft Common Object File Format (COFF), also publicly available.

.NET extends this file with a CLR Header and Data section that allows the CLR to execute/manage the application.

.NET

PE File

Common Language Runtime

.NET

PE File

.NET

PE File

The Microsoft Intermediate Language (MSIL)

Intermediate format that runs in the CLR

Not a machine specific binary but an intermediate representation

Must be converted by a .NET Framework just-in-time (JIT) compiler to native code

MSIL Tools

MSIL Assembler (Ilasm.exe)

Generates executable from MSIL

MSIL Disassembler (Ildasm.exe)

Creates MSIL code from executable

Native Image Generator Tool (Ngen.exe)

Compiles MSIL to machine code in lieu of JIT compiler

MSIL “Hello World”

Assembler directives begin with a period

MSIL instructions: lines 8, 9 and 10

/* This is an MSIL comment */

.assembly extern mscorlib {}

.assembly hello {}

.method static public void main() il managed {

.entrypoint

.maxstack 1

ldstr “Hello World!”

call void [mscorlib]System.Console::WriteLine( class System.String )

ret

}

.NET Application Construction

Write application in one of the many supported languages (C#, VB, C++, etc).

All these languages conform to the Common Language Specification (CLS)

Compile application into Microsoft Intermediate Language (MSIL or IL)

Execute code within the CLR

Since all compilers, tools and the CLR use the Common Type System (CTS) data can be transferred between applications developed in different languages.

Unmanaged Component

C++

C#

VB

Compiler

Compiler

Compiler

Source Code

Managed Code

Assembly Code

Assembly Code

Assembly Code

Common Language Runtime

JIT Compiler

Native Code

Operating System Services

.NET Execution Model

Common Type System (CTS)

.NET supports language integration, which means that you can inherit classes, catch exceptions, etc. across languages. This is possible because all .NET components must adhere to the CTS standard.

All objects derive from root object System.Object

CTS is a type system shared by compilers, tools and the CLR

CTS supports two different types:

Reference (heap allocation)

Value (stack allocation)

CTS

Common Language Specification (CLS)

The goal of .NET is to support language integration

BUT - not all languages are the same

Some are case sensitive, others are not, etc.

CLS is a specification that identifies a base set of rules that are required for language integration.

Languages must support CLS to be compliant with the .NET Framework

Essentially CLS is a contract between language designers and the .NET Framework

CLS

NNET Languages

The CLR was designed to support multiple languages

C#

VB

C++

J#

Mono

An Open Source .NET Framework Implementation.

Effort lead by Ximian, launched in July 2001

~100 contributors, ~30 very active

Status today:

CLI compliant execution system.

Just-in-time compiler on x86 systems.

Multi-platform (Linux, Solaris, BSD, Windows)

C# compiler.

Class Libraries:

Most core functionality done.

Various degrees of readiness at higher levels.

Project Background

Bring Open Source to the Desktop.

The GNOME project:

Unix model vision: CORBA and Bonobo.

Any programming language

Small tools/components

A desktop for Linux.

A development platform

A suite of productivity applications

Started in 1997

Mostly developed in C, Python and Perl.

Avoid C++ as much as possible.

Scope:

We ran into various problems:

Old development tools, C-based

Learning curve too hard for new programmers.

Costly to develop.

Gap between release and support in languages.

Evolving GNOME

Language bindings:

Lag between release and deployment

Good for fine control.

Multiple languages supported

CORBA/Bonobo:

Solves release/deployment

Coarse interfaces.

Bonobo was complicated

Evolution

Outlook replacement for Linux.

Multi-threaded, multi-process, multi-component.

Most standard compliant mailer/calendar/contact system.

800k lines of code.

2 years, 17 programmers & a lot of money.

Slow to develop, debug, improve, innovate.

Example Case

The Future:

Enable scripting, allow plugins

Reduce cost of development

The .NET Framework

What we were looking for

For Gnome, For Ximian

Core standardized (VES + C# language)

A virtual execution system (VES)

Multiple language support

Common subset for interop: CTS

A large class library

A new programming language: C#

VES designed to interoperate with legacy code

Mono Project Scope

A change of direction

Desktop -> Platform

Bring the .NET Framework to Unix

Allows easy migration of Windows to Unix.

Develop with Visual Studio, deploy on Linux.

Gives us much needed room to breathe.

Goals:

Virtual Execution System

C# compiler

Class Libraries compatible with .NET Framework

Mono Runtime

Mono Development Tools:

C# Compiler, Debugger, Profiling.

.NET Classes:

Core + XML

ADO.NET

ASP.NET

Mono Classes:

Gtk#: Gtk, Gnome, A11n, Media

PEToolkit

JIT, Loader, Verifier

Threads, I/O

GC

Native Platform (x86, SPARC, PPC, StrongARM, S390)

C#.NET Programming Language

An object-oriented and type-safe programming language supported by Microsoft for use with the .NET Framework. C# (pronounced "see-sharp") was created specifically for building enterprise-scale applications using the .NET Framework. It is similar in syntax to both C++ and Java and is considered by Microsoft as the natural evolution of the C and C++ languages. C# was created by Anders Hejlsberg (author of Turbo Pascal and architect of Delphi), Scot Wiltamuth, and Peter Golde. C# is defined by the standard ECMA-334

Web Definition:

Mono Runtime

Mono Development Tools:

C# Compiler, Debugger, Profiling.

.NET Classes:

Core + XML

ADO.NET

ASP.NET

Mono Classes:

Gtk#: Gtk, Gnome, A11n

JIT, Loader, Verifier

Threads, I/O

GC

Native Platform (x86, SPARC, PPC, StrongARM, S390)

Media

PEToolkit

GUI classes: Gtk#

Gtk# is Ximian's main interest

For Gnome Purposes

It is also easy, most stuff is already there.

We have plenty of in-house expertise.

Benefits our products directly.

Works on Windows as well.

Windows.Forms

Current strategy:

Use WineLib to implement it.

Reduces time of development.

Need it to be Wndproc/PInvoke compatible.

Implement alternate render engines in Wine:

Gtk on X11

Cocoa on MacOS X

Reasons:

Major interest in getting it done.

Third party developers focused on it.

Second most requested Mono feature.

ASP.NET WebForms

Component-based Web programming.

Most requested Mono feature.

Develop on Windows, deploy on Unix.

ASP.NET: XSP parser.

Finished the HttpRuntime infrastructure recently.

Can run as a cgi-bin in most servers.

Deep integration with Apache coming soon.

Limited to C# for the server-side-scripts

What is gtk+…

“GTK+ is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets…”

gtk.org

GTK+ Libraries

GTK+ is based on three libraries

1

GLib

a. A low-level core library that provides data structure handling for C, portability wrappers, and interfaces for such runtime activity as an event loop, threads, dynamic loading, etc.

Pango

a. A library for layout and rendering of text

ATK

a. A library that provides a set of interfaces for accessibility. It is used by screen readers, and other devices

2

3

GTK+ Uses Widgets…

Widget is an X Windows term for any user interface element.

Buttons

Windows

Labels

http://devolper.gnome.org/doc/API/gtk/gtkobj

GTK+ Basics…

Container Widgets

A widget that can ‘contain’ one other widget. For example a button can contain a label, a window might contain a button

Packing Widgets

A widget that can hold more than one other widget. These are not visible so they are normally placed within another container widget that is visible. These widgets come in three varieties:

Vertical Packing Boxes

Horizontal Packing Boxes

Tables (a grid on which to places widgets)

GTK+ Basics… (cont.)

Properties

Each widget may employ a number of properties such as the visible property, the size property, etc.

Signals

A signal occurs whenever something interesting (like a user clicking a button) happens to a widget. When the signal occurs a callback method is normally called that performs some programmer defined function.

Widget Life-Cycle

Creation

gtk_button_new

Add widget to a container

gtk_container_add( window, button )

Define a signal for the widget

gtk_signal_connect( button, “clicked”, ButtonFunc, NULL )

Show the widget

gtk_widget_show( button)

Destroy the widget

gtk_widget_destroy(button)

Resources

EMCA filing of CLI and C# http://www.ecma.ch/ecma1/STAND/ecma-335.htm

The Mono Project homepage http://www.go-mono.com/

The dotGNU hompage http://www.dotgnu.org

Microsoft's .NET Homepage http://www.microsoft.com/net

2004-02-11T13:08:51