2021-11-25 06:44:12 +00:00
|
|
|
# Python imports
|
2021-11-28 04:03:00 +00:00
|
|
|
import threading, socket, time
|
2021-11-25 06:44:12 +00:00
|
|
|
from multiprocessing.connection import Listener, Client
|
|
|
|
|
2021-12-07 04:44:39 +00:00
|
|
|
# Lib imports
|
2021-11-25 06:44:12 +00:00
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
|
|
|
def threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
2021-12-07 04:44:39 +00:00
|
|
|
|
|
|
|
|
2021-11-25 06:44:12 +00:00
|
|
|
class DBusControllerMixin:
|
|
|
|
|
|
|
|
@threaded
|
|
|
|
def create_ipc_server(self):
|
2021-11-28 22:01:29 +00:00
|
|
|
listener = Listener(('127.0.0.1', 4848), authkey=b'solarfm-ipc')
|
2021-11-25 06:44:12 +00:00
|
|
|
self.is_ipc_alive = True
|
|
|
|
while event_system.keep_ipc_alive:
|
2021-11-28 04:03:00 +00:00
|
|
|
conn = listener.accept()
|
|
|
|
start_time = time.time()
|
|
|
|
|
2021-11-25 06:44:12 +00:00
|
|
|
print(f"New Connection: {listener.last_accepted}")
|
|
|
|
while True:
|
|
|
|
msg = conn.recv()
|
2021-11-25 08:21:10 +00:00
|
|
|
if debug:
|
|
|
|
print(msg)
|
2021-11-25 06:44:12 +00:00
|
|
|
|
|
|
|
if "FILE|" in msg:
|
|
|
|
file = msg.split("FILE|")[1].strip()
|
2021-11-25 08:21:10 +00:00
|
|
|
if file:
|
|
|
|
event_system.push_gui_event(["create_tab_from_ipc", None, file])
|
|
|
|
|
2021-11-25 06:44:12 +00:00
|
|
|
conn.close()
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if msg == 'close connection':
|
|
|
|
conn.close()
|
|
|
|
break
|
|
|
|
if msg == 'close server':
|
|
|
|
conn.close()
|
|
|
|
event_system.keep_ipc_alive = False
|
|
|
|
break
|
2021-11-28 04:03:00 +00:00
|
|
|
|
|
|
|
# NOTE: Not perfect but insures we don't lockup the connection for too long.
|
|
|
|
end_time = time.time()
|
|
|
|
if (end - start) > 15.0:
|
|
|
|
conn.close()
|
|
|
|
|
2021-11-25 06:44:12 +00:00
|
|
|
listener.close()
|
|
|
|
|
|
|
|
|
|
|
|
def send_ipc_message(self, message="Empty Data..."):
|
|
|
|
try:
|
2021-11-29 00:29:09 +00:00
|
|
|
conn = Client(('127.0.0.1', 4848), authkey=b'solarfm-ipc')
|
2021-11-25 06:44:12 +00:00
|
|
|
conn.send(message)
|
|
|
|
conn.send('close connection')
|
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|