|
From: <ma...@us...> - 2011-05-10 15:13:59
|
Revision: 327
http://openautomation.svn.sourceforge.net/openautomation/?rev=327&view=rev
Author: mayerch
Date: 2011-05-10 15:13:52 +0000 (Tue, 10 May 2011)
Log Message:
-----------
- [PyWireGate]: Update the logic editor to have a CometVisu Protocol compatible connection between backend and frontend
- [CometVisu client]: add real session handling to the client
Modified Paths:
--------------
CometVisu/trunk/visu/lib/cometvisu-client.js
PyWireGate/trunk/logic_editor/LogicEditor.py
PyWireGate/trunk/logic_editor/backendCommunication.js
PyWireGate/trunk/logic_editor/index.html
PyWireGate/trunk/logic_editor/logicEditor.js
PyWireGate/trunk/logic_server/LogicServer.py
Property Changed:
----------------
PyWireGate/trunk/logic_editor/lib/
Modified: CometVisu/trunk/visu/lib/cometvisu-client.js
===================================================================
--- CometVisu/trunk/visu/lib/cometvisu-client.js 2011-05-09 17:10:59 UTC (rev 326)
+++ CometVisu/trunk/visu/lib/cometvisu-client.js 2011-05-10 15:13:52 UTC (rev 327)
@@ -106,7 +106,7 @@
{
var requestAddresses = (this.addresses.length)?'a=' + this.addresses.join( '&a=' ):'';
var requestFilters = (this.filters.length )?'f=' + this.filters.join( '&f=' ):'';
- return requestAddresses + ( (this.addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
+ return 's=' + this.session + '&' + requestAddresses + ( (this.addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
}
/**
Modified: PyWireGate/trunk/logic_editor/LogicEditor.py
===================================================================
--- PyWireGate/trunk/logic_editor/LogicEditor.py 2011-05-09 17:10:59 UTC (rev 326)
+++ PyWireGate/trunk/logic_editor/LogicEditor.py 2011-05-10 15:13:52 UTC (rev 327)
@@ -25,6 +25,7 @@
import SocketServer
import threading
+import Queue
import re
from logic_server import LogicLibrary
@@ -119,21 +120,40 @@
contentType="text/plain"
self.path = self.path.replace('/logicCode', thisPath + '/..')
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
- elif self.path.startswith('/live'):
- self.send_response(200)
- self.send_header("Content-type", 'text/plain')
- self.send_header("Access-Control-Allow-Origin", "*")
- self.end_headers()
+
+
+ # Create the CometVisu interface for the internal variables
+ elif self.path.startswith('/live/l'):
# FIXME: BIG, Big, big memory and CPU leak! A created Queue must be
# removed later, or the LogicServer will continue to fill it, even if
# no page will be listening anymore!
l = LOGIC.createQueue( None, None, None ) # get everything!
+ contentType="text/plain"
+ f.write('{"v":"0.0.1","s":"live%s"}' % l)
+ elif self.path.startswith('/live/r'):
+ try:
+ l = int( re.findall('s=live(\d*)', self.path )[0] )
+ except IndexError:
+ return # FIXME - return sensible error message
+ self.send_response(200)
+ #self.send_header("Content-type", 'text/plain')
+ self.send_header("Content-type", 'application/json')
+ self.send_header("Access-Control-Allow-Origin", "*")
+ self.end_headers()
+ self.wfile.write( '{"d":[' )
+ sep = ''
+ getWait = True # wait for the first result, but not any longer
while True:
#self.wfile.write( "new line\n" )
- m = l.get()
- self.wfile.write( "|%s|%s|%s|%s|\n" % m )
- self.wfile.flush()
- #time.sleep( 1.0 )
+ try:
+ m = LOGIC.queues[l][3].get( getWait )
+ getWait = False
+ self.wfile.write( sep )
+ self.wfile.write( '{"task":"%s","module":"%s","block":"%s","value":%s}' % m )
+ sep = ','
+ except Queue.Empty:
+ self.wfile.write( '],"i":0}')
+ return # Queue is empty, end connection
else:
self.path = "%s%s" % ( thisPath, self.path )
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Modified: PyWireGate/trunk/logic_editor/backendCommunication.js
===================================================================
--- PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-09 17:10:59 UTC (rev 326)
+++ PyWireGate/trunk/logic_editor/backendCommunication.js 2011-05-10 15:13:52 UTC (rev 327)
@@ -278,3 +278,30 @@
logics['logik2'] = data;
updateKnownLogics('logik2');
});
+
+// tweak backend communication, should also be done on demand
+XXX = new CometVisu( '/live/' );
+XXX.update = function( json )
+{
+ console.log( json );
+}
+XXX.subscribe( ['ALL'] );
+
+$(window).unload(function() {
+ XXX.stop();
+});
+/*XXX=$.ajax({
+ url: '/live',
+ cache: false,
+ success: function(html){
+ console.log('success', html);
+ }
+});*/
+/*
+ var ws = new websocket("/live");
+ ws.onopen = function() {
+ ws.send("Hello Mr. Server!");
+ };
+ ws.onmessage = function (e) { console.log(e.data); };
+ ws.onclose = function() { console.log('close'); };
+ */
\ No newline at end of file
Modified: PyWireGate/trunk/logic_editor/index.html
===================================================================
--- PyWireGate/trunk/logic_editor/index.html 2011-05-09 17:10:59 UTC (rev 326)
+++ PyWireGate/trunk/logic_editor/index.html 2011-05-10 15:13:52 UTC (rev 327)
@@ -13,6 +13,7 @@
<script type="text/javascript" src="lib/jquery.layout.js"></script>
<script type="text/javascript" src="lib/jquery.jstree.js"></script>
<script type="text/javascript" src="lib/jquery.hotkeys.js"></script>
+ <script type="text/javascript" src="lib/cometvisu-client.js"></script>
<script type="text/javascript" src="backendCommunication.js"></script>
<script type="text/javascript" src="gle/gle.block.js"></script>
<script type="text/javascript" src="gle/gle.connection.js"></script>
Property changes on: PyWireGate/trunk/logic_editor/lib
___________________________________________________________________
Added: svn:externals
+ ^/CometVisu/trunk/visu/lib/cometvisu-client.js cometvisu-client.js
Modified: PyWireGate/trunk/logic_editor/logicEditor.js
===================================================================
--- PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-09 17:10:59 UTC (rev 326)
+++ PyWireGate/trunk/logic_editor/logicEditor.js 2011-05-10 15:13:52 UTC (rev 327)
@@ -163,16 +163,19 @@
function displayLogic( logicName )
{
- console.log( '"'+logicName+'"' );
logic = logics[ logicName ];
+
+ // clean canvas first
+ $('#editor g').remove();
+
+ // draw all the blocks
$.each( logic.blocks, function( name, def ){
var newBlock = $.extend( true, {}, libJSON['MainLib'][ def.type ], def, {'name':name} );
drawElement( undefined, newBlock, true );
});
- console.log( blockRegistry );
+
+ // and connect them
$.each( logic.signals, function( name, def ){
- console.log( name, def, blockRegistry[ def[0] ] );
-
var startBlock = blockRegistry[ def[0] ];
var endBlock = blockRegistry[ def[2] ];
var pn = def[1];
Modified: PyWireGate/trunk/logic_server/LogicServer.py
===================================================================
--- PyWireGate/trunk/logic_server/LogicServer.py 2011-05-09 17:10:59 UTC (rev 326)
+++ PyWireGate/trunk/logic_server/LogicServer.py 2011-05-10 15:13:52 UTC (rev 327)
@@ -21,6 +21,7 @@
import TaskManager
import Queue
import time
+import threading
## Load logik.json
#exec LogicImportJSON.get( 'logik.json' )
@@ -46,7 +47,10 @@
CONNECTOR_NAME = 'Logic Server'
CONNECTOR_VERSION = 0.1
CONNECTOR_LOGNAME = 'logic_server'
- queues = []
+ queues = {}
+ lastQueueId = -1
+ write_mutex = threading.RLock()
+
def __init__(self,parent, instanceName):
self._parent = parent
self.WG = parent.WG
@@ -75,14 +79,15 @@
self.Logik2 = LogikClass
t = TaskManager.TaskManager(self)
- t.addInterval( 'Interval 1 - 75 ms Task', 0.075 )
- t.addInterval( 'Interval 2 - 10 ms Task', 0.010 )
+ t.addInterval( 'Interval 1 - 75 ms Task', 0.75 )
+ t.addInterval( 'Interval 2 - 10 ms Task', 0.910 )
t.addTask( 'Interval 1 - 75 ms Task', 'Logik1', self.Logik1 )
t.addTask( 'Interval 2 - 10 ms Task', 'Logik2', self.Logik2 )
t.start()
while True:
for m in iter( t.getMessage, None ):
for q in self.queues:
+ q = self.queues[q]
if (q[0] == None or q[0] == m[0]) and (q[1] == None or q[1] == m[1]):
for b in m[2]:
if q[2] == None or q[2] == b:
@@ -90,6 +95,11 @@
time.sleep( 0.1 )
def createQueue(self, taskFilter, logicFilter, blockFilter):
- q = Queue.Queue()
- self.queues.append( (taskFilter, logicFilter, blockFilter, q) )
- return q
\ No newline at end of file
+ try:
+ self.write_mutex.acquire()
+ self.lastQueueId += 1
+ thisQueueId = self.lastQueueId # extra variable to be save when the lock is released
+ self.queues[ thisQueueId ] = (taskFilter, logicFilter, blockFilter, Queue.Queue())
+ finally:
+ self.write_mutex.release()
+ return thisQueueId
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|