commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src/commdrivers _helpers/ObjectLibr...


From: Jason Cater
Subject: gnue/common/src/commdrivers _helpers/ObjectLibr...
Date: Wed, 19 Dec 2001 02:50:27 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/12/19 02:50:27

Modified files:
        common/src/commdrivers/_helpers: ObjectLibrarian.py 
        common/src/commdrivers/_parser: Parser.py 
        common/src/commdrivers/xmlrpc: ServerAdapter.py 

Log message:
        added object support via object-by-reference

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/_parser/Parser.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py
diff -c gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py:1.1 
gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py:1.2
*** gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py:1.1 Sun Nov  4 
13:34:37 2001
--- gnue/common/src/commdrivers/_helpers/ObjectLibrarian.py     Wed Dec 19 
02:50:26 2001
***************
*** 28,54 ****
  # NOTES:
  #
  
  
  class InvalidObjectReference(StandardError):
    pass
  
  _objects = {}
  
  def getObjectReference(object):
    try:
!     return object.__id
    except AttributeError:
!     # TODO: This might not be secure to use as a handle
!     object.__id = hex(id(object))
!     return object.__id
  
  
  def archiveObject(object):
!   try:
!     ref = object.__refid
!   except AttributeError:
!     ref = getObjectReference(object)
!     _objects[ref] = object
  
  
  def retrieveObject(handle):
--- 28,58 ----
  # NOTES:
  #
  
+ import sha, time
  
  class InvalidObjectReference(StandardError):
    pass
  
  _objects = {}
+ _index = 0.0
+ 
  
  def getObjectReference(object):
    try:
!     return object._ObjectLibrarian__refid
    except AttributeError:
! 
!     # This is to introduce some obscurity to the id handles...
!     global _index
!     _index += time.clock()
!     object._ObjectLibrarian__refid = \
!         sha.new("%s%s%s"%(id(object), object, _index)).hexdigest()
! 
!     return object._ObjectLibrarian__refid
  
  
  def archiveObject(object):
!   _objects[getObjectReference(object)] = object
  
  
  def retrieveObject(handle):
***************
*** 58,60 ****
--- 62,71 ----
      raise InvalidObjectReference
  
  
+ def deferenceObject(object):
+   try:
+     del _objects[object._ObjectLibrarian__refid]
+   except KeyError:
+     pass
+   except AttributeError:
+     pass
Index: gnue/common/src/commdrivers/_parser/Parser.py
diff -c gnue/common/src/commdrivers/_parser/Parser.py:1.3 
gnue/common/src/commdrivers/_parser/Parser.py:1.4
*** gnue/common/src/commdrivers/_parser/Parser.py:1.3   Thu Dec  6 18:19:42 2001
--- gnue/common/src/commdrivers/_parser/Parser.py       Wed Dec 19 02:50:27 2001
***************
*** 132,138 ****
                 'Typecast': GTypecast.name,
                 'Required': 1 },
              'readonly': {
!                'Typecast': GTypecast.boolean } },
           'ParentTags': ('object',) },
  
        'exception': {
--- 132,142 ----
                 'Typecast': GTypecast.name,
                 'Required': 1 },
              'readonly': {
!                'Typecast': GTypecast.boolean,
!                'Default': 0 },
!             'writeonly': {
!                'Typecast': GTypecast.boolean,
!                'Default': 0 } },
           'ParentTags': ('object',) },
  
        'exception': {
Index: gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py
diff -c gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.3 
gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.4
*** gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py:1.3     Tue Dec 18 
23:05:45 2001
--- gnue/common/src/commdrivers/xmlrpc/ServerAdapter.py Wed Dec 19 02:50:27 2001
***************
*** 46,52 ****
  from gnue.common.commdrivers._helpers import ObjectLibrarian
  
  from gnue.common.commdrivers import GCommBase
! from gnue.common import GComm
  
  import string, sys
  
--- 46,52 ----
  from gnue.common.commdrivers._helpers import ObjectLibrarian
  
  from gnue.common.commdrivers import GCommBase
! from gnue.common import GComm, GDebug
  
  import string, sys
  
***************
*** 82,87 ****
--- 82,91 ----
      HTTPServer.__init__(self, params)
  
  
+     # Keep a directory of all methods we expose and
+     # various attributes of those methods (such as
+     # "signatures" [as defined by the XML-RPC docs]
+     # and help/description information.
      self.directory = {
         'system.listMethods':
             { 'signature': ('string',),
***************
*** 99,108 ****
         }
  
  
!     # Create our internal "service directory"
      self._xmlrpc_mapObjects(rpcdef)
  
!     print self.directory
  
  
    #
--- 103,116 ----
         }
  
  
!     # Add all the grpc defined methods
!     # to our internal "service directory"
      self._xmlrpc_mapObjects(rpcdef)
  
!     GDebug.printMesg(3,'XML-RPC Service Directory:\n * %s' % \
!             string.join(self.directory.keys(),'\n * '))
!     GDebug.printMesg(5,'XML-RPC Service Directory:\n%s' % \
!             self.directory.keys())
  
  
    #
***************
*** 131,136 ****
--- 139,150 ----
        else:
          signature.append(None)
  
+       # To make "Object" definitions with w/non-object RPC,
+       # the first parameters to any "Object" methods are
+       # a "passed reference"
+       if parent._type == 'RpObject':
+         signature.append(_datatypeMap['string'])
+ 
        # Then add the argument datatypes...
        for arg in object._arguments:
          signature.append(_datatypeMap[arg.type])
***************
*** 143,169 ****
            'binding': None   } # TODO
  
  
