lundi 10 février 2020

Architecture Design of Command&Control application center for displays

I am facing dilemma on how to best design the following functionality. What design patterns and OOD principles should I use.

For simplicity sake following are basic requirements:

  • displays type can be any of the following: PC Monitor, LG TV, Samsung TV, or other manufacturer
  • displays can have different functionalities, for example: turn on, turn off, sleep, etc..
  • there should be available some metadata about displays, like
    • is CEC link available and working
    • is RS232 link available and working
    • is HDMI cable connected
    • is display currently turned on or off
    • get/set display resolution, etc...
  • communication with displays can be done in any of the following ways
    • RS232 serial cable commands (which are specific to manufacturer)
    • HDMI CEC commands
    • as a fallback (and for the monitors) we use EnergyStar features aka. xset dpms force off

I'm more familiar with the php, but I will probably implement this in python as it is more systems language and I suppose also more appropriate for this task.

In the end it could be something simple as following I suppose. It could manually figure out which link it has available for communication(cec|rs232) and which command it should send along that link depending on manufacturer of the display.

$display = new Display();
if ($display->isConnected() && $display->isOn()) {
    $display->turnOff();
}
$forfun = $display->getVendorName();

I was thinking about implementing something along this lines, but I can already some some problems with this:

/** DisplayFactory classes */
abstract class AbstractDisplayFactory {
    abstract function makeDisplay();
}

class LGDisplayFactory extends AbstractDisplayFactory {
    private $context = "LG";
    function makeDisplay() {
        return new LGDisplay;
    }
}

class SamsungDisplayFactory extends AbstractDisplayFactory {
    private $context = "Samsung";
    function makeDisplay() {
        return new SamsungDisplay;
    }
}

/** Display classes */
abstract class AbstractDisplay {

    abstract function turnOn();}
    abstract function turnOff();

    function hasCecLink() {
        //return status;
    }
    function hasSerialLink() {
        //return status;
    }
    function isHDMICableConnected() {
        // return status;
    }

    // ....
}

class LGDisplay extends AbstractDisplay {

    function turnOff() {
        if($this->hasCecLink()) {
            // turn off via HDMI CEC - vendor agnostic commands
            // implementation of this would be better placed in a more generic class since
            // is vendor agnostic command, and we would not need to repeat it for every display
        }
        else if($this->hasSerialLink()) {
            // turn off via rs232 - vendor specific commands
        }
        else {
            // shell_exec('xset dpms force off')
            // this also would be better placed in a more generic class
        }
    }

    // ...
}

class SamsungDisplay extends AbstractDisplay {
    // similar as for LGDisplay class
}

Also, could I more easily devise a solution if I would be thinking differently(more abstract) about the different elements involved, for example "is display connected" instead of "is HDMI cable connected", etc..?

Aucun commentaire:

Enregistrer un commentaire