work in progress: agent.talk - client connect basically working
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3290 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									e43810beb2
								
							
						
					
					
						commit
						fa7f9f3d3f
					
				
					 2 changed files with 10 additions and 5 deletions
				
			
		| 
						 | 
					@ -39,6 +39,7 @@ class Session(object):
 | 
				
			||||||
        self.subscriber = subscriber
 | 
					        self.subscriber = subscriber
 | 
				
			||||||
        self.url = url
 | 
					        self.url = url
 | 
				
			||||||
        self.state = 'logon'
 | 
					        self.state = 'logon'
 | 
				
			||||||
 | 
					        self.sending = False
 | 
				
			||||||
        self.queue = []
 | 
					        self.queue = []
 | 
				
			||||||
        self.interactions = {}
 | 
					        self.interactions = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,22 +47,24 @@ class Session(object):
 | 
				
			||||||
        data = json.loads(data)
 | 
					        data = json.loads(data)
 | 
				
			||||||
        self.state = 'open'
 | 
					        self.state = 'open'
 | 
				
			||||||
        self.subscriber.onMessage(None, data)
 | 
					        self.subscriber.onMessage(None, data)
 | 
				
			||||||
 | 
					        self.sending = False
 | 
				
			||||||
        self._processQueue()
 | 
					        self._processQueue()
 | 
				
			||||||
        # self._poll()
 | 
					        # self._poll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def received(self, data):
 | 
					    def received(self, data):
 | 
				
			||||||
        data = json.loads(data)
 | 
					        data = json.loads(data)
 | 
				
			||||||
        # TODO: check data
 | 
					        # TODO: check data
 | 
				
			||||||
 | 
					        self.sending = False
 | 
				
			||||||
        self._processQueue()
 | 
					        self._processQueue()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def pollReceived(self, data):
 | 
					    def pollReceived(self, data):
 | 
				
			||||||
        data = json.loads(data)
 | 
					        data = json.loads(data)
 | 
				
			||||||
        if data.get('action') != 'idle':
 | 
					        if data.get('action') != 'idle':
 | 
				
			||||||
            self.subscriber.onMessage(None, data)
 | 
					            self.subscriber.onMessage(interaction, data)
 | 
				
			||||||
        # self._poll()
 | 
					        # self._poll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _send(self, data, interaction):
 | 
					    def _send(self, data, interaction):
 | 
				
			||||||
        if self.queue:
 | 
					        if self.sending or self.queue:
 | 
				
			||||||
            self.queue.append(data)
 | 
					            self.queue.append(data)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self._sendData(data)
 | 
					            self._sendData(data)
 | 
				
			||||||
| 
						 | 
					@ -69,9 +72,11 @@ class Session(object):
 | 
				
			||||||
    def _processQueue(self):
 | 
					    def _processQueue(self):
 | 
				
			||||||
        if not self.queue:
 | 
					        if not self.queue:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					        self._sendData(self.queue.pop(0))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _sendData(self, data):
 | 
					    def _sendData(self, data, command='send'):
 | 
				
			||||||
        content = dict(id=self.id, command='send', data=data)
 | 
					        self.sending = True
 | 
				
			||||||
 | 
					        content = dict(id=self.id, command=command, data=data)
 | 
				
			||||||
        d = getPage(self.url, postdata=json.dumps(content))
 | 
					        d = getPage(self.url, postdata=json.dumps(content))
 | 
				
			||||||
        d.addCallback(s.received)
 | 
					        d.addCallback(s.received)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,7 +105,7 @@ class ISession(Interface):
 | 
				
			||||||
    manager = Attribute("""The server or client object, respectively, that
 | 
					    manager = Attribute("""The server or client object, respectively, that
 | 
				
			||||||
                created the session.""")
 | 
					                created the session.""")
 | 
				
			||||||
    subscriber = Attribute("The subscriber that initiated the session.")
 | 
					    subscriber = Attribute("The subscriber that initiated the session.")
 | 
				
			||||||
    url = Attribute("The URL of the server the session connects to.")
 | 
					    url = Attribute("The URL of the server (or client) the session connects to.")
 | 
				
			||||||
    state = Attribute("""A string specifying the current state of the session:
 | 
					    state = Attribute("""A string specifying the current state of the session:
 | 
				
			||||||
                'logon': The remote client is trying to connect/log in,
 | 
					                'logon': The remote client is trying to connect/log in,
 | 
				
			||||||
                         data may contain credential information;
 | 
					                         data may contain credential information;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue