RaspCam/server/lib/CameraCommander/WaitDisconnectedReply.py

36 lines
1.1 KiB
Python
Raw Normal View History

2020-05-15 12:27:34 +02:00
import time
from WaitState import WaitState
class WaitDisconnectedReply(WaitState):
def __init__(self, userCommand):
self.userCommand = userCommand
self.initTime = time.time()
def handle(self, context):
data = self.waitMsg(context)
if not data:
if self.userCommand:
self.userCommand.callback(False, "connection_lost")
return
if data == "disconnected":
print("[CameraContext] : Camera ({}) at {}:{} successfully disconnected".format(context.camera.id, context.connection.addr, context.connection.port))
context.close()
if self.userCommand:
self.userCommand.callback(True)
else:
print("[WaitDisconnectedReply] : Error({}) from camera ({}) at {}:{}".format(data, context.camera.id, context.connection.addr, context.connection.port))
context.close()
if self.userCommand:
self.userCommand.callback(False, data)
def tic(self, context):
if time.time() - self.initTime > 10:
print("[WaitEnabledModeReply] : Timeout exeeded for camera ({}) at {}:{}".format(context.camera.id, context.connection.addr, context.connection.port))
context.close()
if self.userCommand:
self.userCommand.callback(False, "timeout")