home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / naming / client.py next >
Encoding:
Python Source  |  1999-06-28  |  3.3 KB  |  100 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/naming/RCS/client.py,v $
  29. # Version:      @(#)$RCSfile: client.py,v $ $Revision: 1.2 $
  30. #
  31. #############################################################################
  32. """ An example of a client using the naming service. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import sys
  37.  
  38. # Fnorb modules.
  39. from Fnorb.orb import CORBA
  40.  
  41. # Naming Service modules.
  42. from Fnorb.cos.naming import CosNaming
  43.  
  44. # Stubs generated by 'fnidl'.
  45. import Thermometer
  46.  
  47.  
  48. def main(argv):
  49.     """ Do it! """
  50.  
  51.     print 'Initialising the ORB...'
  52.  
  53.     # Initialise the ORB.
  54.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  55.  
  56.     # Get a reference to the initial naming service context.
  57.     ctx = CORBA.ORB_init().resolve_initial_references("NameService")
  58.  
  59.     # The 'pathname' of the context that holds the thermometer references (kind
  60.     # of equivalent to '/dev/thermometers').
  61.     path = [CosNaming.NameComponent('dev', ''),
  62.         CosNaming.NameComponent('thermometers', '')]
  63.  
  64.     # Lookup the temperatures of the thermometers in rooms 101-105, and then
  65.     # force a lookup on a non-existent room "106"!
  66.     for room in ["101", "102", "103", "104", "105", "106"]:
  67.     # Create a naming service 'name' for the thermometer.
  68.     name = path + [CosNaming.NameComponent(room, '')]
  69.  
  70.     try:
  71.         # Lookup the thermometer in the naming service.
  72.         thermometer = ctx.resolve(name)
  73.  
  74.         # Make sure that the object is not a 'nil object reference'
  75.         # (represented in Python by the value 'None').
  76.         if thermometer is None:
  77.         raise 'Nil object reference!'
  78.  
  79.         # Make sure that the object implements the expected interface!
  80.         if not thermometer._is_a(CORBA.id(Thermometer.ThermometerIF)):
  81.         raise 'This is not a Thermometer!'
  82.  
  83.         # Get the temperature of the thermometer!
  84.         print 'Temperature in', room, 'is', thermometer._get_temperature()
  85.  
  86.     except CosNaming.NamingContext.NotFound:
  87.         print 'No thermometer in room', room
  88.  
  89.     return 0
  90.  
  91. #############################################################################
  92.  
  93. if __name__ == '__main__':
  94.     # Do it!
  95.     sys.exit(main(sys.argv))
  96.  
  97. #############################################################################
  98.