340 likes | 628 Views
Components in GNOME. 林咸禮. Outline. Components in GNOME Why object model ? The uses of CORBA Implementation notes ORBit Programming. Why object model ? (1/3). UNIX pipe system Allow users to create new results by joining smaller components. > ls | more. orbit-docs.tar.gz orbit.zip ….
E N D
Outline • Components in GNOME • Why object model ? • The uses of CORBA • Implementation notes • ORBit Programming
Why object model ? (1/3) • UNIX pipe system • Allow users to create new results by joining smaller components. • > ls | more orbit-docs.tar.gz orbit.zip … ls More pipe
Why object model ? (2/3) • Pipe in modern desktop environment • The information flow is unidirectional • Characters, lines, and entire files are basic unit of information exchange. • Not scale well with complex application • Solution • Component based programming framework • But UNIX lacks such a framework
Why object model ? (3/3) • GNOME provides a component model • Based on OMG’s CORBA • Adapt ORBit implementation Object D CORBA Object A Object B Object C
The uses of CORBA in GNOME • Exporting an application’s API • General IPC and RPC mechanism • Scripting • Automate common tasks • Define system services • Standard interfaces • Bonobo • Document based application
Exporting an application’s API • Export internal engine • Use interfaces in GNOME::Gnumeric • Guppi can manipulate a spreadsheet in gnumeric • Standard interfaces to implement • Desktop::Editor • A mail client can choose any Editor that implement Desktop::Editor
IPC and RPC Mechanism (1/4) • Process communication • In traditional UNIX world • IPC: shared memory, pipe… • RPC: TCP/IP • IPC/RPC protocols are hand-crafted individually • Hard to maintain and too efforts on details Hand-crafted protocol Program1 Program2 RPC/IPC codes RPC/IPC codes IPC / RPC
IPC and RPC Mechanism (2/4) • CORBA provide object location transparency Program1 Program2 Handle by ORB Object reference Remote Object Stub skeleton CORBA Programmer’s view
IPC and RPC Mechanism (3/4) • Currently use: • Communicate with embedded applications • GNOME Control and GNOME Panel • Modify a “live” application • Changes happen to the current server on the fly • Mod_CORBA apache module, Dents DNS Server)
IPC and RPC Mechanism (4/4) embedded program
Scripting • Allow user to automate common tasks • Like macro and VBA in Windows • Manipulate a gnumeric spreadsheet, automate some repetitive tasks… • Major scripting languages on UNIX have CORBA binding • Such as Perl, Python and Java
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 • Encapsulate details by CORBA-based server • System::admin::user • System::Mail::deliver
Bonobo (1/2) • GNOME Document model • Let document-based applications embed themselves in each other • Similar with OLE and ActiveX in Windows
Bonobo (2/2) • Embed many programs in gnumeric
Implementation notes • ORBit • CORBA implementation on GNOME • Written in straight C, but have many language binding • GNORBA • Wrapper of common CORBA services in GNOME • Name server and the initialization code • Allow to create specific application name server • Start automatically when needed
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) Client object Create correct message Stub skeleton Translate messages to correct call ORB IIOP/GIOP ORB
Interface Definition Language • Define object type • A specification language • Use idl-compiler to generate stubs and skeletons from IDL files C stub C mapping C skeleton .idl file Java stub Java mapping Java skeleton
IDL basics (1/2) • IDL modules and interfaces • Namespace and object definition • #include and #pragma are support • IDL types • short , unsigned short, long, long long… • IDL methods • in, out, inout, oneway
IDL basics (2/2) • #include “orange.idl”module FruitBasket { 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 • Native representation of a CORBA-object • GNOME is almost entirely written in C • IDL C-mapping basics: methods and attributes • 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 _set-function
C mapping (2/2) • Module FruitsBasket { interface Apple { void eat_me (in boolean eat_yes_or_not); attribute boolean is_eaten; }} • typedef CORBA_Object FruitsBasket_Apple;void FruitsBasket_Apple_eat_me (Fruit_Apple object, CORBA_boolean eat_yes_or_not, CORBA_Environment *ev); FruitsBasket_Apple_set_is_eaten (…);CORBA_boolean FruitsBasket_Apple_get_is_eaten (…);
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 interfacemodule CORBA { interface Object { InterfaceDef 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; type sequence <string> arg_list; ORB 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 • CORBA::ORB_init() • Simple sample
Naming service • Use to associate each object with a human readable string • Bind and resolve • Tree structure Root GNOME servers … GNOME.servers.Panel GNOME.servers.GMC … Panel GMC
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 • 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 • Create a POA and tell the POA about its servants • Ask the POA for an object reference • Advertised to the outside world • IOR string • Binding this object reference to a name with the Naming Service IOR string Servant (3) (2) Naming Service POA (1) (3) Servant Server
The POA interface (3/4) • A client request 1 • 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 Naming Service (1) Client (2) ORB
The POA interface (4/4) • A client request 2 • 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 POA Servant (3) (2) (1) ORB Server Servant
CORBA in GNOME (1/2) • The Gnorba library • Initialization • Combine GTK+ event loop with ORBit event loop • gnome_CORBA_init() • Naming service • gnome_name_service_get() • The GOAD (GNOME Object Activation Directory) • Find a server by its name • Add servers to the GOAD • .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 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