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

#include <tango/client/GroupAttrReply.h>

namespace Tango
{

//=============================================================================
// class GroupAttrReply : reply to read/write attr on a group
//=============================================================================
GroupAttrReply::GroupAttrReply() = default;

//-----------------------------------------------------------------------------
GroupAttrReply::GroupAttrReply(const std::string &_dev_name,
                               const std::string &_obj_name,
                               const Tango::DeviceAttribute &_dev_attr) :
    GroupReply(_dev_name, _obj_name, true),
    data_m(_dev_attr)
{
    //-noop impl
}

//-----------------------------------------------------------------------------
GroupAttrReply::GroupAttrReply(const std::string &_dev_name,
                               const std::string &_obj_name,
                               const Tango::DevFailed &_exception) :
    GroupReply(_dev_name, _obj_name, _exception, true)
{
    //-noop impl
}

//-----------------------------------------------------------------------------
GroupAttrReply::GroupAttrReply(const std::string &_dev_name,
                               const std::string &_obj_name,
                               bool _group_element_enabled) :
    GroupReply(_dev_name, _obj_name, _group_element_enabled)
{
    //-noop impl
}

GroupAttrReply::~GroupAttrReply() = default;

GroupAttrReply::GroupAttrReply(const GroupAttrReply &) = default;
GroupAttrReply &GroupAttrReply::operator=(const GroupAttrReply &) = default;

GroupAttrReply::GroupAttrReply(GroupAttrReply &&) = default;
GroupAttrReply &GroupAttrReply::operator=(GroupAttrReply &&) = default;

//-----------------------------------------------------------------------------
/*const*/ DeviceAttribute &GroupAttrReply::get_data()
{
    if(!group_element_enabled_m && exception_enabled)
    {
        Tango::DevErrorList errors(1);
        errors.length(1);
        errors[0].severity = Tango::ERR;
        errors[0].desc = Tango::string_dup("no available data");
        errors[0].reason = Tango::string_dup("no data - group member is disabled");
        errors[0].origin = Tango::string_dup(TANGO_EXCEPTION_ORIGIN);
        DevFailed df(errors);
        throw df;
    }
    else if(has_failed_m && exception_enabled)
    {
        throw exception_m;
    }
    std::bitset<DeviceAttribute::numFlags> bs;
    data_m.exceptions(exception_enabled ? bs.set() : bs.reset());
    return data_m;
}

} // namespace Tango
