Commit c6c1ebf5 authored by David Trattnig's avatar David Trattnig
Browse files

Moved communicator to core.

parent fdda8c6b
......@@ -80,7 +80,7 @@ class Aura:
Starts the Engine Core.
"""
from modules.scheduling.scheduler import AuraScheduler
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
from modules.core.engine import SoundSystem
from modules.communication.redis.adapter import ServerRedisAdapter
# Check if the database has to be re-created
......@@ -88,16 +88,16 @@ class Aura:
AuraScheduler(self.config, None)
# Create scheduler and Liquidsoap communicator
self.liquidsoapcommunicator = LiquidSoapCommunicator(self.config)
self.scheduler = AuraScheduler(self.config, self.liquidsoapcommunicator)
self.soundsystem = SoundSystem(self.config)
self.scheduler = AuraScheduler(self.config, self.soundsystem)
# Create the Redis adapter
self.messenger = ServerRedisAdapter(self.config)
self.messenger.scheduler = self.scheduler
self.messenger.liquidsoapcommunicator = self.liquidsoapcommunicator
self.messenger.soundsystem = self.soundsystem
# TODO Check if it's working / needed.
#self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.liquidsoapcommunicator)
#self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.soundsystem)
#self.diskspace_watcher.start()
# And finally wait for redis message / start listener thread
......
......@@ -35,7 +35,7 @@ class Padavan:
args = None
config = None
lsc = None
ss = None
zmqclient = None
redisclient = None
stringreply = ""
......@@ -105,17 +105,17 @@ class Padavan:
# ------------------------------------------------------------------------------------------ #
def init_liquidsoap_communication(self):
# import
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
from modules.core.engine import SoundSystem
# init liquidsoap communication
self.lsc = LiquidSoapCommunicator(self.config)
self.ss = SoundSystem(self.config)
# enable connection
self.lsc.enable_transaction()
self.ss.enable_transaction()
# ------------------------------------------------------------------------------------------ #
def destroy_liquidsoap_communication(self):
# enable connection
self.lsc.disable_transaction()
self.ss.disable_transaction()
# ------------------------------------------------------------------------------------------ #
def init_redis_communication(self, with_server=False):
......@@ -248,7 +248,7 @@ class Padavan:
self.init_liquidsoap_communication()
# select mixer and return the feedback
self.stringreply = self.lsc.channel_activate(mixername, activate)
self.stringreply = self.ss.channel_activate(mixername, activate)
# disable connection
self.destroy_liquidsoap_communication()
......@@ -257,14 +257,14 @@ class Padavan:
def set_volume(self, mixernumber, volume):
# init lqs and enable comm
self.init_liquidsoap_communication()
self.stringreply = self.lsc.channel_volume(mixernumber, volume)
self.stringreply = self.ss.channel_volume(mixernumber, volume)
# disable connection
self.destroy_liquidsoap_communication()
# ------------------------------------------------------------------------------------------ #
def get_active_mixer(self):
self.init_liquidsoap_communication()
am = self.lsc.get_active_mixer()
am = self.ss.get_active_mixer()
if len(am) == 0:
self.destroy_liquidsoap_communication()
......@@ -279,7 +279,7 @@ class Padavan:
def get_mixer_status(self):
self.init_liquidsoap_communication()
status = self.lsc.get_mixer_status()
status = self.ss.get_mixer_status()
for k, v in status.items():
self.stringreply += "source: " + k + "\t status: " + v + "\n"
......
......@@ -49,7 +49,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
scheduler = None
redisclient = None
# connection_tester = None
liquidsoapcommunicator = None
soundsystem = None
socket = None
# ------------------------------------------------------------------------------------------ #
......@@ -154,7 +154,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
self.logger.info("shutdown event received. Bye bye...")
elif item["data"] == "init_player":
self.execute(RedisChannel.IP_REPLY.value, self.liquidsoapcommunicator.init_player)
self.execute(RedisChannel.IP_REPLY.value, self.soundsystem.init_player)
elif item["data"] == "get_act_programme":
self.execute(RedisChannel.GAP_REPLY.value, self.scheduler.get_act_programme_as_string)
......@@ -177,7 +177,7 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
elif item["data"].find("on_play") >= 0:
source = item["data"].split("on_play ")[1]
self.execute(RedisChannel.TS_REPLY.value, self.scheduler.liquidsoapcommunicator.on_play, source)
self.execute(RedisChannel.TS_REPLY.value, self.scheduler.soundsystem.on_play, source)
elif item["data"] == "recreate_db":
self.execute(RedisChannel.RDB_REPLY.value, self.scheduler.recreate_database)
......
......@@ -38,9 +38,9 @@ from modules.base.exceptions import LQConnectionError, InvalidChannelException,
from libraries.exceptions.exception_logger import ExceptionLogger
class LiquidSoapCommunicator(ExceptionLogger):
class SoundSystem(ExceptionLogger):
"""
LiquidSoapCommunicator Class
SoundSystem Class
Uses LiquidSoapClient, but introduces more complex commands, transactions and error handling.
"""
......
......@@ -37,18 +37,18 @@ class StartupThread(threading.Thread):
"""
logger = None
active_entry = None
liquidsoapcommunicator = None
soundsystem = None
scheduler = None
def __init__(self, liquidsoapcommunicator):
def __init__(self, soundsystem):
"""
Initialize the thread.
"""
threading.Thread.__init__(self)
self.logger = logging.getLogger("AuraEngine")
self.liquidsoapcommunicator = liquidsoapcommunicator
self.scheduler = liquidsoapcommunicator.scheduler
self.soundsystem = soundsystem
self.scheduler = soundsystem.scheduler
......@@ -57,7 +57,7 @@ class StartupThread(threading.Thread):
Boots the soundsystem.
"""
try:
self.liquidsoapcommunicator.start()
self.soundsystem.start()
self.logger.info(EngineUtil.engine_info("Engine Core", meta.__version__))
self.scheduler.on_ready()
......
......@@ -34,7 +34,7 @@ from modules.base.exceptions import DiskSpaceException
# ------------------------------------------------------------------------------------------ #
class DiskSpaceWatcher(threading.Thread):
liquidsoapcommunicator = None
soundsystem = None
exit_event = None
config = None
logger = None
......@@ -43,9 +43,9 @@ class DiskSpaceWatcher(threading.Thread):
is_critical = False
# ------------------------------------------------------------------------------------------ #
def __init__(self, config, logger, liquidsoapcommunicator):
def __init__(self, config, logger, soundsystem):
threading.Thread.__init__(self)
self.liquidsoapcommunicator = liquidsoapcommunicator
self.soundsystem = soundsystem
self.config = config
self.logger = logger
......@@ -113,15 +113,15 @@ class DiskSpaceWatcher(threading.Thread):
try:
self.check_disk_space_of_folder(folder)
# ensure recorder is running
if self.liquidsoapcommunicator.is_liquidsoap_running:
self.liquidsoapcommunicator.recorder_start(num)
if self.soundsystem.is_liquidsoap_running:
self.soundsystem.recorder_start(num)
else:
self.logger.warning("Cannot enable recorder. Liquidsoap is not running!")
except DiskSpaceException as e:
self.logger.critical(str(e))
# stop recorder when diskspace is critical
if self.liquidsoapcommunicator.is_liquidsoap_running:
self.liquidsoapcommunicator.recorder_stop(num)
if self.soundsystem.is_liquidsoap_running:
self.soundsystem.recorder_stop(num)
else:
self.logger.warning("Cannot stop recorder. Liquidsoap is not running!")
......@@ -160,8 +160,8 @@ class DiskSpaceWatcher(threading.Thread):
subj = "Diskspace warning"
msg = "Free space in " + folder + " under " + warning_value_raw + ". " + str(usage(total, used, free))
self.send_mail(subj, msg)
if self.liquidsoapcommunicator.is_liquidsoap_running:
self.liquidsoapcommunicator.recorder_start()
if self.soundsystem.is_liquidsoap_running:
self.soundsystem.recorder_start()
else:
self.logger.warning("Cannot enable recorder. Liquidsoap is not running!")
self.sent_a_mail = True
......
......@@ -71,7 +71,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
config (AuraConfig): Holds the Engine Configuration
logger: The logger
exit_event(threading.Event): Used to exit the thread if requested
liquidsoapcommunicator: Stores the connection to LiquidSoap
soundsystem: Manages the audio streams via LiquidSoap
last_successful_fetch (datetime): Stores the last time a fetch from Steering/Tank was successful
programme: The current radio programme to be played as defined in the local engine database
......@@ -84,7 +84,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
config = None
logger = None
exit_event = None
liquidsoapcommunicator = None
soundsystem = None
last_successful_fetch = None
programme = None
message_timer = []
......@@ -93,7 +93,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
def __init__(self, config, liquidsoapcommunicator):
def __init__(self, config, soundsystem):
"""
Constructor
......@@ -107,8 +107,8 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
self.init_database()
self.fallback_manager = FallbackManager(config, self.logger, self)
self.redismessenger = RedisMessenger(config)
self.liquidsoapcommunicator = liquidsoapcommunicator
self.liquidsoapcommunicator.scheduler = self
self.soundsystem = soundsystem
self.soundsystem.scheduler = self
# init threading
threading.Thread.__init__(self)
......@@ -138,7 +138,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
self.logger.info("Fetch new programmes every %ss. Next fetching in %ss." % (str(seconds_to_wait), str(next_time)))
self.fetch_new_programme()
if self.liquidsoapcommunicator.is_ready():
if self.soundsystem.is_ready():
self.queue_programme()
self.print_message_queue()
......@@ -183,7 +183,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
self.logger.info("The FFWD [>>] range exceeds the length of the entry. Drink some tea and wait for the sound of the next entry.")
else:
# Play active entry
self.liquidsoapcommunicator.play(active_entry, TransitionType.FADE)
self.soundsystem.play(active_entry, TransitionType.FADE)
# Check if this is the last item of the schedule
if active_entry.end_unix > active_entry.playlist.schedule.end_unix:
......@@ -198,9 +198,9 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
seconds_to_seek += sleep_offset
time.sleep(sleep_offset)
self.logger.info("Going to fast-forward %s seconds" % seconds_to_seek)
self.liquidsoapcommunicator.enable_transaction()
response = self.liquidsoapcommunicator.playlist_seek(active_entry.channel, seconds_to_seek)
self.liquidsoapcommunicator.disable_transaction()
self.soundsystem.enable_transaction()
response = self.soundsystem.playlist_seek(active_entry.channel, seconds_to_seek)
self.soundsystem.disable_transaction()
self.logger.info("LiquidSoap seek response: " + response)
......@@ -553,7 +553,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
transition_type = TransitionType.INSTANT
if fade_in:
transition_type = TransitionType.FADE
self.liquidsoapcommunicator.play(entry, transition_type)
self.soundsystem.play(entry, transition_type)
self.logger.info(self.get_ascii_programme())
......@@ -636,7 +636,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
transition_type = TransitionType.INSTANT
if fade_out:
transition_type = TransitionType.FADE
self.liquidsoapcommunicator.stop(entry, transition_type)
self.soundsystem.stop(entry, transition_type)
if fade_out == True:
fade_out_time = int(round(float(self.config.get("fade_out_time")))) #FIXME Use float
......@@ -752,7 +752,7 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
# """
# self.logger.critical("ENABLING SWITCHTIMER FOR " + str(entry))
# entry.switchtimer = self.add_or_update_timer(diff, self.liquidsoapcommunicator.play, [entry])
# entry.switchtimer = self.add_or_update_timer(diff, self.soundsystem.play, [entry])
# # FIXME Fade In/Out logic: Not sure if that's functional
# #self.enable_fading(diff, entry, old_entry)
......@@ -765,14 +765,14 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
# # enable fading when entry types are different
# if old_entry is not None:
# if old_entry.type != new_entry.type:
# #self.add_or_update_timer(diff, self.liquidsoapcommunicator.fade_out, [old_entry])
# old_entry.fadeouttimer = self.create_timer(diff-fade_out_time, self.liquidsoapcommunicator.fade_out, [old_entry], fadeout=True)
# #self.add_or_update_timer(diff, self.soundsystem.fade_out, [old_entry])
# old_entry.fadeouttimer = self.create_timer(diff-fade_out_time, self.soundsystem.fade_out, [old_entry], fadeout=True)
# self.logger.critical("ENABLING FADEOUTTIMER FOR " + str(old_entry))
# # same for fadein except old_entry can be None
# else:
# #self.add_or_update_timer(diff, self.liquidsoapcommunicator.fade_in, [new_entry])
# new_entry.fadeintimer = self.create_timer(diff, self.liquidsoapcommunicator.fade_in, [new_entry], fadein=True)
# #self.add_or_update_timer(diff, self.soundsystem.fade_in, [new_entry])
# new_entry.fadeintimer = self.create_timer(diff, self.soundsystem.fade_in, [new_entry], fadein=True)
# self.logger.critical("ENABLING FADEINTIMER FOR " + str(new_entry))
......
......@@ -26,7 +26,7 @@ import urllib
import logging
import json
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
from modules.core.engine import SoundSystem
#from libraries.database.broadcasts import ScheduleEntry
from modules.base.config import AuraConfig
......@@ -62,7 +62,7 @@ class ConnectionTester(AuraConfig):
# ------------------------------------------------------------------------------------------ #
def test_lqs_conn(self):
try:
lsc = LiquidSoapCommunicator(self.config)
lsc = soundsystem(self.config)
lsc.get_mixer_status()
return True
......@@ -72,7 +72,7 @@ class ConnectionTester(AuraConfig):
# ------------------------------------------------------------------------------------------ #
def test_lqsr_conn(self):
try:
lsc = LiquidSoapCommunicator(self.config)
lsc = soundsystem(self.config)
lsc.get_recorder_status()
return True
......
......@@ -13,7 +13,7 @@ from libraries.database.broadcasts import Schedule, TrackService
# from libraries.security.user import AuraUser
# modules
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
from modules.core.engine import SoundSystem
from modules.scheduling.scheduler import AuraScheduler
class TestLogger(unittest.TestCase):
......@@ -128,10 +128,10 @@ class TestLQSComm(unittest.TestCase):
# wosn do passiert?
p = AuraConfig().config
self.comm = LiquidSoapCommunicator(p)
self.comm.scheduler = AuraScheduler(p)
self.soundsystem = SoundSystem(p)
self.soundsystem.scheduler = AuraScheduler(p)
self.comm.init_player()
self.soundsystem.init_player()
def test_get_active_channel(self):
......
......@@ -30,7 +30,7 @@ import logging
import sqlalchemy
import decimal
from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator
from modules.core.engine import SoundSystem
from modules.monitoring.diskspace_watcher import DiskSpaceWatcher
from modules.base.config import AuraConfig
from libraries.database.broadcasts import Schedule, ScheduleEntry
......@@ -55,7 +55,7 @@ def alchemyencoder(obj):
def start_diskspace_watcher():
config = AuraConfig()
config.read_config()
diskspace_watcher = DiskSpaceWatcher(config.config, logging.getLogger("AuraEngine"), LiquidSoapCommunicator(config.config))
diskspace_watcher = DiskSpaceWatcher(config.config, logging.getLogger("AuraEngine"), SoundSystem(config.config))
diskspace_watcher.run()
def select_current_programme():
......@@ -64,11 +64,11 @@ def select_current_programme():
config = AuraConfig()
config.read_config()
liquidsoapcommunicator = LiquidSoapCommunicator(config.config)
soundsystem = SoundSystem(config.config)
sched = AuraScheduler(config.config)
liquidsoapcommunicator.scheduler = sched
sched.liquidsoapcommunicator = liquidsoapcommunicator
soundsystem.scheduler = sched
sched.soundsystem = soundsystem
programme = sched.load_programme_from_db()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment