Components in GNOME Outline Components in GNOME n

  • Slides: 34
Download presentation
Components in GNOME 林咸禮

Components in GNOME 林咸禮

Outline Components in GNOME n n n Why object model ? The uses of

Outline Components in GNOME n n n Why object model ? The uses of CORBA Implementation notes ORBit Programming

Why object model ? (1/3) UNIX pipe system n n Allow users to create

Why object model ? (1/3) UNIX pipe system n n Allow users to create new results by joining smaller components. > ls | more orbit-docs. tar. gz orbit. zip … ls pipe More

Why object model ? (2/3) Pipe in modern desktop environment n n n The

Why object model ? (2/3) Pipe in modern desktop environment n n n The information flow is unidirectional Characters, lines, and entire files are basic unit of information exchange. Not scale well with complex application Solution n n Component based programming framework But UNIX lacks such a framework

Why object model ? (3/3) GNOME provides a component model n n Based on

Why object model ? (3/3) GNOME provides a component model n n Based on OMG’s CORBA Adapt ORBit implementation Object D Object A CORBA Object C Object B

The uses of CORBA in GNOME Exporting an application’s API General IPC and RPC

The uses of CORBA in GNOME Exporting an application’s API General IPC and RPC mechanism Scripting n Automate common tasks Define system services n Standard interfaces Bonobo n Document based application

Exporting an application’s API Export internal engine n n Use interfaces in GNOME: :

Exporting an application’s API Export internal engine n n Use interfaces in GNOME: : Gnumeric Guppi can manipulate a spreadsheet in gnumeric Standard interfaces to implement n n Desktop: : Editor A mail client can choose any Editor that implement Desktop: : Editor

IPC and RPC Mechanism (1/4) Process communication n In traditional UNIX world w IPC:

IPC and RPC Mechanism (1/4) Process communication n In traditional UNIX world w IPC: shared memory, pipe… w RPC: TCP/IP w IPC/RPC protocols are hand-crafted individually n Hard to maintain and too efforts on details Program 1 Hand-crafted protocol RPC/IPC codes Program 2 RPC/IPC codes IPC / RPC

IPC and RPC Mechanism (2/4) CORBA provide object location transparency Program 1 Handle by

IPC and RPC Mechanism (2/4) CORBA provide object location transparency Program 1 Handle by ORB Object reference. Stub skeleton CORBA Programmer’s view Program 2 Remote Object

IPC and RPC Mechanism (3/4) Currently use: n Communicate with embedded applications w GNOME

IPC and RPC Mechanism (3/4) Currently use: n Communicate with embedded applications w GNOME Control and GNOME Panel n Modify a “live” application w Changes happen to the current server on the fly w Mod_CORBA apache module, Dents DNS Server)

IPC and RPC Mechanism (4/4) embedded program

IPC and RPC Mechanism (4/4) embedded program

Scripting Allow user to automate common tasks n n Like macro and VBA in

Scripting Allow user to automate common tasks n n Like macro and VBA in Windows Manipulate a gnumeric spreadsheet, automate some repetitive tasks… Major scripting languages on UNIX have CORBA binding n Such as Perl, Python and Java

