home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / misc / server.py < prev   
Text File  |  1999-06-28  |  5KB  |  188 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/server.py,v $
  29. # Version:      @(#)$RCSfile: server.py,v $ $Revision: 1.13 $
  30. #
  31. #############################################################################
  32. """ Implementation of the ExampleIF interface. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import sys
  37.  
  38. # Fnorb modules.
  39. from Fnorb.orb import BOA, CORBA
  40.  
  41. # Stubs and skeletons generated by 'fnidl'.
  42. import Example, Example_skel
  43.  
  44.  
  45. class ExampleServer(Example_skel.ExampleIF_skel):
  46.     """ Implementation of the 'ExampleIF' interface. """
  47.  
  48.     def __init__(self):
  49.  
  50.     # Base class constructor.
  51.     CORBA.Object_skel.__init__(self)
  52.  
  53.     self.width = 100
  54.     self.quality = 'shoddy!'
  55.     return
  56.  
  57.     def hello_world(self):
  58.     return "Hello CORBA World!"
  59.  
  60.     # Ok, spot the difference ;^)
  61.     def double_it(self, n):
  62.     return n * 2
  63.  
  64.     def double_it_again(self, n):
  65.     return n * 2
  66.  
  67.     def double_it_one_last_time(self, n):
  68.     return n * 2
  69.     
  70.     def move_by(self, p, delta_x, delta_y):
  71.  
  72.     return Example.ExampleIF.Point(p.x + delta_x, p.y + delta_y)
  73.  
  74.     def take_that(self, u):
  75.  
  76.     (discriminator, value) = (u.d, u.v)
  77.     if discriminator == 0:
  78.         print 'Got long', value
  79.  
  80.     elif discriminator == 1:
  81.         print 'Got float', value
  82.  
  83.     else:
  84.         print 'Got string', value
  85.  
  86.     return
  87.  
  88.     def ten_hello_worlds(self, x):
  89.  
  90.     return ["hello world"] * 10
  91.  
  92.     def lots_of_hello_worlds(self, n):
  93.     
  94.     return ["hello world"] * n
  95.  
  96.     def next_color(self, c):
  97.  
  98.     if c == Example.ExampleIF.red:
  99.         next = Example.ExampleIF.green
  100.  
  101.     elif c == Example.ExampleIF.green:
  102.         next = Example.ExampleIF.blue
  103.  
  104.     else:
  105.         next = Example.ExampleIF.red
  106.  
  107.     return next
  108.  
  109.     def get_beer(self):
  110.  
  111.     raise Example.ExampleIF.DOH("Moe's is shut!")
  112.  
  113.     def get_peanuts(self):
  114.  
  115.     raise CORBA.NO_MEMORY()
  116.  
  117.     def _get_width(self):
  118.     return self.width
  119.  
  120.     def _set_width(self, width):
  121.     self.width = width
  122.     return
  123.  
  124.     def _get_quality(self):
  125.     return self.quality
  126.  
  127.  
  128.     def quit(self):
  129.  
  130.     boa = BOA.BOA_init()
  131.     boa._fnorb_quit()
  132.  
  133.     return
  134.  
  135. def main(argv):
  136.     """ Do it! """
  137.  
  138.     print 'Initialising the ORB...'
  139.  
  140.     # Initialise the ORB.
  141.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  142.  
  143.     print 'Initialising the BOA...'
  144.  
  145.     # Initialise the BOA.
  146.     boa = BOA.BOA_init(argv, BOA.BOA_ID)
  147.  
  148.     print 'Creating object reference...'
  149.  
  150.     # Create an object reference ('fred' is the object key).
  151.     obj = boa.create('fred', ExampleServer._FNORB_ID)
  152.  
  153.     print 'Creating implementation...'
  154.  
  155.     # Create an instance of the implementation class.
  156.     impl = ExampleServer()
  157.  
  158.     print 'Activating the implementation...'
  159.  
  160.     # Activate the implementation (ie. connect the generated object reference
  161.     # to the implementation).  Note that the implementation will not receive
  162.     # any operation requests until we start the event loop (see below).
  163.     boa.obj_is_ready(obj, impl)
  164.  
  165.     # Write the stringified object reference to a file (this is just a 'cheap
  166.     # and cheerful' way of making the object reference available to the
  167.     # client!).
  168.     open('server.ref', 'w').write(orb.object_to_string(obj))
  169.  
  170.     print 'Server created and accepting requests...'
  171.  
  172.     # Start the event loop.
  173.     boa._fnorb_mainloop()
  174.  
  175.     print 'Server complete!'
  176.  
  177.     return 0
  178.  
  179. #############################################################################
  180.  
  181. if __name__ == '__main__':
  182.     # Do it!
  183.     sys.exit(main(sys.argv))
  184.  
  185. #############################################################################
  186.