/*
 * SmartHome server: Plug-in logic
 *
 * Copyright (C) 2010 Daniel Pisi <dan.pisi@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 */

/**
 * @file shlogic.h
 * @brief Implements a simple logic gate
 * @author Daniel Pisi
 */

#ifndef SHLOGIC_H
#define SHLOGIC_H

#include <QtCore/QCoreApplication>
#include <QtPlugin>
#include <QObject>
#include "shobjecthelper.h"

// -----------------------------------------------------------------------------

/**
 * \class ShLogic
 * \brief Implements a simple logic gate
 */
class ShLogic : public ShObjectHelper
{
    Q_OBJECT
    Q_INTERFACES(ShObject)

public:
    ShLogic();
    virtual ~ShLogic() {};
    virtual bool init(QString param);
    virtual void updatePins(const QList<ShPin> &pins);
    virtual void processMessage(ShMessagePtr message);

private:
    enum GateType
    {
        gtAnd, gtNand, gtOr, gtNor, gtXor
    };

    void updateOutput();

    GateType mGateType;
    QMap<QString,bool> mInputs;
    bool mOutput;
};
// -----------------------------------------------------------------------------

#endif // SHLOGIC_H
