All Manuals > Developing Component Software with CORBA® > 2 Quick Start Tutorial

2.2 Complete source code for the Hello World example

The complete source code for the Hello World application is included here for your convenience. It can also be found in the corba/hello-world subdirectory of the standard examples directory.

2.2.1 The complete interface source code

The complete code for the Hello World interface (the hello-world.idl file), written in IDL, is:

module HelloWorld {
  interface world {
    string hello();
  };
};

2.2.2 The complete defsystem source code

The complete code for the Hello World defsystem (the defsys.lisp file) is:

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

2.2.3 The complete source code for the file transfer of the IOR

The complete code for the Interoperable Object Reference (IOR) file transfer (the shared.lisp file) is:

(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))))

2.2.4 The complete Hello World client source code

The complete code for the Hello World client (the hello-world-client.lisp file) is:

(in-package "CL-USER")
 
(defun run-client ()
  (let ((orb (op:orb_init nil "LispWorks ORB")))
    (let ((world (op:narrow 'HelloWorld:world (file-to-object
                                               orb))))
      (format t "~S~%" (op:hello world)))))

2.2.5 The complete Hello World server source code

The complete code for the Hello World server (the hello-world-server.lisp file) is:

(in-package "CL-USER")
 
(defclass world-implementation (HelloWorld:world-servant) ())
 
(corba:define-method op:hello ((self world-implementation))
  (declare (ignore self))
  "Hello World!")
 
(defun server-startup ()
  (let* ((orb (op:orb_init nil "LispWorks ORB"))
         (poa (op:resolve_initial_references orb "RootPOA"))
         (impl (make-instance 'world-implementation))
         (world (op:narrow 'HelloWorld:world
                           (op:servant_to_reference poa impl))))
    (object-to-file orb world)
    (let ((manager (op:the_poamanager poa)))
      (op:activate manager))))

Developing Component Software with CORBA® - 01 Dec 2021 19:38:36