home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / Lib / site-packages / Fnorb / orb / IIOPProtocol.py < prev    next >
Text File  |  1999-06-28  |  5KB  |  155 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/orb/RCS/IIOPProtocol.py,v $
  29. # Version:      @(#)$RCSfile: IIOPProtocol.py,v $ $Revision: 1.8 $
  30. #
  31. #############################################################################
  32. """ IIOP Protocol module. """
  33.  
  34.  
  35. # Fnorb modules.
  36. import CORBA, IIOP, IOP, Nudger, Protocol, Reactor
  37.  
  38. # IIOP protocol modules.
  39. import IIOPAcceptor, IIOPConnection
  40.  
  41.  
  42. class IIOPProtocol(Protocol.Protocol):
  43.     """ IIOP Protocol. """
  44.  
  45.     #########################################################################
  46.     # Protocol interface.
  47.     #########################################################################
  48.  
  49.     def enable(self, host, port):
  50.     """ Create an endpoint for connection requests. """
  51.  
  52.     # Create/initialise a reactor.
  53.     self.__reactor = Reactor.Reactor_init()
  54.  
  55.     # Create an acceptor to listen for client connection requests.
  56.     self.__acceptor = IIOPAcceptor.IIOPAcceptor((host, port))
  57.  
  58.     # Create a nudger.
  59.     self.__nudger = Nudger.Nudger()
  60.  
  61.     return
  62.  
  63.     def disable(self):
  64.     """ Destroy the endpoint that is listening for connection requests. """
  65.  
  66.     pass
  67.  
  68.     def start(self, timeout=0):
  69.     """ Start the protocol event loop. """
  70.  
  71.     # Start the reactor's event loop.
  72.     self.__reactor.start_event_loop(timeout)
  73.  
  74.     return
  75.  
  76.     def stop(self):
  77.     """ Stop the protocol event loop. """
  78.  
  79.     # Stop the reactor's event loop.
  80.     self.__reactor.stop_event_loop()
  81.  
  82.     # Give the reactor a nudge so that it can realise that it has been
  83.     # stopped!
  84.     self.__nudger.nudge()
  85.  
  86.     return
  87.  
  88.     def create_connection(self):
  89.     """ Create a connection. """
  90.  
  91.     return IIOPConnection.IIOPConnection()
  92.  
  93.     def create_profile(self, id):
  94.     """ Create an IOR profile for the protocol. """
  95.  
  96.     # Get the host and port number of the acceptor.
  97.     (host, port) = self.__acceptor.address()
  98.     
  99.     # Create an IIOP tagged profile.
  100.     version = IIOP.Version(chr(1), chr(0))
  101.     profile_body = IIOP.ProfileBody(version, host, port, id)
  102.     profile = IOP.TaggedProfile(IOP.TAG_INTERNET_IOP, profile_body)
  103.  
  104.     return profile
  105.  
  106.     def get_object_key(self, ior):
  107.     """ Extract the object key from an IOR. """
  108.  
  109.     try:
  110.         # If the object reference does NOT contain an IIOP profile, then
  111.         # this call will raise an 'INV_OBJREF' exception.
  112.         object_key = ior._fnorb_iiop_profile().object_key
  113.  
  114.     except CORBA.INV_OBJREF:
  115.         object_key = None
  116.  
  117.     return object_key
  118.  
  119.     def get_address(self, ior):
  120.     """ Extract the address from an IOR. """
  121.  
  122.     try:
  123.         # If the object reference does NOT contain an IIOP profile, then
  124.         # this call will raise an 'INV_OBJREF' exception.
  125.         iiop_profile = ior._fnorb_iiop_profile()
  126.         address = (iiop_profile.host, iiop_profile.port)
  127.  
  128.     except CORBA.INV_OBJREF:
  129.         address = None
  130.  
  131.     return address
  132.  
  133.     def is_local(self, ior):
  134.     """ Does the IOR reference an object in *this* ORB? """
  135.  
  136.     try:
  137.         # If the object reference does NOT contain an IIOP profile, then
  138.         # this call will raise an 'INV_OBJREF' exception.
  139.         iiop_profile = ior._fnorb_iiop_profile()
  140.  
  141.         # Get the host and port number of the acceptor.
  142.         (host, port) = self.__acceptor.address()
  143.  
  144.         # Is the object in *this* ORB?
  145.         result = (iiop_profile.host == host and iiop_profile.port == port)
  146.  
  147.     except CORBA.INV_OBJREF:
  148.         result = 0
  149.         
  150.     return result
  151.  
  152. #############################################################################
  153.