aboutsummaryrefslogtreecommitdiff
path: root/ivy.py
diff options
context:
space:
mode:
Diffstat (limited to 'ivy.py')
-rw-r--r--ivy.py225
1 files changed, 0 insertions, 225 deletions
diff --git a/ivy.py b/ivy.py
deleted file mode 100644
index 20b570f..0000000
--- a/ivy.py
+++ /dev/null
@@ -1,225 +0,0 @@
-import threading
-# -*- coding: iso-8859-1 -*-
-
-import ivycpy
-import sys
-import traceback
-class Ivy:
- class IvyClient:
- def __init__(self, ptr):
- self.ptr=ptr
-
- def getPtr(self):
- return self.ptr
-
- def getName(self):
- return ivycpy.IvyGetApplicationName(self.ptr)
-
- def getHost(self):
- return ivycpy.IvyGetApplicationHost(self.ptr)
-
- def getMessages(self):
- return ivycpy.IvyGetApplicationMessages(self.ptr)
-
- def sendDie(self,message):
- ivycpy.IvySendDieMsg(self.ptr)
-
- def sendDirectMsg(self, id, message):
- ivycpy.IvySendDirectMsg(self.ptr,id,message)
-
- def sendError(self, id, error):
- ivycpy.IvySendError(self.ptr,id,error)
-
- class Domain:
- def __init__(self, domainaddr, port):
- self.domainaddr=domainaddr
- self.port=port
-
- def __str__(self):
- return self.domainaddr+":"+self.port
-
- def getDomainaddr(self):
- return self.domainaddr
-
- def getPort(self):
- return self.port
-
- def __call__(self):
- self.theThread=threading.Thread(target=self.mainloop)
- self.theThread.setDaemon(1)
- self.theThread.start()
-
- def __init__(self, name, message, aIvyApplicationListener):
- self.lIvyApplicationlisteners=[]
- self.dIvyClient={}
- self.addApplicationListener(aIvyApplicationListener)
- self.sReadyMessage=message
- self.sAppName=name
- self.dRegexp={}
- self.lBindListeners=[]
- ivycpy.IvyInit(name,
- message,
- 0,
- self._appliCallback,
- self._die)
-
- def start(self, sdomainbus):
- #Todo Creation des objets Domaine
- #a partir de la chaine de caracteres
- self.sDomainBus=sdomainbus
- ivycpy.IvySetBindCallback(self._bindCallback)
- ivycpy.IvyStart(sdomainbus)
-
- def mainloop(self):
- ivycpy.IvyMainLoop()
-
- def _bindCallback(self, client, id, regexp, event):
- if (event == ivycpy.IvyAddBind ):
- for bl in self.lBindListeners:
- bl.bindPerformed(client, id, regexp)
- elif (event == ivycpy.IvyRemoveBind ):
- for bl in self.lBindListeners:
- bl.unbindPerformed(client, id, regexp)
-
- def addBindListener(self, aBindListener):
- self.lBindListeners.append(aBindListener)
-
- def removeBindListener(self, aBindListener):
- self.lBindListeners.remove(aBindListener)
-
- def addApplicationListener(self, aApplicationListener):
- self.lIvyApplicationlisteners.append(aApplicationListener)
-
- def removeApplicationListener(self, aApplicationListener):
- try:
- self.lIvyApplicationlisteners.remove(aApplicationListener)
- except ValueError, x:
- IvyException(str(x))()
-
- def _appliCallback(self, ivyclient, connected):
- if not self.dIvyClient.has_key(ivyclient):
- ivyClient=Ivy.IvyClient(ivyclient)
- self.dIvyClient[ivyclient]=ivyClient
- else:
- ivyClient=self.dIvyClient[ivyclient]
-
- if connected == ivycpy.IvyApplicationConnected:
- self._connect(ivyClient)
- else:
- self._disconnect(ivyClient)
-
- def _connect(self, *arg):
- for listener in self.lIvyApplicationlisteners:
- listener.connect(*arg)
-
- def _disconnect(self, *arg):
- for listener in self.lIvyApplicationlisteners:
- listener.disconnect(*arg)
-
- def _die(self,ivyclient):
- try:
- ivyClient=self.dIvyClient[ivyclient]
- except KeyError:
- ivyClient=Ivy.IvyClient(ivyclient)
- self.dIvyClient[ivyclient]=ivyClient
-
- for listener in self.lIvyApplicationlisteners:
- listener.die(ivyclient)
-
- def _directMessage(self, ivyclient, *arg):
- try:
- ivyClient=self.dIvyClient[ivyclient]
- except KeyError:
- ivyClient=Ivy.IvyClient(ivyclient)
- self.dIvyClient[ivyclient]=ivyClient
- for listener in self.lIvyApplicationlisteners:
- listener.directMessage(ivyClient,*arg)
-
- def bindMsg(self, regexp, aIvyMessageListener):
- id=ivycpy.IvyBindMsg(aIvyMessageListener.receive,
- regexp)
- self.dRegexp[regexp]=id
- return id
-
- def unBindMsg(self, param):
- if type(param) == type(1):
- ivycpy.unBindMsg(self, id)
- else:
- if self.dRegexp.has_key(param):
- id=self.dRegexp[param]
- ivycpy.unBindMsg(self, id)
- else:
- IvyException("This expression not existed")()
-
- def sendMsg(self, message):
- return ivycpy.IvySendMsg(message)
-
- def getSelfIvyClient(self):
- return self.getIvyClientsByName(self.sAppName)
-
- def getIvyClients(self):
- livyclient=ivycpy.IvyGetApplicationList().split()
- lIvyClient=[]
- for client in livyclient:
- print "client %s"%client
- ivyClient=self.getIvyClientsByName(client)
- lIvyClient.append(ivyClient)
- return lIvyClient
-
- def getIvyClientsByName(self, name):
- ivyclient=ivycpy.IvyGetApplication(name)
- try:
- ivyClient=self.dIvyClient[ivyclient]
- except KeyError:
- ivyClient=IvyClient(ivyclient)
- self.dIvyClient[ivyclient]=ivyClient
- return ivyClient
-
-class IvyApplicationAdapter :
- """IvyApplicationAdapter
- Classe d'objets abstraite définissant l'interface des objets à  fournir à  l'objet de classe Ivy
- lors de son initialisation et par les methodes addApplicationListener et removeApplicationListener
- """
-
- def connect(self,client):
- pass
- def disconnect(self,client):
- pass
- def die(self,id):
- pass
- def directMessage(self, client, id, msg):
- pass
-
-class IvyBindAdapter :
- """IvyBindAdapter
- Classe d'objets abstraite définissant l'interface des objets
- à  fournir à  l'objet de classe Ivy
- via addBindListener et removeBindListener
- """
- def bindPerformed(self,client, id, regexp):
- """
- invoked when a Ivy Client performs a bind
- """
- pass
-
- def unbindPerformed(self,client, id, regexp):
- """
- invoked when a Ivy Client performs a unbind
- """
- pass
-
-class IvyMessageAdapter:
- def receive(self, client, *arg):
- pass
-
-class IvyException :
- def __call__(self):
- raise self
-
- def __str__(self):
- return self.message
-
- def __init__(self, message):
- self.message=message
-
-