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

added the deSyncFig method to server and client side

parent 8956bbf9
Pipeline #404 failed with stage
in 1 minute and 28 seconds
......@@ -46,8 +46,7 @@ class MplClient2():
print('please provide host,port. currently host: ',self.host,' , port:',self.port)
def send(self,sig):
# pickel the signal
# send the str
""" Sending a Type derived from Signal through the socket after 'pickling' it"""
wf = self.sock.makefile(mode='wb')
if debug:
print('sending ',type(sig),' with content \"',sig.content,'\"')
......@@ -103,7 +102,10 @@ class MplClient2():
return self.testStatusSig(query,statusSig)
def listRemoteData(self):
""" The server retuns a list with the content of its G_RAWDATA """
""" The server retuns a list with the content of its G_RAWDATA
not implemented yet.
"""
pass
def newSyncFigure(self, figname, dataname,*args,**kwargs) :
......@@ -115,6 +117,7 @@ class MplClient2():
# create a Signal of type Query with args
query = Query(Query.NEWSYNCFIGURE,{'figClassName' : figname.__name__, "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()
......@@ -152,20 +155,25 @@ class MplClient2():
#~ # do not update the figure.
#~ print statusSig.error
#~
#~ def deleteSyncFigure()
#~ '''
#~ Send a DELETE_SYNC_FIGURE query to the server.
#~ wait for the status
#~ if status ok then sync.
#~ '''
#~ # create a signal with args
#~ query = Query(Query.DELETE_SYNC_FIGURE)
#~ sendSignal(query)
#~ statusSig = waitForSignal()
#~ if statusSig.value:
#~ # delete local figure.
#~ else:
#~ print statusSig.error
def deleteSyncFigure(self,syncID):
'''
Send a DELETESYNCFIGURE query to the server.
If the FigID is known delete it from G_FIGURES (server)
wait for the confirmation status
if status ok then proceed deletion.
'''
# create a signal with syncID as content
query = Query(Query.DELETESYNCFIGURE,syncID)
status = self.send(query)
statusSig = self.waitForSignal()
if status and statusSig.value:
return True
else:
print('The remote figure could not be deleted')
print statusSig.content
return False
# SYNC FIGURE FORMAT RAWDATA ---------------------------------------
def syncFigFormatRawData(self, syncID):
......@@ -174,9 +182,8 @@ class MplClient2():
if answer not empty then set data to answer's value.
'''
# Send the signal with syncID
# Send the signal with syncID as content
signal = Query(Query.SYNCFIGFORMATRAWDATA,syncID)
status = self.send(signal)
if debug:
......
......@@ -119,6 +119,15 @@ class MplHandler(SocketServer.StreamRequestHandler):
datas = datas + (ax.data,)
return Answer(datas)
def treatDeleteSyncFigure(self,figID) :
""" Deletes the figure with ID figID from G_FIGURES """
if figID in G_FIGURES :
del G_FIGURES[figID]
return Status(True,'Figure with ID '+str(figID)+' deleted from server.')
else :
return Status(False,'Figure with ID '+str(figID)+' not found on server side.')
def send(self,sig):
# pickel the signal
......@@ -166,6 +175,8 @@ class MplHandler(SocketServer.StreamRequestHandler):
return self.treatUpdateSyncFigure(sig.content)
elif sig.queryType == sig.SYNCFIGFORMATRAWDATA :
return self.treatSyncFigFormatRawData(sig.content)
elif sig.queryType == sig.DELETESYNCFIGURE :
return self.treatDeleteSyncFigure(sig.content)
else :
self.servPrint('received unknown query type')
return Status(False,"received unknown query type")
......
......@@ -110,6 +110,16 @@ class MyFig_client(Figure):
# initialise
self._initialize(*args, **kwargs)
def deSyncFig(self):
if self.client is not None :
if self.client.deleteSyncFigure(self.syncID) :
print('The figure was successfully deleted on the server Side')
self.syncID = -1
else :
print('The figure could not be deleted on the server Side')
else:
print('The client is not connected to a server yet')
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
......
......@@ -9,9 +9,10 @@ class Query(Signal) :
NEWSYNCFIGURE = 2
UPDATESYNCFIGURE = 3
SYNCFIGFORMATRAWDATA = 4
DELETESYNCFIGURE = 5
def __init__(self,queryType, content) :
if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA] :
if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA,Query.DELETESYNCFIGURE] :
self.queryType = queryType
if queryType == Query.READDATA :
if type(content) == dict :
......@@ -27,11 +28,16 @@ class Query(Signal) :
raise
elif queryType == Query.UPDATESYNCFIGURE :
pass
self.content = content
elif queryType == Query.SYNCFIGFORMATRAWDATA :
self.content = content
elif queryType == Query.DELETESYNCFIGURE :
self.content = content
else :
print('unknown query type!')
raise
class Status(Signal):
......
......@@ -27,4 +27,6 @@ client.connect(('', 50803))
client.readData('readStupidData', 'data1')
fig = client.newSyncFigure(FigTestc, ('data1',))
win=mpl_client.MyWin(fig)
sleep(10)
sleep(2)
fig.deSyncFig()
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