Next Prev Up Top Contents Index

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 called shared.lisp .
  2. Enter the following Common Lisp code into the shared.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:

(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 - 14 Dec 2001

Next Prev Up Top Contents Index