home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / misc / client.py next >
Text File  |  1999-06-28  |  4KB  |  126 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999, 1999
  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, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of any
  23. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  24. # kind arising out of or in connection with the use or performance of
  25. # this software.
  26. #
  27. # Project:      Fnorb
  28. # File:         $Source: /units/arch/src/Fnorb/examples/misc/RCS/client.py,v $
  29. # Version:      @(#)$RCSfile: client.py,v $ $Revision: 1.9 $
  30. #
  31. #############################################################################
  32. """ Client of the ExampleIF interface. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import sys
  37.  
  38. # Fnorb modules.
  39. from Fnorb.orb import CORBA
  40.  
  41. # Stubs generated by 'fnidl'.
  42. import Example
  43.  
  44.  
  45. def main(argv):
  46.     """ Do it! """
  47.  
  48.     print 'Initialising the ORB...'
  49.  
  50.     # Initialise the ORB.
  51.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  52.  
  53.     # Read the server's stringified IOR from a file.
  54.     stringified_ior = open('server.ref', 'r').read()
  55.  
  56.     # Convert the stringified IOR into an active object reference.
  57.     server = orb.string_to_object(stringified_ior)
  58.  
  59.     # Make sure that the server is not a 'nil object reference' (represented
  60.     # in Python by the value 'None').
  61.     if server is None:
  62.     raise 'Nil object reference!'
  63.  
  64.     # Make sure that the object implements the expected interface!
  65.     if not server._is_a('IDL:dstc.edu.au/Example/ExampleIF:1.0'):
  66.     raise 'This is not an "ExampleIF" server!'
  67.  
  68.     # Call the server!
  69.     print server.hello_world()
  70.  
  71.     print server.double_it(25)
  72.     print server.double_it_again(25)
  73.     print server.double_it_one_last_time(25)
  74.  
  75.     point = Example.ExampleIF.Point(20, 50)
  76.     new_point = server.move_by(point, 30, 50)
  77.  
  78.     print 'New point:', new_point.x, new_point.y
  79.  
  80.     server.take_that(Example.ExampleIF.OneOfThese(0, 123))
  81.     server.take_that(Example.ExampleIF.OneOfThese(1, 123.456))
  82.     server.take_that(Example.ExampleIF.OneOfThese(2, "Yowza!"))
  83.  
  84.     print server.ten_hello_worlds(['1', '2', '3', '4', '5',
  85.                    '6', '7', '8', '9', '10'])
  86.     print server.lots_of_hello_worlds(30)
  87.  
  88.     print "Next color:", server.next_color(Example.ExampleIF.red)
  89.     print "Next color:", server.next_color(Example.ExampleIF.green)
  90.     print "Next color:", server.next_color(Example.ExampleIF.blue)
  91.  
  92.     try:
  93.     server.get_beer()
  94.  
  95.     except Example.ExampleIF.DOH, ex:
  96.     print 'Got user exception:', ex.message
  97.  
  98.     try:
  99.     server.get_peanuts()
  100.  
  101.     except CORBA.SystemException, ex:
  102.     print 'Got system exception:', ex
  103.  
  104.     width = server._get_width()
  105.     print 'Width:', width
  106.     server._set_width(width+10)
  107.     width = server._get_width()
  108.     print 'Width:', width
  109.  
  110.     print 'Quality:', server._get_quality()
  111.  
  112.     print 'Close down the server!'
  113.     server.quit()
  114.  
  115.     return 0
  116.  
  117. #############################################################################
  118.  
  119. if __name__ == '__main__':
  120.     # Do it!
  121.     sys.exit(main(sys.argv))
  122.  
  123. #############################################################################
  124.