/*
 * 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.cpp
 * @brief Stores messages transferred between plug-ins
 * @author Daniel Pisi
 */

#include "shmessage.h"

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

/**
 * \brief Constructor of ShMessage, an initialization of the object
 */
ShMessage::ShMessage()
{
    mMsgType = mtUnknown;
    mSenderId = 0;
    mReceiverId = 0;
    mRequireAck = false;
}
// -----------------------------------------------------------------------------

/**
 * \brief Sets a type of the message according to given string
 * \param typeStr Message type in a form of string
 * \return true if the type has been recognized
 */
bool ShMessage::setMsgType(QString typeStr)
{
    mMsgType = (typeStr == "set")   ? mtValue :
               (typeStr == "value") ? mtValue :
               (typeStr == "get")   ? mtGet :
               (typeStr == "setOk") ? mtAck :
               (typeStr == "error") ? mtError :
               (typeStr == "reload") ? mtReload : mtUnknown;

    return mMsgType != mtUnknown;
}
// -----------------------------------------------------------------------------

/**
 * \brief Returns the message type in a form of string
 * \return Message type in a form of string
 */
QString ShMessage::msgTypeStr()
{
    switch (mMsgType)
    {
    case mtValue:  return "value";
    case mtGet:    return "get";
    case mtAck:    return "setOk";
    case mtReload: return "reload";
    case mtError:  return "error";
    default:       return "unknown";
    }
}
// -----------------------------------------------------------------------------
