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.

Create a file called
shared.lisp
.

Enter the following Common Lisp code into the
shared.lisp
file:

(in-package "CL-USER")

(defparameter *hello-world-ior-file*

#+mswindows "c:/temp/hello.ior"

#-mswindows "/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:

object-to-file
opens the shared file and uses the
op:object_to_string
function to convert the object reference into a string, which is then written into the file

file-to-object
performs the inverse operation: it reads the string from the file and uses
op:string_to_object
to convert the string back into a client-side proxy object

Save and close the
shared.lisp
file.

Add
shared.lisp
to the defsystem by adding one line of code to the
defsys.lisp
file, which should then look like this: