All Manuals > Developing Component Software with CORBA > 2 Quick Start Tutorial > 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 called shared.lisp .
  2. 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:

(in-package "CL-USER") (require "corba-orb")
(defsystem hello-world-corba-object ()
  :members (
            ("hello-world" :type :idl-file)
:rules ((:in-order-to :compile :all
         (:requires (:load :previous)))))

Developing Component Software with CORBA - 29 Jul 2010