# Path: core/interfaces/base.py
# class BaseInterface(ABC, Module):
# 
#     def  __init__(self, hplayer, name="INTERFACE", color="blue"):
#         super().__init__(hplayer, name, color)
#         self.hplayer = hplayer
# 
#         # stopping flag
#         self.stopped = threading.Event()
#         self.stopped.set()
# 
#         # Listen thread
#         self.recvThread = threading.Thread(target=self.listen)
# 
# 
#     # Receiver THREAD (ABSTRACT)
#     @abstractmethod
#     def listen(self):
#         self.stopped.wait()
# 
#     # Start
#     def start(self):
#         self.stopped.clear()
#         self.recvThread.start()
#         return self
# 
#     # Stop
#     def quit(self):
#         self.log("stopping...")
#         self.stopped.set()
#         self.recvThread.join()
#         self.log("stopped")
# 
# 	# is Running
#     def isRunning(self, state=None):
#         if state is not None:
#             self.stopped.clear() if state else self.stopped.set()
#         return not self.stopped.is_set()


from .base import BaseInterface
from time import sleep
from pyre import Pyre 
from pyre import zhelper 
import zmq 

        self.zyre.set_name(str(self.interface.hplayer.name()).encode())
        self.zyre.set_header(b"TS-PORT",  str(get_port(self.timereply)).encode())
        self.zyre.set_header(b"PUB-PORT", str(get_port(self.publisher)).encode())

        self.zyre.set_interval(PING_PEER)
        self.zyre.set_evasive_timeout(PING_PEER*3)
        self.zyre.set_silent_timeout(PING_PEER*5)
        self.zyre.set_expired_timeout(PING_PEER*10)

        self.zyre.start()
        self.zyre.join(b"broadcast")
        self.zyre.join(b"sync")

        # Add self to book
        self.book[self.zyre.uuid()] = Peer(self, {
            'uuid':         self.zyre.uuid(),
            'name':         self.zyre.name().decode(),
            'ip':           '127.0.0.1',
            'ts_port':      get_port(self.timereply),
            'pub_port':     get_port(self.publisher)
        }) 
        self.book[self.zyre.uuid()].subscribe(self.topics)

    


#
#  HPLAYER2 Pyre interface
#

# Path: core/interfaces/base.py
# class BaseInterface(ABC, Module):
# 
#     def  __init__(self, hplayer, name="INTERFACE", color="blue"):
#         super().__init__(hplayer, name, color)
#         self.hplayer = hplayer
# 
#         # stopping flag
#         self.stopped = threading.Event()
#         self.stopped.set()
# 
#         # Listen thread
#         self.recvThread = threading.Thread(target=self.listen)
# 
# 
#     # Receiver THREAD (ABSTRACT)
#     @abstractmethod
#     def listen(self):
#         self.stopped.wait()
# 
#     # Start
#     def start(self):
#         self.stopped.clear()
#         self.recvThread.start()
#         return self
# 
#     # Stop
#     def quit(self):
#         self.log("stopping...")
#         self.stopped.set()
#         self.recvThread.join()
#         self.log("stopped")
# 
# 	# is Running
#     def isRunning(self, state=None):
#         if state is not None:
#             self.stopped.clear() if state else self.stopped.set()
#         return not self.stopped.is_set()


# Path: core/interfaces/pyre.py
from .base import BaseInterface
from time import sleep
from pyre import Pyre 
from pyre import zhelper 
import zmq 


        self.zyre.set_name(str(self.interface.hplayer.name()).encode())
        self.zyre.set_header(b"TS-PORT",  str(get_port(self.timereply)).encode())
        self.zyre.set_header(b"PUB-PORT", str(get_port(self.publisher)).encode())

        self.zyre.set_interval(PING_PEER)
        self.zyre.set_evasive_timeout(PING_PEER*3)
        self.zyre.set_silent_timeout(PING_PEER*5)
        self.zyre.set_expired_timeout(PING_PEER*10)

        self.zyre.start()
        self.zyre.join(b"broadcast")
        self.zyre.join(b"sync")

        # Add self to book
        self.book[self.zyre.uuid()] = Peer(self, {
            'uuid':         self.zyre.uuid(),
            'name':         self.zyre.name().decode(),
            'ip':           '127.0.0.1',
            'ts_port':      get_port(self.timereply),
            'pub_port':     get_port(self.publisher)
        }) 
        self.book[self.zyre.uuid()].subscribe(self.topics)

    


#
#  HPLAYER2 Pyre interface
#

class PyreInterface (BaseInterface):