client: Add timed callback

A timed callback allows the modification of server-side filters
during runtime (the client instance provided as callback argument
includes the socket and its send function).

Since sock_file.readline() is blocking, a secure scheduling can't
be guaranteed but is likely due to regular server-sent status messages.
pull/4/head
Fabian P. Schmidt 2016-03-25 18:48:44 +01:00
rodzic 03cb921e51
commit fd53e6a3df
2 zmienionych plików z 6 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,8 @@
# CHANGELOG # CHANGELOG
## Unreleased
- aprs client: Added the possibility of a timed callback
## 0.3.0 - 2016-03-18 ## 0.3.0 - 2016-03-18
The repository ogn-python splitted up into two separate repositories: The repository ogn-python splitted up into two separate repositories:
- python-ogn-client (the repository this Changelog belongs to), - python-ogn-client (the repository this Changelog belongs to),

Wyświetl plik

@ -45,14 +45,15 @@ class AprsClient:
except OSError: except OSError:
self.logger.error('Socket close error', exc_info=True) self.logger.error('Socket close error', exc_info=True)
def run(self, callback, autoreconnect=False): def run(self, callback, timed_callback=lambda client: None, autoreconnect=False):
while True: while True:
try: try:
keepalive_time = time() keepalive_time = time()
while True: while True:
if time() - keepalive_time > settings.APRS_KEEPALIVE_TIME: if time() - keepalive_time > settings.APRS_KEEPALIVE_TIME:
self.logger.info('Send keepalive') self.logger.info('Send keepalive')
self.sock.send('#keepalive'.encode()) self.sock.send('#keepalive\n'.encode())
timed_callback(self)
keepalive_time = time() keepalive_time = time()
# Read packet string from socket # Read packet string from socket