Compare commits
2 Commits
035576dff0
...
d72ff01372
Author | SHA1 | Date | |
---|---|---|---|
d72ff01372 | |||
ba0d687b63 |
@ -40,22 +40,3 @@ class Config:
|
||||
|
||||
def check(self):
|
||||
return self.dect.check()
|
||||
|
||||
|
||||
class ExtensionConfig(ConfigBase):
|
||||
def __init__(self, c):
|
||||
self.num = c[0]
|
||||
self._c = c[1]
|
||||
|
||||
|
||||
class Extensions:
|
||||
def __init__(self, c):
|
||||
self._c = c
|
||||
self.extensions = []
|
||||
for e in self._c.get("extensions", {}).items():
|
||||
self.extensions.append(ExtensionConfig(e))
|
||||
|
||||
def extensions_by_type(self, t):
|
||||
for e in self.extensions:
|
||||
if e.type == t:
|
||||
yield e
|
||||
|
67
fieldpoc/extensions.py
Normal file
67
fieldpoc/extensions.py
Normal file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
class ExtensionConfig:
|
||||
num = None
|
||||
|
||||
callgroup_members = []
|
||||
dect_claim_token = None
|
||||
dect_ipei = None
|
||||
dialout_allowed = False
|
||||
name = None
|
||||
outgoing_extension = None
|
||||
sip_password = None
|
||||
static_target = None
|
||||
trunk = False
|
||||
type = None
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for name, value in kwargs.items():
|
||||
if hasattr(type(self), name):
|
||||
self.__setattr__(name, value)
|
||||
else:
|
||||
raise Exception("Invalid config option {}".format(name))
|
||||
|
||||
if self.type is None:
|
||||
raise Exception("Type field for extension {} is required".format(self.num))
|
||||
elif self.type == "dect":
|
||||
if self.dect_ipei is None and self.dect_claim_token is None:
|
||||
raise Exception("dect_ipei can't be used together with dect_claim_token in extension {}".format(self.num))
|
||||
elif self.type == "sip":
|
||||
if self.sip_password is None:
|
||||
raise Exception("sip_password is required for sip extension {}".format(self.num))
|
||||
elif self.type == "static":
|
||||
if self.static_target is None:
|
||||
raise Exception("static_target is required for static extension {}".format(self.num))
|
||||
|
||||
def check_global(self, extensions):
|
||||
if self.type == "callgroup":
|
||||
for member in self.callgroup_members:
|
||||
if member not in extensions.extensions_by_num.keys():
|
||||
raise Exception("Callgroup member {} of callgroup {} does not exist as extension".format(member, self.num))
|
||||
|
||||
|
||||
class Extensions:
|
||||
extensions = []
|
||||
extensions_by_num = {}
|
||||
|
||||
def __init__(self, c):
|
||||
for num, e in c.get("extensions", {}).items():
|
||||
extension_config = ExtensionConfig(**{
|
||||
"num": num,
|
||||
} | e)
|
||||
|
||||
self.extensions.append(extension_config)
|
||||
|
||||
if extension_config.num in self.extensions_by_num.keys():
|
||||
raise Exception("Extension num already used {}".format(num))
|
||||
|
||||
self.extensions_by_num[num] = extension_config
|
||||
|
||||
for e in self.extensions:
|
||||
e.check_global(self)
|
||||
|
||||
|
||||
def extensions_by_type(self, t):
|
||||
for e in self.extensions:
|
||||
if e.type == t:
|
||||
yield e
|
@ -8,6 +8,7 @@ import threading
|
||||
|
||||
from . import config
|
||||
from . import controller
|
||||
from . import extensions
|
||||
from . import dect
|
||||
from . import routing
|
||||
from . import ywsd
|
||||
@ -39,6 +40,18 @@ class FieldPOC:
|
||||
self._routing = routing.Routing(self)
|
||||
self._ywsd = ywsd.Ywsd(self)
|
||||
|
||||
logger.info("initialising threads")
|
||||
self.threads = {
|
||||
"controller": threading.Thread(target=self._controller.run),
|
||||
"dect": threading.Thread(target=self._dect.run),
|
||||
"routing": threading.Thread(target=self._routing.run),
|
||||
"ywsd": threading.Thread(target=self._ywsd.run, daemon=True),
|
||||
}
|
||||
|
||||
# Set thread names
|
||||
for name, thread in self.threads.items():
|
||||
thread.name = name
|
||||
|
||||
def queue_all(self, msg):
|
||||
"""
|
||||
Send message to every queue
|
||||
@ -60,21 +73,16 @@ class FieldPOC:
|
||||
logger.info("initialization complete")
|
||||
|
||||
def run(self):
|
||||
logger.info("starting components")
|
||||
"""
|
||||
Start FieldPOC
|
||||
"""
|
||||
|
||||
self._controller_thread = threading.Thread(target=self._controller.run)
|
||||
self._controller_thread.start()
|
||||
logger.info("starting threads")
|
||||
|
||||
self._dect_thread = threading.Thread(target=self._dect.run)
|
||||
self._dect_thread.start()
|
||||
for name, thread in self.threads.items():
|
||||
thread.start()
|
||||
|
||||
self._routing_thread = threading.Thread(target=self._routing.run)
|
||||
self._routing_thread.start()
|
||||
|
||||
self._ywsd_thread = threading.Thread(target=self._ywsd.run, daemon=True)
|
||||
self._ywsd_thread.start()
|
||||
|
||||
logger.info("started components")
|
||||
logger.info("started threads")
|
||||
|
||||
def reload_extensions(self):
|
||||
self._load_extensions()
|
||||
@ -84,4 +92,4 @@ class FieldPOC:
|
||||
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
||||
|
||||
def _load_extensions(self):
|
||||
self.extensions = config.Extensions(json.loads(self.extensions_file_path.read_text()))
|
||||
self.extensions = extensions.Extensions(json.loads(self.extensions_file_path.read_text()))
|
||||
|
Loading…
Reference in New Issue
Block a user