!     # Add all methods to our directory
      if object._type == 'RpAttribute':
  
!       # Add the directory entry
!       self.directory['%s.get_%s' % (parent._xmlrpc__path, object.name)] = \
!         { 'signature': (object.type,),
!           'help': '',         # TODO
!           'binding': None   } # TODO
! 
!       # Add the directory entry
!       self.directory['%s.set_%s' % (parent._xmlrpc__path, object.name)] = \
!         { 'signature': (None, object.type),
!           'help': '',         # TODO
!           'binding': None   } # TODO
  
  
  
      # Now, map our children
      for child in object._children:
        self._xmlrpc_mapObjects(child, object)
  
  
    #
    # Return an exception
--- 157,201 ----
            'binding': None   } # TODO
  
  
!     #
!     # Add all attribute methods to our directory..
!     # XML-RPC doesn't support "Attributes", so an
!     # attribute is exposed as a pair of get_<name>
!     # and set_<name> methods.
!     #
      if object._type == 'RpAttribute':
  
!       # To simulate "Object" definitions with w/this
!       # non-object RPC, the first parameters to any
!       # "Object" methods are a "passed reference"
!       if parent._type == 'RpObject':
!         getsig = (_datatypeMap[object.type], _datatypeMap['string'])
!         setsig = (None, _datatypeMap['string'], _datatypeMap[object.type])
!       else:
!         getsig = (_datatypeMap[object.type],)
!         setsig = (None, _datatypeMap[object.type])
  
+       if not object.readonly:
+         # Add the get_* directory entry
+         self.directory['%s.get_%s' % (parent._xmlrpc__path, object.name)] = \
+           { 'signature': getsig,
+             'help': '',         # TODO
+             'binding': None   } # TODO
+ 
+       if not object.writeonly:
+         # Add the set_* directory entry
+         self.directory['%s.set_%s' % (parent._xmlrpc__path, object.name)] = \
+           { 'signature': setsig,
+             'help': '',         # TODO
+             'binding': None   } # TODO
  
  
      # Now, map our children
      for child in object._children:
        self._xmlrpc_mapObjects(child, object)
  
+     # Sigh... what kind of drugs was I on to volunteer for RPC abstraction?
+ 
  
    #
    # Return an exception
***************
*** 211,214 ****
--- 243,291 ----
    #                                                                          #
    #                                                                          #
    ############################################################################
+ 
+ 
+ #
+ # Used internally be the XML-RPC server to proxy
+ # between Object-by-Ref and actual objects.
+ #
+ class _ObjectByReferenceHandler:
+ 
+   def __init__(self, oclass):
+     self._class = oclass
+ 
+   # If this makes absolutely no sense, move on and trust the code :)
+   def requestHandler(self, method, *params, **args):
+ 
+     if len(params):
+ 
+       # If parameters were passed, the first one is always the handle
+       refid = params[0]
+ 
+       # The object's real method doesn't expect to receive the object handle
+       params = params[1:]
+ 
+     else:
+ 
+       try:
+ 
+         # If only named parameters are present, then
+         # obj_handle should be the object handle...
+         refid = args['obj_handle']
+ 
+         # The object's real method doesn't expect to receive the object handle
+         del args['obj_handle']
+ 
+       except KeyError:
+         raise StandardError, 'Object handle not returned'   # TDOO
+ 
+     try:
+       return ObjectLibrarian. \
+         retrieveObject(refid).__dict__[method](*params, **args)
+     except KeyError:
+ 
+       # Attempt to use an invalid objecthandle
+       raise StandardError, 'Invalid object handle' # TODO
+ 
+ 
  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]