home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / unions / server.py < prev    next >
Text File  |  1999-06-28  |  6KB  |  231 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/server.py,v $
  29. # Version:      @(#)$RCSfile: server.py,v $ $Revision: 1.8 $
  30. #
  31. #############################################################################
  32. """ Example server using IDL unions. """
  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 Unions, Unions_skel
  43.  
  44.  
  45. class Server(Unions_skel.test_skel):
  46.     """ Implementation of the 'test' interface. """
  47.  
  48.     # 'in' parameters.
  49.     def in_a(self, a):
  50.     print a
  51.     return
  52.  
  53.     def in_b(self, b):
  54.     print b
  55.     return
  56.  
  57.     def in_c(self, c):
  58.     print c
  59.     return
  60.  
  61.     def in_d(self, d):
  62.     print d
  63.     return
  64.  
  65.     def in_e(self, e):
  66.     print e
  67.     return
  68.  
  69.     def in_f(self, f):
  70.     print f
  71.     return
  72.  
  73.     # 'inout' parameters.
  74.     def inout_a(self, a):
  75.     print (a.d, a.v)
  76.     if a.d == 1:
  77.         a.v = a.v + 1
  78.  
  79.     else:
  80.         a.v = "Hello to you too!"
  81.  
  82.     return a
  83.  
  84.     def inout_b(self, b):
  85.     print (b.d, b.v)
  86.     if b.d == 1:
  87.         b.v = b.v + 1
  88.  
  89.     else:
  90.         b.v = "Hello to you too!"
  91.  
  92.     return b
  93.  
  94.     def inout_c(self, c):
  95.     print (c.d, c.v)
  96.     if c.d == 1:
  97.         c.v = c.v + 1
  98.  
  99.     else:
  100.         c.v = "Hello to you too!"
  101.  
  102.     return c
  103.  
  104.     def inout_d(self, d):
  105.     print 'inout_d:', d, d.d, d.v
  106.     print (d.d, d.v)
  107.     if d.d == Unions.red:
  108.         d.v = d.v + 1
  109.  
  110.     elif d.d == Unions.green:
  111.         d.v = d.v + 1.0
  112.  
  113.     elif d.d == Unions.blue:
  114.         d.v = d.v + " ... and there's more"
  115.  
  116.     print 'inout_d:', d, d.d, d.v
  117.     return d
  118.  
  119.     def inout_e(self, e):
  120.     print (e.d, e.v)
  121.     if e.d == Unions.red:
  122.         e.v = e.v + 1
  123.  
  124.     else:
  125.         e.v = "Whatever I put here should disappear!"
  126.  
  127.     return e
  128.  
  129.     def inout_f(self, f):
  130.     print (f.d, f.v)
  131.     if f.d == Unions.red:
  132.         f.v = f.v + 1
  133.  
  134.     else:
  135.         f.v = "But this should get back as the default case!"
  136.  
  137.     return f
  138.  
  139.     # 'out' parameters.
  140.     def out_a(self):
  141.     return Unions.A(0, 'How are you?')
  142.  
  143.     def out_b(self):
  144.     return Unions.B(0, 'This value should be None in the client!')
  145.  
  146.     def out_c(self):
  147.     return Unions.C(0, 'This one should get through as the default!')
  148.  
  149.     def out_d(self):
  150.     return Unions.D(Unions.blue, 'How are you?')
  151.  
  152.     def out_e(self):
  153.     return Unions.E(Unions.blue, 'This value should be None in the client')
  154.  
  155.     def out_f(self):
  156.     return Unions.F(Unions.blue, 'This one should get thru as the default')
  157.  
  158.     # Return values.
  159.     def return_a(self):
  160.     return Unions.A(0, 'Is anybody out there?')
  161.  
  162.     def return_b(self):
  163.     return Unions.B(0, 'This value should be None in the client!')
  164.  
  165.     def return_c(self):
  166.     return Unions.C(0, 'This one should get through as the default!')
  167.  
  168.     def return_d(self):
  169.     return Unions.D(Unions.blue, 'Is anybody out there?')
  170.  
  171.     def return_e(self):
  172.     return Unions.E(Unions.blue, 'This value should be None in the client')
  173.  
  174.     def return_f(self):
  175.     return Unions.F(Unions.blue, 'This one should get thru as the default')
  176.     
  177.  
  178. def main(argv):
  179.     """ Do it! """
  180.     
  181.     print 'Initialising the ORB...'
  182.  
  183.     # Initialise the ORB.
  184.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  185.  
  186.     print 'Initialising the BOA...'
  187.  
  188.     # Initialise the BOA.
  189.     boa = BOA.BOA_init(sys.argv, BOA.BOA_ID)
  190.  
  191.     print 'Creating object reference...'
  192.  
  193.     # Create an object reference ('fred' is the object key).
  194.     obj = boa.create('fred', Server._FNORB_ID)
  195.  
  196.     print 'Creating implementation...'
  197.  
  198.     # Create an instance of the implementation class.
  199.     impl = Server()
  200.  
  201.     print 'Activating the implementation...'
  202.  
  203.     # Activate the implementation (ie. connect the generated object reference
  204.     # to the implementation).  Note that the implementation will not receive
  205.     # any operation requests until we start the event loop (see below).
  206.     boa.obj_is_ready(obj, impl)
  207.  
  208.     # Write the stringified object reference to a file (this is just a 'cheap
  209.     # and cheerful' way of making the object reference available to the
  210.     # client!).
  211.     open('server.ref', 'w').write(orb.object_to_string(obj))
  212.  
  213.     print 'Server created and accepting requests...'
  214.  
  215.     # Start the event loop.
  216.     boa._fnorb_mainloop()
  217.  
  218.     print 'Server finished!'
  219.  
  220.     return 0
  221.  
  222. #############################################################################
  223.  
  224. if __name__ == '__main__':
  225.     # Do it!
  226.     sys.exit(main(sys.argv))
  227.  
  228. #############################################################################
  229.