# -*- coding: utf-8 -*-
|
|
#!/usr/bin/python
|
# -*- coding: utf-8 -*
|
import paho.mqtt.client as mqtt
|
from linkListUtil import Node, LinkedList
|
|
class inside_option:
|
|
def __init__(self):
|
self.cases = {}
|
|
def valuecontrol(self, condition):
|
def decorator(func):
|
self.cases[condition] = func
|
return func
|
return decorator
|
|
def default(self):
|
print('defual value')
|
|
def switch(self, option):
|
case_func = self.cases.get(option, self.default)
|
case_func()
|
|
insideH = inside_option()
|
|
@insideH.valuecontrol(0)
|
def outside(objs: LinkedList, x, client: mqtt.Client ):
|
print('case 0')
|
node = objs.find_by_value(x['object_id'])
|
if node is None:
|
objs.insert_value_to_head(x['object_id'], [x])
|
node = objs.find_by_value(x['object_id'])
|
if x['isInside'] == 1:
|
client.publish(send_topic[0], json.dumps(x))
|
data_queue.put(node.track)
|
else :
|
obj0 = node.track[0]
|
client.publish(send_topic[2],x['object_id'])
|
objs.delete_by_value(x['object_id'], node.track)
|
data_queue.put(node.track)
|
node.track.append(x)
|
|
@insideH.valuecontrol(1)
|
def inside():
|
print('case 1')
|
|
@insideH.valuecontrol(-1)
|
def lost():
|
print('case -1')
|
|
if __name__ == '__main__':
|
|
insideH.switch(1)
|
insideH.switch(2)
|
insideH.switch(-1)
|