from app.app_config import SPEAKER_CONFIG_FILE
import configparser
import sys

def singleton(cls, *args, **kwargs):
    instances = {}
    
    def _singleton():
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]
    return _singleton

from app.log import Logger
"""
    desc:
        日志实例初始化
 
    Parameters:
 
    Returns:
        返回日志一个日志实例
"""
log = Logger()

"""
    desc:
        配置解析器
"""
app_enanle_cf = configparser.RawConfigParser()
app_enanle_cf.read(SPEAKER_CONFIG_FILE, encoding='utf-8')

"""
    desc:
        启动开关读取
"""

multicast_enanle = app_enanle_cf.get("multicast_player", "enable")

if multicast_enanle != 'yes':
    log.logger.warning("Multicast service disbaled!")
    sys.exit(0)

from app.redisSub import RedisHelper
redisObj = RedisHelper()

project_cf = configparser.RawConfigParser()
speaker_cf = configparser.RawConfigParser()
volume_cf = configparser.RawConfigParser()

if multicast_enanle == 'yes':
    from app.config import MulticastConfig
    multicastConfig = MulticastConfig()

    from app.multicast_player import MulticastPlayer
    multicast_palyer = MulticastPlayer()