Skip to content

Commit

Permalink
Merge pull request #85 from OlivOS-Team/dev
Browse files Browse the repository at this point in the history
合并开发分支
  • Loading branch information
lunzhiPenxil authored Apr 19, 2023
2 parents 51d467b + cfd3734 commit 0c3a7a5
Show file tree
Hide file tree
Showing 19 changed files with 822 additions and 118 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -322,7 +322,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -361,7 +361,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_debug.spec
- name: Run artifact
run: |
Expand Down Expand Up @@ -390,7 +390,7 @@ jobs:
- name: Run packing
run: |
cp ./OlivOS/hook.py ./OlivOS/hook_bak.py
cp ./OlivOS/hook_pack.py ./OlivOS/hook.py
cp ./OlivOS/hook_pack_debug.py ./OlivOS/hook.py
pyinstaller ./main_mac.spec
- name: Run artifact
run: |
Expand Down
62 changes: 59 additions & 3 deletions OlivOS/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import hashlib
import time
import traceback
import inspect
import ctypes

from functools import wraps

Expand Down Expand Up @@ -1423,18 +1425,42 @@ class StoppableThread(threading.Thread):
def __init__(self, *args, **kwargs):
super(StoppableThread, self).__init__(*args, **kwargs)
self._stop_event = threading.Event()
self.root = None

def terminate(self):
if self.root is not None:
try:
self.root.on_terminate()
except Exception as e:
traceback.print_exc()
self._stop_event.set()
self.stop_thread()

def stop(self):
self._stop_event.set()
self.terminate()

def join(self):
pass

def stopped(self):
return self._stop_event.is_set()

def _async_raise(self, tid, exctype):
"""raises the exception, performs cleanup if needed"""
tid = ctypes.c_long(tid)
if not inspect.isclass(exctype):
exctype = type(exctype)
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
raise SystemError("PyThreadState_SetAsyncExc failed")

def stop_thread(self):
self._async_raise(self.ident, SystemExit)


class Proc_templet(object):
Expand All @@ -1460,22 +1486,52 @@ def __init__(self, rx_queue, tx_queue, control_queue, logger_proc, scan_interval
self.rx_queue = rx_queue
self.tx_queue = tx_queue
self.control_queue = control_queue
self.control_rx_queue = multiprocessing.Queue()
self.logger_proc = logger_proc
self.scan_interval = scan_interval
self.dead_interval = dead_interval

def run(self):
pass

def run_total(self):
t_this = StoppableThread(
name=self.Proc_name + '+on_control_rx',
target=self.on_control_rx_init,
args=()
)
t_this.daemon = self.deamon
t_this.start()
self.run()

def on_control_rx_init(self):
while True:
if self.Proc_info.control_rx_queue.empty():
time.sleep(0.02)
else:
try:
packet = self.Proc_info.control_rx_queue.get(block=False)
except:
continue
self.on_control_rx(packet)

def on_control_rx(self, packet):
#print("!!!! " + self.Proc_name + str(packet.__dict__))
pass

def on_terminate(self):
pass

def start(self):
proc_this = multiprocessing.Process(name=self.Proc_name, target=self.run, args=())
proc_this = multiprocessing.Process(name=self.Proc_name, target=self.run_total, args=())
proc_this.daemon = self.deamon
proc_this.start()
# self.Proc = proc_this
return proc_this

def start_lite(self):
proc_this = StoppableThread(name=self.Proc_name, target=self.run, args=())
proc_this = StoppableThread(name=self.Proc_name, target=self.run_total, args=())
proc_this.root = self
proc_this.daemon = self.deamon
proc_this.start()
# self.Proc = proc_this
Expand Down
12 changes: 12 additions & 0 deletions OlivOS/L10NDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
'libCWCBEXEModelAPI_0004': 'OlivOS libCWCBEXEModel failed: {0}\n{1}',
'libCWCBEXEModelAPI_0005': 'OlivOS libCWCBEXEModel server [{0}] is running',
'libCWCBEXEModelAPI_0006': 'OlivOS libCWCBEXEModel server [{0}] exited',
'bootAPI_0001': 'OlivOS model [{0}] will init',
'bootAPI_0002': 'OlivOS model [{0}] init',
'bootAPI_0003': 'OlivOS model [{0}] will try init',
'bootAPI_0004': 'OlivOS model [{0}] type init',
'bootAPI_0005': 'OlivOS model [{0}] stopped',
'bootAPI_0006': 'OlivOS model [{0}] will stop',
},
'zh-CN': {
'diagnoseAPI_0001': '欢迎使用 青果核心交互栈 OlivOS {0}',
Expand Down Expand Up @@ -166,5 +172,11 @@
'libCWCBEXEModelAPI_0004': 'OlivOS ComWeChatBotClient进程托管服务组件 错误: {0}\n{1}',
'libCWCBEXEModelAPI_0005': 'OlivOS ComWeChatBotClient进程托管服务组件 [{0}] 正在运作',
'libCWCBEXEModelAPI_0006': 'OlivOS ComWeChatBotClient进程托管服务组件 [{0}] 已经存在',
'bootAPI_0001': 'OlivOS 组件 [{0}] 即将初始化',
'bootAPI_0002': 'OlivOS 组件 [{0}] 初始化',
'bootAPI_0003': 'OlivOS 组件 [{0}] 即将尝试初始化',
'bootAPI_0004': 'OlivOS 组件 [{0}] 类型 即将初始化',
'bootAPI_0005': 'OlivOS 组件 [{0}] 已被停止',
'bootAPI_0006': 'OlivOS 组件 [{0}] 即将停止',
}
}
1 change: 1 addition & 0 deletions OlivOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
from . import libWQEXEModelAPI
from . import libCWCBEXEModelAPI
from . import nativeWinUIAPI
from . import webviewUIAPI
from . import userModule
Loading

0 comments on commit 0c3a7a5

Please sign in to comment.