/*
 * SPDX-FileCopyrightText: 2004 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <tango/server/AttrValue.h>

#include <tango/internal/server/attribute_utils.h>

#include <tango/client/Database.h>
#include <tango/common/defines.h>
#include <tango/server/Attribute.h>
#include <tango/server/DeviceImpl.h>
#include <tango/server/EventSupplier.h>
#include <tango/server/FwdAttribute.h>
#include <tango/server/LogAdapter.h>
#include <tango/server/MultiClassAttribute.h>

#include <algorithm>
#include <functional>

#ifdef _TG_WINDOWS_
  #include <sys/types.h>
#endif /* _TG_WINDOWS_ */

namespace Tango
{

void LastAttrValue::store(const AttributeValue_5 *attr_5,
                          const AttributeValue_4 *attr_4,
                          const AttributeValue_3 *attr_3,
                          const AttributeValue *attr,
                          DevFailed *error)
{
    if(error != nullptr)
    {
        except = *error;
        err = true;
    }
    else
    {
        if(attr_5 != nullptr)
        {
            quality = attr_5->quality;
            value_4 = attr_5->value;
        }
        else if(attr_4 != nullptr)
        {
            quality = attr_4->quality;
            value_4 = attr_4->value;
        }
        else if(attr_3 != nullptr)
        {
            quality = attr_3->quality;
            value = attr_3->value;
        }
        else if(attr != nullptr)
        {
            quality = attr->quality;
            value = attr->value;
        }

        err = false;
    }

    inited = true;
}

} // namespace Tango
