# This file is part of Sigviewr.
# This project is licensed under the GNU GPL (version 3 or higher).
# Copyright 2014 by Clemens Brunner and Thomas Brunner.


from os import linesep
from collections import OrderedDict


class MetaInfo(object):
    """Meta information of a stream."""
    
    def __init__(self):
        self.general = OrderedDict()  # Contains information about the data stream itself, such as type, version, name, recording time, ...
        self.subject = OrderedDict()  # Contains subject-specific information, such as ID, gender, age, ...
        self.streams = []  # Contains information about the individual streams (e.g. EEG, EMG, EOG, ...), such as number of channels, sampling rate, ...
        self.channels = [[]]  # Contains information about each channel in each stream, such as the label

    def __repr__(self):
        tempstr = ""
        if len(self.general) > 0:
            tempstr = "General"
            for key, value in self.general.items():
                tempstr = linesep.join([tempstr, " " + key + " : " + value])
        if len(self.subject) > 0:
            tempstr = linesep.join([tempstr, "Subject"])
            for key, value in self.subject.items():
                tempstr = linesep.join([tempstr, " " + key + " : " + value])
        return tempstr
    

class StreamReader(object):
    """Abstract base class for reading streams (files or online streams)."""
    
    def __init__(self):
        self.name = None
        self.metainfo = MetaInfo()
        
    def open(self):
        raise NotImplementedError
    
    def close(self):
        raise NotImplementedError
    

class StreamReaderError(Exception):
    pass
