Commit db624575 authored by Philipp Gast's avatar Philipp Gast
Browse files

started to implement newSyncFigure query. Not working yet.

parent 0bc979cf
......@@ -30,11 +30,10 @@ class MplClient2():
wf = self.sock.makefile(mode='wb')
if debug:
print('sending ',type(sig),' with content \"',sig.content,'\"')
#~ try :
print(sig.__class__)
pickle.dump(sig,wf)
#~ except :
#~ return False
try :
pickle.dump(sig,wf)
except :
return False
wf.close()
return True
......@@ -44,16 +43,15 @@ class MplClient2():
rf = self.sock.makefile(mode='rb')
try :
print('before pickle')
response = pickle.load(rf)
print('after pickle')
if debug:
if debug and isinstance(response,Signal):
print('CLIENT Received: {} with content \"{}\"'.format(type(response),response.content))
except EOFError :
print('no answer received')
print('no answer received - or connection closed unexpectedly')
response = None
except :
print('unknown error while waiting for response')
response = None
#~ except :
#~ return False
rf.close()
if isinstance(response,Signal) :
return response
......@@ -70,34 +68,32 @@ class MplClient2():
print(statusSig.content)
return False
else :
if debug :
print('request type ',orgQuery.queryType,' retured unknown status type with content: \"',statusSig.content,'\"')
print('request type ',orgQuery.queryType,' returned unknown status type')
return False
def readData(self,ioFunction, dataName, *args, **kwargs) :
# create a Signal of type Query with arguments
query = Query(Query.READDATA,{'func' : ioFunction, 'dataname' : dataName,'args' : args,'kwargs': kwargs})
status = self.send(query)
print(status)
if not status :
print('something went wrong with the sending of readData request...')
statusSig = self.waitForSignal()
print(statusSig)
return self.testStatusSig(query,statusSig)
#~ def newSyncFigure() :
#~ '''
#~ Send a query NEW_SYNC_FIGURE to the server
#~ wait for the status.
#~ if status ok then sync.
#~ '''
#~ # create a Signal of type Query with args
#~ query = Query(Query.NEWSYNCFIGURE)
#~ status = send(query)
#~ if not status :
#~ print('something went wrong with the sending of newSincFigure request...')
#~ statusSig = waitForSignal()
#~
def newSyncFigure(self, figname, dataname,*args,**kwargs) :
'''
Send a query NEWSYNCFIGURE to the server
wait for the status.
if status ok then sync.
'''
# create a Signal of type Query with args
query = Query(Query.NEWSYNCFIGURE,{'figClassName' : figname, "dataName" : dataname, 'args' : args, 'kwargs' : kwargs})
status = self.send(query)
if not status :
print('something went wrong with the sending of newSincFigure request...')
statusSig = self.waitForSignal()
return self.testStatusSig(query,statusSig)
#~ if statusSig.value :
#~ # create Figure with args
#~ if created
......
......@@ -9,9 +9,11 @@ from . import SERVER_FIGURES
from . import DBUG,WARN,SPCE,SEVR,INFO
G_RAWDATA = dict()
G_FIGURES = dict()
DEBUG = True
class MplHandler(SocketServer.StreamRequestHandler):
def servPrint(self,x) :
print("SERVER: "+x)
......@@ -39,23 +41,44 @@ class MplHandler(SocketServer.StreamRequestHandler):
if(DEBUG):
print(WARN+"SERVER: The instructions of readData could not be executed.")
print(SPCE+"SERVER: I tried: "+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
status = Status(False,"The instructions of readData could not be executed. I tried: "+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return Status(False,"The instructions of readData could not be executed. I tried: "+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
if dataName in G_RAWDATA :
status = Status(True,"SERVER: I read the data following instructions"+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return status
return Status(True,"SERVER: I read the data following instructions"+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return False #should never get here
def treatNewSyncFigure(self,content) :
# Try to create the requested figure
FigClass = SERVER_FIGURES[content.get('figClassName')]
args = content.get('args')
kwargs = content.get('kwargs')
datas = content.get('dataName')
# Generate an FigID
FigID = '26042017'
try:
G_FIGURES[FigID] = FigClass(datas, **kwargs)
if (DEBUG):
print(INFO+"SERVER: I created the requested Figure")
except:
if (DEBUG):
print(WARN+"SERVER: I could not create the requested Figure.")
print(SPCE+"SERVER: I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')')
return Status(False, "I could not create the requested Figure. I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')')
if FigID in G_FIGURES :
return Status(True,"SERVER: I created the requested Figure with following instructions"+str(FigClass.__name__)+str(datas)+'('+str(args)+', '+str(kwargs)+')')
return False #should never get here
def treatNewSyncFigure(content) :
pass
def treatUpdateSyncFigure(content) :
pass
def treatSyncFigFormatRawData(content):
pass
def treatSig(self,sig):
print('I am here')
print(str(sig))
print(type(sig))
print(isinstance(sig, Query))
if isinstance(sig,Query) :
if sig.queryType == sig.READDATA :
return self.treatReadData(sig.content)
......@@ -90,16 +113,16 @@ class MplHandler(SocketServer.StreamRequestHandler):
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
## self.data = self.rfile.readline()#.strip()
print('before pickle')
request = pickle.load(self.rfile)
print('after pickle')
reply = self.treatSig(request)
while self.server.running :
request = pickle.load(self.rfile)
reply = self.treatSig(request)
# Likewise, self.wfile is a file-like object used to write back
# to the client
## self.wfile.write(self.data.upper())
if isinstance(reply,Signal) :
self.servPrint("returning {}-Signal:".format(type(reply)))
pickle.dump(reply,self.wfile)
if isinstance(reply,Signal) :
if DEBUG:
self.servPrint("returning {}-Signal:".format(type(reply)))
pickle.dump(reply,self.wfile)
class MplServer2(SocketServer.TCPServer):
......@@ -127,5 +150,6 @@ class MplServer2(SocketServer.TCPServer):
SocketServer.TCPServer.__init__(self,*args, **kwargs)
self.initialized = True
self.running = True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment