-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout de la partie filtre avec receiver/emitter
- Loading branch information
Showing
11 changed files
with
176 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/env python3 | ||
|
||
import sys | ||
|
||
sys.path += ['..'] | ||
from Server import Handler | ||
|
||
def Emitter(shm): | ||
class _Emitter(Handler): | ||
def _msgToSend(self): | ||
data = shm.data | ||
data_str = 'TOGETIC ' + ' '.join(map(str, data)) | ||
return bytes(data_str + '\n', 'UTF-8') | ||
|
||
def _parseRecv(self, data_raw): | ||
pass | ||
|
||
def _run(self): | ||
pass | ||
return _Emitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/env python3 | ||
|
||
import sys | ||
|
||
sys.path += ['..'] | ||
from Server.AbstractServer import AbstractServer | ||
|
||
class FilterHandler(AbstractServer): | ||
def __init__(self, input_shm, output_shm): | ||
AbstractServer.__init__(self) | ||
self._in_shm = input_shm | ||
self._out_shm = output_shm | ||
|
||
def _serve(self): | ||
in_data = self._in_shm.data | ||
out_data = in_data | ||
self._out_shm.data = out_data | ||
|
||
def _free(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/env python3 | ||
|
||
import sys | ||
|
||
sys.path += ['..'] | ||
from Server import ClientHandler | ||
|
||
class Receiver(ClientHandler): | ||
def __init__(self, addr, shm): | ||
ClientHandler.__init__(self, addr) | ||
self._shm = shm | ||
|
||
def _msgToSend(self): | ||
pass | ||
|
||
def _parseRecv(self, data_raw): | ||
data_line = data_raw.decode('UTF-8').split('\n') | ||
for data in data_line: | ||
data_array = data.split(' ') | ||
if len(data_array) == 7 and data_array[0] == 'TOGETIC': | ||
try: | ||
info = map(float, data_array[1:]) | ||
except ValueError: | ||
return | ||
self._shm.data = info | ||
|
||
def _run(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/env python3 | ||
|
||
import sys | ||
from threading import Lock | ||
|
||
sys.path += ['..'] | ||
from Server.AbstractServer import AbstractServer | ||
from Server.Listener import Listener | ||
|
||
from Filter.Receiver import Receiver | ||
from Filter.Emitter import Emitter | ||
from Filter.FilterHandler import FilterHandler | ||
|
||
class shm: | ||
def __init__(self): | ||
self._data = None | ||
self._lock = Lock() | ||
|
||
def set(self, data): | ||
with self._lock: | ||
self._data = data | ||
|
||
def get(self): | ||
with self._lock: | ||
return self._data | ||
|
||
data = property(get, set) | ||
|
||
class ThreadedFilter(AbstractServer): | ||
def __init__(self, addr_input, addr_output): | ||
AbstractServer.__init__(self) | ||
|
||
shm_in = shm() | ||
shm_out = shm() | ||
self._receiver = Receiver(addr_input, shm_in) | ||
self._handler = FilterHandler(shm_in, shm_out) | ||
self._emitter = Listener(addr_output, Emitter(shm_out)) | ||
|
||
def start(self): | ||
self._receiver.start() | ||
self._handler.start() | ||
self._emitter.start() | ||
AbstractServer.start(self) | ||
|
||
def _serve(self): | ||
pass | ||
|
||
def _free(self): | ||
for s in [self._receiver, self._handler, self._emitter]: | ||
s.stop() | ||
if s.isAlive(): | ||
s.join(2) | ||
|
||
if __name__ == '__main__': | ||
addr_in = '/tmp/togetic-input' | ||
addr_out = '/tmp/togetic-out' | ||
f = ThreadedFilter(addr_in, addr_out) | ||
try: | ||
f.start() | ||
except KeyboardInterrupt: | ||
f.stop() | ||
f.join(2) | ||
if f.isAlive(): | ||
f.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ThreadedFilter import ThreadedFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters