Next Previous Up Top Contents Index

2.1 A CORBA-based Hello World

2.1.3 Defining utilities for sharing an object reference

Now we will define some utilities for communicating an object reference from the server to the client by converting the object reference into a string using ORB-supplied functions and writing it to a shared file. The client can then read the string from the shared file and convert it back into an object reference. Note that a real application would probably use a higher level service such as a Name Service for passing object references between applications.

1. Create a file calledshared.lisp.
2. Enter the following Common Lisp code into theshared.lisp file:
(in-package "CL-USER")

(defparameter *hello-world-ior-file* #+Harlequin-PC-Lisp "c:/temp/hello.ior" #-Harlequin-PC-Lisp "/tmp/hello.ior")

(defun object-to-file (orb object) (with-open-file (st *hello-world-ior-file* :direction :output :if-exists :supersede) (prin1 (op:object_to_string orb object) st)))

(defun file-to-object (orb) (with-open-file (st *hello-world-ior-file*) (op:string_to_object orb (read st))))

This code does the following:

3. Save and close theshared.lisp file.
4. Addshared.lisp to the defsystem by adding one line of code to thedefsys.lisp file, which should then look like this:
(in-package "CL-USER")

(require "corba-orb")

(defsystem hello-world-corba-object () :members ( ("hello-world" :type :idl-file) "shared" ))

:rules ((:in-order-to :compile "all (:requires (:load :previous)))))

Developing Component Software with CORBA - 22 Jan 1999

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker