/*
 * SmartHome server: Base of the system
 *
 * 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 shmessage.h
 * @brief Stores messages transferred between plug-ins
 * @author Daniel Pisi
 */

#ifndef SHMESSAGE_H
#define SHMESSAGE_H

#include <QString>
#include <QVariant>
#include <QSharedPointer>

#include "shpin.h"

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

class ShMessage;

/**
 * typedef ShMessagePtr
 * \brief Shared pointer to ShMessage object
 */
typedef QSharedPointer<ShMessage> ShMessagePtr;

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

/**
 * \class ShMessage
 * \brief Defines and stores messages transferred between plug-ins
 */
class ShMessage
{
public:
    enum MessageType
    {
        mtUnknown = 0, mtValue, mtGet, mtAck, mtReload, mtError
    };

    ShMessage();

    bool        setMsgType(QString typeStr);
    QString     msgTypeStr();

    void        setMsgType(MessageType msgType)  { mMsgType = msgType;       };
    MessageType msgType()                        { return mMsgType;          };

    void        setPin(ShPin pin)                { mPin = pin;               };
    ShPin       pin()                            { return mPin;              };

    void        setSignal(QString signal)        { mSignal = signal;         };
    QString     signal()                         { return mSignal;           };

    void        setValue(QVariant value)         { mValue = value;           };
    QVariant    value()                          { return mValue;            };

    void        setSenderId(int senderId)        { mSenderId = senderId;     };
    int         senderId()                       { return mSenderId;         };
    void        setReceiverId(int receiverId)    { mReceiverId = receiverId; };
    int         receiverId()                     { return mReceiverId;       };

    void        setRequireAck(bool requireAck)   { mRequireAck = requireAck; };
    bool        requireAck()                     { return mRequireAck;       };

private:
    MessageType mMsgType;
    QString mSignal;
    QVariant mValue;
    int mSenderId, mReceiverId;
    ShPin mPin;
    bool mRequireAck;
};
// -----------------------------------------------------------------------------

#endif // SHMESSAGE_H
