# Path: src/bin/tools.py
# def RunThread(func, args=(), daemon=True, lock=None, wait_lock=False, wait_timeout=0.5):
# 	'''
# 	 @brief Run function in separate thread.
# 
# 	 @param func Function to run.
# 	 @param args Input arguments (single argument: (arg1,) - or multiple: (arg1, arg2))
# 	 @param daemon (True/false) - run as daemon or not.
# 	 @param lock Mutex lock - wait for it to be available before starting thread.
# 	 @param wait_lock - Wait for mutex to be available, or raise exception immideately.
# 	 @param wait_timeout - Time to wait in seconds (if wait_lock==True)
# 
# 	 return t Threading object
# 	'''
# 	t = threading.Thread(target=func, args=args)
# 	t.daemon = daemon
# 	if lock == None:
# 		t.start()
# 	else:
# 		if wait_lock:
# 			timeout = timeit.default_timer()
# 			while True:
# 				if not(lock.locked()):
# 					t.start()
# 					break
# 				elif (timeit.default_timer() - timeout) > wait_timeout:
# 					raise Exception('Runtime error - lock not availble')
# 		else:
# 			if not(lock.locked()):
# 				t.start()
# 			else:
# 				raise Exception('Runtime error - lock not availble')
# 	return t


import socket, sys, os, timeit
from src.bin.tools import RunThread
from Requests import Requests
from MsgParserRecv.MessageReceiverSlave import MessageReceiverSlave
from MsgParserRecv.MessageParser import MessageParser
            content                 = self.GetContentRequestPointList(frame_content, error)
            self.SendPayload(request, content)
            if content['valid']:
                self.__subclass.SetStoreDBFlag() # Store frames to database after sending them to master.
        elif request == 'setTimestamp':
            self.SendPayload(request, '')
            self.__subclass.SetTimestamp(self.GetContentRequestSetTimestamp(content))
        elif request == 'calibrateCV':
            calibrate_stereopsis_session            = content['calibrate_stereopsis_session']
            calibrate_blob_scale_detector_session   = content['calibrate_blob_scale_detector_session']
            self.__subclass.CalibrateCV(calibrate_stereopsis_session, calibrate_blob_scale_detector_session)
            self.SendPayload(request, '')
        elif request == 'slaveReady':
            content = self.GetContentRequestSlaveReady(self.__subclass.GetSlaveReady())
            self.SendPayload(request, content)
        elif request == 'sendFlagToSlave':
            flag = self.GetContentSendFlagToSlave(content)
            self.__subclass.SetFlagFromMaster(flag)
            self.SendPayload(request, '')
        elif request == 'stop':
            self.SendPayload(request, '')
            self.ForceTermination()
        elif request == 'disconnect':
            self.SendPayload(request, '')
            self.Disconnect()
            stop = True
        elif request == 'restart':
            self.SendPayload(request, '')
            self.Disconnect()
            stop = True

# Path: src/bin/tools.py
# def RunThread(func, args=(), daemon=True, lock=None, wait_lock=False, wait_timeout=0.5):
# 	'''
# 	 @brief Run function in separate thread.
# 
# 	 @param func Function to run.
# 	 @param args Input arguments (single argument: (arg1,) - or multiple: (arg1, arg2))
# 	 @param daemon (True/false) - run as daemon or not.
# 	 @param lock Mutex lock - wait for it to be available before starting thread.
# 	 @param wait_lock - Wait for mutex to be available, or raise exception immideately.
# 	 @param wait_timeout - Time to wait in seconds (if wait_lock==True)
# 
# 	 return t Threading object
# 	'''
# 	t = threading.Thread(target=func, args=args)
# 	t.daemon = daemon
# 	if lock == None:
# 		t.start()
# 	else:
# 		if wait_lock:
# 			timeout = timeit.default_timer()
# 			while True:
# 				if not(lock.locked()):
# 					t.start()
# 					break
# 				elif (timeit.default_timer() - timeout) > wait_timeout:
# 					raise Exception('Runtime error - lock not availble')
# 		else:
# 			if not(lock.locked()):
# 				t.start()
# 			else:
# 				raise Exception('Runtime error - lock not availble')
# 	return t


# Path: src/MasterSlave/Slave.py
import socket, sys, os, timeit
from src.bin.tools import RunThread
from Requests import Requests
from MsgParserRecv.MessageReceiverSlave import MessageReceiverSlave
from MsgParserRecv.MessageParser import MessageParser

            content                 = self.GetContentRequestPointList(frame_content, error)
            self.SendPayload(request, content)
            if content['valid']:
                self.__subclass.SetStoreDBFlag() # Store frames to database after sending them to master.
        elif request == 'setTimestamp':
            self.SendPayload(request, '')
            self.__subclass.SetTimestamp(self.GetContentRequestSetTimestamp(content))
        elif request == 'calibrateCV':
            calibrate_stereopsis_session            = content['calibrate_stereopsis_session']
            calibrate_blob_scale_detector_session   = content['calibrate_blob_scale_detector_session']
            self.__subclass.CalibrateCV(calibrate_stereopsis_session, calibrate_blob_scale_detector_session)
            self.SendPayload(request, '')
        elif request == 'slaveReady':
            content = self.GetContentRequestSlaveReady(self.__subclass.GetSlaveReady())
            self.SendPayload(request, content)
        elif request == 'sendFlagToSlave':
            flag = self.GetContentSendFlagToSlave(content)
            self.__subclass.SetFlagFromMaster(flag)
            self.SendPayload(request, '')
        elif request == 'stop':
            self.SendPayload(request, '')
            self.ForceTermination()
        elif request == 'disconnect':
            self.SendPayload(request, '')
            self.Disconnect()
            stop = True
        elif request == 'restart':
            self.SendPayload(request, '')
            self.Disconnect()
            stop = True

            RunThread(self.RestartRequest, daemon=False)