1 Star 0 Fork 6

anda/modules

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
common.py 2.98 KB
一键复制 编辑 原始数据 按行查看 历史
JackSun 提交于 2022-12-21 15:26 . update: new tracker modules
# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import _thread
def option_lock(thread_lock):
"""Function thread lock decorator"""
def function_lock(func):
def wrapperd_fun(*args, **kwargs):
with thread_lock:
return func(*args, **kwargs)
return wrapperd_fun
return function_lock
class BaseError(Exception):
"""Exception base class"""
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class Singleton(object):
"""Singleton base class"""
_instance_lock = _thread.allocate_lock()
def __init__(self, *args, **kwargs):
pass
def __new__(cls, *args, **kwargs):
if not hasattr(cls, "instance_dict"):
Singleton.instance_dict = {}
if str(cls) not in Singleton.instance_dict.keys():
with Singleton._instance_lock:
_instance = super().__new__(cls, *args, **kwargs)
Singleton.instance_dict[str(cls)] = _instance
return Singleton.instance_dict[str(cls)]
class Observer(object):
"""Observer base class"""
def update(self, observable, *args, **kwargs):
pass
class Observable(Singleton):
"""Observable base class"""
def __init__(self):
self.__observers = []
def addObserver(self, observer):
"""Add observer"""
try:
self.__observers.append(observer)
return True
except:
return False
def delObserver(self, observer):
"""Delete observer"""
try:
self.__observers.remove(observer)
return True
except:
return False
def notifyObservers(self, *args, **kwargs):
"""Notify observer"""
for o in self.__observers:
o.update(self, *args, **kwargs)
class CloudObservable(Observable):
"""Cloud observable base class"""
def __init__(self):
super().__init__()
def connect(self, enforce=False):
"""Cloud connect"""
pass
def disconnect(self):
"""Cloud disconnect"""
pass
def post_data(self, data):
"""Cloud publish data"""
pass
def ota_request(self, *args, **kwargs):
"""Cloud publish ota plain request"""
pass
def ota_action(self, action, module=None):
"""Cloud publish ota upgrade or not request"""
pass
class DeviceDriversMeta(object):
pass
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/andaai/modules.git
git@gitee.com:andaai/modules.git
andaai
modules
modules
master

搜索帮助