# Path: SigObject.py
# class SigObject(QObject):
#     def __init__(self):
# 
# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass


from TcpClient import TcpClient
from SigObject import sigObject
from log import logger
import signals
import socket
import socktypes
import threading
        
        return True
        
    def stop(self):
        self.removeAllClients()
        self.stopflag = True
    
    def removeClient(self, client):
        self.removeClientById(client.getId())
        
    def removeClientById(self, clientId):
        logger.debug("client id is --> %d" % clientId)
        tcpClient = self.tcpClients.get(clientId)
        if tcpClient is None:
            logger.error("fail to get tcp Client")
            return
        
        tcpClient.stop()
        del self.tcpClients[clientId]
        
    def removeAllClients(self):
        for _id, tcpClient in self.tcpClients.items():
            self.removeClient(tcpClient)
        
    def run(self):
        while not self.stopflag:
            #logger.debug("waiting for client...")
            try:
                client, addr = self.sock.accept()
                tcpClient = TcpClient(self._id, client, addr, socktypes.TCP_CLIENT_REMOTE)

# Path: SigObject.py
# class SigObject(QObject):
#     def __init__(self):
# 
# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass


# Path: net/TcpServer.py
from TcpClient import TcpClient
from SigObject import sigObject
from log import logger
import signals
import socket
import socktypes
import threading

        
        return True
        
    def stop(self):
        self.removeAllClients()
        self.stopflag = True
    
    def removeClient(self, client):
        self.removeClientById(client.getId())
        
    def removeClientById(self, clientId):
        logger.debug("client id is --> %d" % clientId)
        tcpClient = self.tcpClients.get(clientId)
        if tcpClient is None:
            logger.error("fail to get tcp Client")
            return
        
        tcpClient.stop()
        del self.tcpClients[clientId]
        
    def removeAllClients(self):
        for _id, tcpClient in self.tcpClients.items():
            self.removeClient(tcpClient)
        
    def run(self):
        while not self.stopflag:
            #logger.debug("waiting for client...")
            try:
                client, addr = self.sock.accept()
                tcpClient = TcpClient(self._id, client, addr, socktypes.TCP_CLIENT_REMOTE)

                sigObject.emit(signals.SIG_REMOTE_TCP_CLIENT_CONNECTED, tcpClient, self._id, tcpClient.getId(), addr[0], addr[1])