from saleae.analyzers import AnalyzerFrame
from abc import ABC, abstractmethod

"""Parent class for a second layer analyzer (SLA)
that defines four abstract methods and their default
implementation.

This methods will be called in the I3C HLA and
each SLA should overwrite them to decode the
protocol
"""
class SecondLayerHLA:
    @abstractmethod
    def __init__(self):
        pass

    """This method updates the ccc_dict dictionary to overwrite
    the vendor specific CCC commands.
    """
    @abstractmethod
    def update_ccc(self, ccc_dict: dict) -> None:
        pass

    """This method add the result type entries to the dictionary
    so it support the transactions specific of the SLA.
    """
    @abstractmethod
    def update_result_types(self, result_types: dict) -> None:
        pass

    """This method will be called in the I3C HLA each time a frame
    is about to be committed so it can be processed first by the
    SLA.
    When overwriting this method it must always return an
    AnalyzerFrame or None if nothing is to be committed.
    """
    @abstractmethod
    def instruction_decoder(self, frame: AnalyzerFrame) -> AnalyzerFrame:
        return frame

    """This method will be called when an aborted event has been received.
    When overwritten this method returns an AnalyzerFrame that represents what
    has to be shown in the abort case.
    """
    @abstractmethod
    def handle_abort_message(self, temp_frame: AnalyzerFrame, end_time) -> AnalyzerFrame:
        return temp_frame