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

G_RAWDATA and G_FIGURES are now privat variables of server _rawdata and...

G_RAWDATA and G_FIGURES are now privat variables of server _rawdata and _figures. Ownership of getFigByID() is also transfered to server
parent 8b12f30a
Pipeline #477 passed with stage
in 4 minutes and 24 seconds
......@@ -44,7 +44,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Try to execute the instructions
try:
self.server.G_RAWDATA[dataName] = fct(*args, **kwargs)
self.server._rawdata[dataName] = fct(*args, **kwargs)
if debug:
print(INFO+"SERVER: I read the data following instructions")
except:
......@@ -52,7 +52,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
print(WARN+"SERVER: The instructions of readData could not be executed.")
print(SPCE+"SERVER: 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 self.server.G_RAWDATA :
if dataName in self.server._rawdata :
return Status(True,"SERVER: I read the data following instructions"+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return False #should never get here
......@@ -65,7 +65,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
kwargs = content.get('kwargs')
datanames = content.get('dataName')
datas = [self.server.G_RAWDATA[name] for name in datanames]
datas = [self.server._rawdata[name] for name in datanames]
try:
# create the figure:
......@@ -80,30 +80,16 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Status(False, "I could not create the requested Figure. I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')'+" Exception details where:"+str(e.message)+str(e.args))
# add the figure to the global index
self.server.G_FIGURES[fig.getFigID()] = fig
self.server._figures[fig.getFigID()] = fig
if fig.getFigID() in self.server.G_FIGURES :
if fig.getFigID() in self.server._figures :
return Answer(fig.getFigID())
def getFigByID(self,figID) :
""" Identify the figure by ID and return it. On error it will return a Status Signal"""
# Identify the figure
fig = self.server.G_FIGURES.get(figID,None)
if fig is None :
if debug:
print(WARN+"The figure ID: "+figID+" does not exist.")
return Status(False,"The figure ID: "+figID+" does not exist.")
elif isinstance(fig,MyFig) :
if debug :
print('Figure ',figID,' found in database')
return fig
def treatUpdateSyncFigure(self,content) :
""" If client request an update of the keywords of a figure. This function forwards the request to the corresponding figure"""
figID,kwargs = content
fig = self.getFigByID(figID)
fig = self.server.getFigByID(figID)
# if an error occured forward the signal
if isinstance(fig,Signal) :
......@@ -119,7 +105,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
def treatSyncFigFormatRawData(self,figID):
# Identify the figure
fig = self.getFigByID(figID)
fig = self.server.getFigByID(figID)
# if an error occured forward the signal
if isinstance(fig,Signal) :
......@@ -140,27 +126,27 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Answer(datas)
def treatDeleteSyncFigure(self,figID) :
""" Deletes the figure with ID figID from G_FIGURES """
if figID in self.server.G_FIGURES :
del self.server.G_FIGURES[figID]
""" Deletes the figure with ID figID from _figures """
if figID in self.server._figures :
del self.server._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 treatListData(self,content) :
""" list the keys (and possibly (later) the location) from G_RAWDATA """
return Answer(self.server.G_RAWDATA.keys())
""" list the keys (and possibly (later) the location) from _rawdata """
return Answer(self.server._rawdata.keys())
def treatGetData(self,content) :
""" from G_FIGURES """
if content in self.server.G_RAWDATA:
return Answer(self.server.G_RAWDATA[content])
""" from _figures """
if content in self.server._rawdata:
return Answer(self.server._rawdata[content])
else :
return Status(False,'Dataname not found in index of the server side...')
def treatListFig(self,content) :
""" list the keys from G_FIGURES """
return Answer(self.server.G_FIGURES.keys())
""" list the keys from _figures """
return Answer(self.server._figures.keys())
# Actually not used anymore. Keep for testing?
# def send(self,sig):
......@@ -297,8 +283,8 @@ class MplServer2(SocketServer.TCPServer):
self.running = False
self.initialized = True
self.G_RAWDATA = dict()
self.G_FIGURES = dict()
self._rawdata = dict()
self._figures = dict()
def run(self, as_daemon=True):
self.server_thread = threading.Thread(target=self.serve_forever)
......@@ -311,3 +297,16 @@ class MplServer2(SocketServer.TCPServer):
# self.server_thread.stop()
self.running = False
def getFigByID(self,figID) :
""" Identify the figure by ID and return it. On error it will return a Status Signal"""
# Identify the figure
fig = self._figures.get(figID,None)
if fig is None :
if debug:
print(WARN+"The figure ID: "+figID+" does not exist.")
return Status(False,"The figure ID: "+figID+" does not exist.")
elif isinstance(fig,MyFig) :
if debug :
print('Figure ',figID,' found in database')
return fig
......@@ -86,21 +86,8 @@ class RemoteFigTestCase(unittest.TestCase):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
# client side:
self.assertEqual(fig1.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(fig1.getAxesByName('p1').keywords['yRange'],[-2, 2])
# server side:
sfig = self.server.G_FIGURES['2'] # Warning this line will fail if tests are modified . BAD!!!
self.assertEqual(sfig.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(sfig.getAxesByName('p1').keywords['yRange'],[-2, 2])
# Alternative :
for sfig in self.server.G_FIGURES.values() :
# only one fig should be here.???
self.assertEqual(sfig.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(sfig.getAxesByName('p1').keywords['yRange'],[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig1.syncID)).getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig1.syncID)).getAxesByName('p1').keywords['yRange'],[-2, 2])
#~ def test_ReSync(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
......
Supports Markdown
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