forked from nico-osd/osd_repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (37 loc) · 1.47 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/python3
import sys
from broadcast.manager import UDPManager
from broadcast.receiver.udp_observer import Observer
from util.config.logger import Log
from util.config.statics import INTERFACE_NAME
from util.listhandler import Entry
from util.networking import get_ip_address
from util.patterns.singletons import ListHandlerSingleton, UDPObservableSingleton
def main(argv):
interface_name = None
if len(argv) > 0:
interface_name = argv[0]
list_handler_singleton = ListHandlerSingleton()
udp_observable_singleton = UDPObservableSingleton()
logger = Log.get_logger("main")
try:
if interface_name:
wlan_ip_addr = get_ip_address(interface_name)
else:
# determine current ip-address of the interface wlan0
wlan_ip_addr = get_ip_address(INTERFACE_NAME)
except OSError:
logger.error("Not connected to any network on adapter %s. Please check the connection of %s.", INTERFACE_NAME,
INTERFACE_NAME)
exit(1)
logger.info("Selected network address: %s", wlan_ip_addr)
# add own ip + empty Entry object to dict
list_handler_singleton.handler.add_or_override_entry(wlan_ip_addr, Entry())
udp_manager = UDPManager(wlan_ip_addr)
udp_manager.start()
observer = Observer()
observer.subscribe_observed(udp_observable_singleton.observable)
input("Enter to Exit.\n")
udp_manager.stop()
if __name__ == "__main__":
main(sys.argv[1:])