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

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 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/unions/RCS/client.py,v $
  29. # Version:      @(#)$RCSfile: client.py,v $ $Revision: 1.7 $
  30. #
  31. #############################################################################
  32. """ Example client using IDL unions. """
  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 Unions
  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 IOR from a file.
  54.     stringified_ior = open('server.ref', 'r').read()
  55.  
  56.     print 'Creating active object reference...'
  57.  
  58.     # Convert the stringified IOR into an active object reference.
  59.     server = orb.string_to_object(stringified_ior)
  60.  
  61.     # Make sure that the server is not a 'nil object reference' (represented
  62.     # in Python by the value 'None').
  63.     if server is None:
  64.     raise 'Nil object reference!'
  65.  
  66.     # Make sure that the object implements the expected interface!
  67.     if not server._is_a('IDL:dstc.edu.au/Unions/test:1.0'):
  68.     raise 'This is not a "test" server!'
  69.  
  70.     # 'in' parameters.
  71.     server.in_a(Unions.A(1, 123))
  72.     server.in_a(Unions.A(0, 'Hello'))
  73.  
  74.     server.in_b(Unions.B(1, 123))
  75.     server.in_b(Unions.B(0, 'Hello'))
  76.  
  77.     server.in_c(Unions.C(1, 123))
  78.     server.in_c(Unions.C(0, 'Hello'))
  79.  
  80.     server.in_d(Unions.D(Unions.red, 123))
  81.     server.in_d(Unions.D(Unions.green, 123.456))
  82.     server.in_d(Unions.D(Unions.blue, 'Hello Bluey'))
  83.  
  84.     server.in_e(Unions.E(Unions.red, 123))
  85.     server.in_e(Unions.E(Unions.green, 123.456))
  86.     server.in_e(Unions.E(Unions.blue, 'Hello Bluey'))
  87.  
  88.     server.in_f(Unions.F(Unions.red, 123))
  89.     server.in_f(Unions.F(Unions.green, 'Hello Greeny'))
  90.     server.in_f(Unions.F(Unions.blue, 'Hello Bluey'))
  91.  
  92.     # 'inout' parameters.
  93.     print server.inout_a(Unions.A(1, 123))
  94.     print server.inout_a(Unions.A(0, 'Hello'))
  95.  
  96.     print server.inout_b(Unions.B(1, 123))
  97.     print server.inout_b(Unions.B(0, 'Hello'))
  98.  
  99.     print server.inout_c(Unions.C(1, 123))
  100.     print server.inout_c(Unions.C(0, 'Hello'))
  101.  
  102.     server.inout_d(Unions.D(Unions.red, 123))
  103.     server.inout_d(Unions.D(Unions.green, 123.456))
  104.     server.inout_d(Unions.D(Unions.blue, 'Hello Bluey'))
  105.  
  106.     server.inout_e(Unions.E(Unions.red, 123))
  107.     server.inout_e(Unions.E(Unions.green, 123.456))
  108.     server.inout_e(Unions.E(Unions.blue, 'Hello Bluey'))
  109.  
  110.     server.inout_f(Unions.F(Unions.red, 123))
  111.     server.inout_f(Unions.F(Unions.green, 'Hello Greeny'))
  112.     server.inout_f(Unions.F(Unions.blue, 'Hello Bluey'))
  113.  
  114.     # 'out' parameters.
  115.     print server.out_a()
  116.     print server.out_b()
  117.     print server.out_c()
  118.     print server.out_d()
  119.     print server.out_e()
  120.     print server.out_f()
  121.  
  122.     # Return values.
  123.     print server.return_a()
  124.     print server.return_b()
  125.     print server.return_c()
  126.     print server.return_d()
  127.     print server.return_e()
  128.     print server.return_f()
  129.  
  130.     return 0
  131.  
  132. #############################################################################
  133.  
  134. if __name__ == '__main__':
  135.     # Do it!
  136.     sys.exit(main(sys.argv))
  137.  
  138. #############################################################################
  139.