summaryrefslogtreecommitdiffstats
path: root/src/ogClient.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ogClient.py')
-rw-r--r--src/ogClient.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ogClient.py b/src/ogClient.py
index 51aa33b..2635a3f 100644
--- a/src/ogClient.py
+++ b/src/ogClient.py
@@ -6,6 +6,7 @@
# Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
+import threading
import errno
import select
import socket
@@ -26,6 +27,8 @@ class State(Enum):
class ogClient:
OG_PATH = '/opt/opengnsys/'
+ SESSION_POLL_INTERVAL = 5
+ EVENT_SOCKET_PORT = 55885
def __init__(self, config):
self.CONFIG = config
@@ -36,7 +39,7 @@ class ogClient:
if self.mode in {'linux', 'windows'}:
self.event_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.event_sock.setblocking(0)
- self.event_sock.bind(('127.0.0.1', 55885))
+ self.event_sock.bind(('127.0.0.1', ogClient.EVENT_SOCKET_PORT))
else:
self.event_sock = None
@@ -49,6 +52,25 @@ class ogClient:
self.ogrest = ogRest(self.CONFIG)
self.seq = None
+ self.session_check_thread = threading.Thread(target=self._session_check_loop, daemon=True)
+ self.session_check_thread.start()
+
+ def _session_check_loop(self):
+ while True:
+ session_status = self.ogrest.check_interactive_session_change()
+ if session_status is True:
+ message = "session start user"
+ elif session_status is False:
+ message = "session stop user"
+ else:
+ message = None
+
+ if message:
+ self.event_sock.sendto(message.encode('utf-8'),
+ ('127.0.0.1', ogClient.EVENT_SOCKET_PORT))
+
+ time.sleep(ogClient.SESSION_POLL_INTERVAL)
+
def get_socket(self):
return self.sock