home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / threaded / server.py < prev   
Text File  |  1999-06-28  |  3KB  |  104 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the DSTC Pty
  7. # Ltd.  Use of this software is strictly in accordance with the
  8. # license agreement in the accompanying LICENSE.HTML file.  If your
  9. # distribution of this software does not contain a LICENSE.HTML file
  10. # then you have no rights to use this software in any manner and
  11. # should contact DSTC at the address below to determine an appropriate
  12. # licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, Gehrmann Labs
  15. #      University of Queensland
  16. #      St Lucia, 4072
  17. #      Australia
  18. #      Tel: +61 7 3365 4310
  19. #      Fax: +61 7 3365 4311
  20. #      Email: enquiries@dstc.edu.au
  21. # This software is being provided "AS IS" without warranty of any
  22. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  23. # kind arising out of or in connection with the use or performance of
  24. # this software.
  25. #
  26. # Project:      Distributed Environment
  27. # File:         $Source: /units/arch/src/Fnorb/examples/threaded/RCS/server.py,v $
  28. # Version:      @(#)$RCSfile: server.py,v $ $Revision: 1.1 $
  29. #
  30. #############################################################################
  31. """ Implementation of the HelloWorldIF interface. """
  32.  
  33.  
  34. # Standard/built-in modules.
  35. import sys, thread
  36.  
  37. # Fnorb modules.
  38. from Fnorb.orb import BOA, CORBA
  39.  
  40. # Stubs and skeletons generated by 'fnidl'.
  41. import HelloWorld, HelloWorld_skel
  42.  
  43.  
  44. class HelloWorldServer(HelloWorld_skel.HelloWorldIF_skel):
  45.     """ Implementation of the 'HelloWorldIF' interface. """
  46.  
  47.     def hello_world(self, payload):
  48.     print HelloWorld.Message, thread.get_ident()
  49.     return
  50.  
  51. #############################################################################
  52.  
  53. def main(argv):
  54.     """ Do it! """
  55.  
  56.     print 'Initialising the ORB...'
  57.  
  58.     # Initialise the ORB.
  59.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  60.  
  61.     print 'Initialising the BOA...'
  62.  
  63.     # Initialise the BOA.
  64.     boa = BOA.BOA_init(argv, BOA.BOA_ID)
  65.  
  66.     print 'Creating object reference...'
  67.  
  68.     # Create an object reference ('fred' is the object key).
  69.     obj = boa.create('fred', HelloWorldServer._FNORB_ID)
  70.  
  71.     print 'Creating implementation...'
  72.  
  73.     # Create an instance of the implementation class.
  74.     impl = HelloWorldServer()
  75.  
  76.     print 'Activating the implementation...'
  77.  
  78.     # Activate the implementation (ie. connect the generated object reference
  79.     # to the implementation).  Note that the implementation will not receive
  80.     # any operation requests until we start the event loop (see below).
  81.     boa.obj_is_ready(obj, impl)
  82.  
  83.     # Write the stringified object reference to a file (this is just a 'cheap
  84.     # and cheerful' way of making the object reference available to the
  85.     # client!).
  86.     open('server.ref', 'w').write(orb.object_to_string(obj))
  87.  
  88.     print 'Server created and accepting requests...'
  89.  
  90.     # Start the event loop.
  91.     boa._fnorb_mainloop()
  92.  
  93.     return 0
  94.  
  95. #############################################################################
  96.  
  97. if __name__ == '__main__':
  98.     # Do it!
  99.     sys.exit(main(sys.argv))
  100.  
  101. #############################################################################
  102.