Define system services Many procedure carried on UNIX do not have a standard (rely

Define system services Many procedure carried on UNIX do not have a standard (rely on tradition) Use helper script is not robust Define standard interface about system service n n n Encapsulate details by CORBA-based server System: : admin: : user System: : Mail: : deliver

Bonobo (1/2) GNOME Document model n Let document-based applications embed themselves in each other

Bonobo (1/2) GNOME Document model n Let document-based applications embed themselves in each other Similar with OLE and Active. X in Windows

Bonobo (2/2) Embed many programs in gnumeric

Bonobo (2/2) Embed many programs in gnumeric

Implementation notes ORBit n n CORBA implementation on GNOME Written in straight C, but

Implementation notes ORBit n n CORBA implementation on GNOME Written in straight C, but have many language binding GNORBA n n Wrapper of common CORBA services in GNOME Name server and the initialization code w Allow to create specific application name server w Start automatically when needed

What is CORBA (1/2) Protocol for interaction between objects Programmer does not care whether

What is CORBA (1/2) Protocol for interaction between objects Programmer does not care whether the method was executed on a local machine or remote The ORB (Object Request Broker) will take care of sending message between objects

What is CORBA (2/2) Create correct message Client object Stub skeleton ORB IIOP/GIOP ORB

What is CORBA (2/2) Create correct message Client object Stub skeleton ORB IIOP/GIOP ORB Translate messages to correct call

Interface Definition Language Define object type A specification language Use idl-compiler to generate stubs

Interface Definition Language Define object type A specification language Use idl-compiler to generate stubs and skeletons from IDL files C mapping C stub C skeleton . idl file Java mapping Java stub Java skeleton

IDL basics (1/2) IDL modules and interfaces n n Namespace and object definition #include

IDL basics (1/2) IDL modules and interfaces n n Namespace and object definition #include and #pragma are support IDL types n short , unsigned short, long… IDL methods n in, out, inout, oneway

IDL basics (2/2) #include “orange. idl” module Fruit. Basket { interface Apple { void

IDL basics (2/2) #include “orange. idl” module Fruit. Basket { interface Apple { void eat_me (in boolean eat_yes_or_not); boolean who_ate (out string who_name); // asynchronous method oneway boolean eaten (); }; };

C mapping (1/2) Language mapping n n Native representation of a CORBA-object GNOME is

C mapping (1/2) Language mapping n n Native representation of a CORBA-object GNOME is almost entirely written in C IDL C-mapping basics: methods and attributes n n All method-calls need an object reference as first parameter and a CORBA_Environment object as last parameter Mapping attribute to a _get-function and a _setfunction

C mapping (2/2) Module Fruits. Basket { interface Apple { void eat_me (in boolean

C mapping (2/2) Module Fruits. Basket { interface Apple { void eat_me (in boolean eat_yes_or_not); attribute boolean is_eaten; } } typedef CORBA_Object Fruits. Basket_Apple; void Fruits. Basket_Apple_eat_me (Fruit_Apple object, CORBA_boolean eat_yes_or_not, CORBA_Environment *ev); Fruits. Basket_Apple_set_is_eaten (…); CORBA_boolean Fruits. Basket_Apple_get_is_eaten (…);

The CORBA module (1/3) Use IDL to describe all standardized objects The ORB is

The CORBA module (1/3) Use IDL to describe all standardized objects The ORB is a CORBA object which has IDL interfaces Defined in CORBA spec: module CORBA { … } module IOR { … } …

The CORBA module (2/3) CORBA: : Object interface module CORBA { interface Object {

The CORBA module (2/3) CORBA: : Object interface module CORBA { interface Object { Interface. Def get_interface (); boolean is_nil (); Object duplicate (); void release (); boolean is_a (in string logical_type_id); boolean non_existant (); boolean is_equivalent (in Object other_object); unsigned long hash (in unsigned long maximum); }; }; This interface is implicitly inherited by all other interfaces

The CORBA module (3/3) CORBA: : ORB interface module CORBA { typedef string ORBid;

The CORBA module (3/3) CORBA: : ORB interface module CORBA { typedef string ORBid; type sequence <string> arg_list; ORB_init (inout arg_list argv, in ORBid orb_ideftifier); interface ORB { /* serialize function */ string object_to_string (in Object obj); Object string_to_object(in string str); }; }; Bootstrap function of the core ORB n CORBA: : ORB_init() Simple sample

Naming service Use to associate each object with a human readable string Bind and

Naming service Use to associate each object with a human readable string Bind and resolve Root Tree structure GNOME servers … GNOME. servers. Panel GNOME. servers. GMC … Panel

The POA interface (1/4) Clients hold object references on which that invoke methods Server

The POA interface (1/4) Clients hold object references on which that invoke methods Server object that implements the methods talks only to the POA and the server skeleton all cooperate to decide to which function the client request must be passed to. Server Servant POA Servant

The POA interface (2/4) The server registration n Create a POA and tell the

The POA interface (2/4) The server registration n Create a POA and tell the POA about its servants Ask the POA for an object reference Advertised to the outside world w IOR string w Binding this object reference to a name with the Naming Service IOR string Servant (2) (3) POA (1) Server Servant (3) Naming Service

The POA interface (3/4) A client request 1 n n Ask the Name Service

The POA interface (3/4) A client request 1 n n Ask the Name Service about some object reference and get a object reference The invocation is passed to the ORB through the stub, once the ORB find the correct server, it hands the request to the server (1) Naming Service Client (2) ORB

The POA interface (4/4) A client request 2 n n n The ORB pass

The POA interface (4/4) A client request 2 n n n The ORB pass request to the server The server then locate the POA which created the object reference and pass the request to the POA The request is finally passed to the correct servant by the POA (3) Servant (2) ORB (1) Server Servant

CORBA in GNOME (1/2) The Gnorba library n Initialization w Combine GTK+ event loop

CORBA in GNOME (1/2) The Gnorba library n Initialization w Combine GTK+ event loop with ORBit event loop w gnome_CORBA_init() n Naming service w gnome_name_service_get() The GOAD (GNOME Object Activation Directory) n n Find a server by its name Add servers to the GOAD w. gnorba files in /etc/CORBA or /urs/etc/CORBA

CORBA in GNOME (2/2) include <orb/orbit. h> #include <libgnorba/gnorba. h> #include <gnome. h> int

CORBA in GNOME (2/2) include <orb/orbit. h> #include <libgnorba/gnorba. h> #include <gnome. h> int main (int argc, char **argv) { CORBA_Object name_server; CORBA_Environment ev; CORBA_exception_init (&ev); orb = gnome_CORBA_init ("a simple gnorba test prgm", "v 1. 0", &argc, argv, &ev); name_server = gnome_name_service_get (); return 0; }

Reference Components in the GNOME Project GNOME & CORBA

Reference Components in the GNOME Project GNOME & CORBA