Hello all,
I'm trying to create a COM Server with an embedded xmlrpc server.
Here is way it must work:
- The client application (programmed with a COM capable language)
instantiates my COM server (programmed with python).
- The COM server must have a connect interface in order to let the
client application process the xmlrpc request.
- After executing a "serveforev er" method on the COM server it begins
to listen on a configured port for xmlrpc requests.
- When the COM server receives a xmlrpc request it passes this request
to the client application event (connect interface) in order to
process it.
- The client application processes the request and returns a result to
the COM server. The COM server returns this result to the xmlrpc
requester.
So, I must say that I have programmed some COM servers in python with
the aid of Mark's book, but in this case I have some problems:
- Must I instantiate a new thread for the xmlrpc server?
- If the xmlrpc server is a different thread how can this thread call
the _BroadcastNotif y method from the main thread (the COM server)?
- I have successfully called the _BroadcastNotif y method from the main
thread, but I become a strange behaviuor calling it from other thread.
- I tryied to pass the calling object reference to the xmlrpc thread,
so the xmlrpc thread has a reference to the _BroadcastNotif y method,
but it does not work correctly.
Here is part of my code (I have deleted some parts):
class xmlrpcServer(Th read):
def __init__(self, mainthread, host, port):
Thread.__init__ (self)
self.host = host
self.port = port
self.mainthread = mainthread
def run(self):
while 1:
# the following line simulates the reception
# of a xmlrpc request
request = xmlrpcRequest(' testmethod', [n, 'parameter2'])
wrapped = wrap(request, useDispatcher=u seDispatcher)
self.mainthread ._BroadcastNoti fy(self.mainthr ead.NotifyCall,
(wrapped,))
class COMServer(Conne ctableServer):
_public_methods _ = ['Serve'] + ConnectableServ er._public_meth ods_
_connect_interf aces_ = [IID_IxmlrpcEven ts]
def __init__(self):
ConnectableServ er.__init__(sel f)
self.Host = ''
self.Port = None
def Serve(self):
# method Serve
#req = xmlrpcRequest(' testmethod', ['parameter1', 23])
#wrapped = wrap(req, useDispatcher=u seDispatcher)
#self._Broadcas tNotify(self.No tifyCall, (wrapped,))
#req = unwrap(wrapped)
self._s = xmlrpcServer(se lf)
self._s.start()
def NotifyCall(self , interface, arg):
interface.Invok e(1000, 0, pythoncom.DISPA TCH_METHOD, 1, arg)
class xmlrpcRequest:
# wraps a xmlrpc request as a COM object in order to pass it to
# a client event
_public_methods _ = ['Method', 'Parameter', 'Result']
def __init__(self, method, parameters):
self.Result = None
self._method = method
self._parameter s = parameters
If I call the _BroadcastNotif y method directly from the Serve method,
it works correctly.
Has anybody examples of a similar COM server?
Helps will be appreciated.
Thank you.
I'm trying to create a COM Server with an embedded xmlrpc server.
Here is way it must work:
- The client application (programmed with a COM capable language)
instantiates my COM server (programmed with python).
- The COM server must have a connect interface in order to let the
client application process the xmlrpc request.
- After executing a "serveforev er" method on the COM server it begins
to listen on a configured port for xmlrpc requests.
- When the COM server receives a xmlrpc request it passes this request
to the client application event (connect interface) in order to
process it.
- The client application processes the request and returns a result to
the COM server. The COM server returns this result to the xmlrpc
requester.
So, I must say that I have programmed some COM servers in python with
the aid of Mark's book, but in this case I have some problems:
- Must I instantiate a new thread for the xmlrpc server?
- If the xmlrpc server is a different thread how can this thread call
the _BroadcastNotif y method from the main thread (the COM server)?
- I have successfully called the _BroadcastNotif y method from the main
thread, but I become a strange behaviuor calling it from other thread.
- I tryied to pass the calling object reference to the xmlrpc thread,
so the xmlrpc thread has a reference to the _BroadcastNotif y method,
but it does not work correctly.
Here is part of my code (I have deleted some parts):
class xmlrpcServer(Th read):
def __init__(self, mainthread, host, port):
Thread.__init__ (self)
self.host = host
self.port = port
self.mainthread = mainthread
def run(self):
while 1:
# the following line simulates the reception
# of a xmlrpc request
request = xmlrpcRequest(' testmethod', [n, 'parameter2'])
wrapped = wrap(request, useDispatcher=u seDispatcher)
self.mainthread ._BroadcastNoti fy(self.mainthr ead.NotifyCall,
(wrapped,))
class COMServer(Conne ctableServer):
_public_methods _ = ['Serve'] + ConnectableServ er._public_meth ods_
_connect_interf aces_ = [IID_IxmlrpcEven ts]
def __init__(self):
ConnectableServ er.__init__(sel f)
self.Host = ''
self.Port = None
def Serve(self):
# method Serve
#req = xmlrpcRequest(' testmethod', ['parameter1', 23])
#wrapped = wrap(req, useDispatcher=u seDispatcher)
#self._Broadcas tNotify(self.No tifyCall, (wrapped,))
#req = unwrap(wrapped)
self._s = xmlrpcServer(se lf)
self._s.start()
def NotifyCall(self , interface, arg):
interface.Invok e(1000, 0, pythoncom.DISPA TCH_METHOD, 1, arg)
class xmlrpcRequest:
# wraps a xmlrpc request as a COM object in order to pass it to
# a client event
_public_methods _ = ['Method', 'Parameter', 'Result']
def __init__(self, method, parameters):
self.Result = None
self._method = method
self._parameter s = parameters
If I call the _BroadcastNotif y method directly from the Serve method,
it works correctly.
Has anybody examples of a similar COM server?
Helps will be appreciated.
Thank you.