Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jul 2007 12:02:30 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 123532 for review
Message-ID:  <200707151202.l6FC2ULF064139@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123532

Change 123532 by andrew@andrew_hermies on 2007/07/15 12:01:54

	When sending a call hold the response lock until the response is set
	Wait for the response lock to be released when issuing a call
	Create a response object when a response is found and add it to the call object
	When the data is a child of an array append it to the array

Affected files ...

.. //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#4 edit
.. //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#8 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/frontend/facund/computer.py#4 (text+ko) ====

@@ -97,6 +97,10 @@
 
 		call = facund.Call("list_updates", args)
 		self.__connection.doCall(call)
+		# Wait for the response
+		call.acquireLock()
+		call.releaseLock()
+		return call.getResponse()
 
 	def connect(self):
 		'''Connects to the remote computer'''

==== //depot/projects/soc2007/andrew-update/frontend/facund/network/__init__.py#8 (text+ko) ====

@@ -35,6 +35,7 @@
 		self.isReady = False
 
 		self.__data = None
+		self.__calls = {}
 
 		self.bufSize = 1024
 		self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -50,7 +51,7 @@
 		# Mark the class as ready and able to disconnect
 		self.isReady = True
 
-		self.socket.send("<call name=\"ping\" id=\"1\"/>")
+		#self.socket.send("<call name=\"ping\" id=\"1\"/>")
 
 	def disconnect(self):
 		if self.isReady:
@@ -65,9 +66,11 @@
 			self.parser.close()
 
 	def doCall(self, call):
+		print call.getID()
+		call.acquireLock()
+		self.__calls[str(call.getID())] = call
 		self.socket.send(call.getCall())
 
-
 	def interact(self):
 		'''Reads data from the connection and passes it to the
 		XML parser'''
@@ -103,6 +106,21 @@
 			data.setParent(self.__data)
 			self.__data = data
 
+		elif name == "response":
+			self.__responseID = None
+			self.__responseMessage = None
+			self.__responseCode = None
+
+			for attr in attributes.items():
+				if attr[0] == "id":
+					self.__responseID = int(attr[1])
+				elif attr[0] == "code":
+					print self.__responseCode
+				elif attr[0] == "message":
+					self.__responseMessage = str(attr[1])
+				else:
+					print attr
+
 		elif name == "facund-server":
 			self.__connected_lock.acquire()
 
@@ -112,11 +130,20 @@
 		if name == "data":
 			data = self.__data.getParent()
 			if data is not None:
+				data.append(self.__data)
 				self.__data = data
 
 		elif name == "response":
-			print str(self.__data)
-			del self.__data
+			response = facund.Response(self.__responseID,
+			    self.__responseMessage, self.__responseCode,
+			    self.__data)
+
+			# TODO: Check this is a valid item
+			call = self.__calls[str(self.__responseID)]
+			call.setResponse(response)
+			call.releaseLock()
+			self.__calls[self.__responseID] = None
+
 			self.__data = None
 
 		elif name == "facund-server":



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707151202.l6FC2ULF064139>