Commit dbf2257e authored by Thomas Ives's avatar Thomas Ives Committed by Thomas Braun
Browse files

src/server/attrsetval.cpp: Move into Attribute.cpp

parent a5a618df
Loading
Loading
Loading
Loading
+98 −0
Original line number Diff line number Diff line
@@ -6863,4 +6863,102 @@ template void Attribute::set_value(Tango::DevLong *p_data, long x, long y, bool
template void Attribute::set_value(Tango::DevULong *p_data, long x, long y, bool release);
template void Attribute::set_value(Tango::DevLong64 *p_data, long x, long y, bool release);
template void Attribute::set_value(Tango::DevULong64 *p_data, long x, long y, bool release);

/// @cond DO_NOT_DOCUMENT

/*
 * method: Attribute::set_value and Attribute::set_value_date_quality for Tango::DevEncoded dtype
 *
 * These are two special realizations of Attribute::set_value and Attribute::set_value_date_quality (see
 * attrsetval_templ.h) for Tango::DevEncoded dtype in case if user calls these method with separate data_str and data.
 *
 * In this case we make an intermediate helper Tango::DevEncoded variable, copy user data there
 * and then call method realizations from attrsetval_templ.h
 */

void Attribute::set_value(Tango::DevString *p_data_str, Tango::DevUChar *p_data, long size, bool release)
{
    TANGO_LOG_DEBUG << "Attribute::set_value() called " << std::endl;

    if(p_data_str == nullptr || p_data == nullptr)
    {
        TangoSys_OMemStream o;
        o << "Data pointer for attribute " << name << " is NULL!" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    if(!release)
    {
        enc_help.encoded_format = Tango::string_dup(*p_data_str);
        enc_help.encoded_data.replace(size, size, p_data, false);

        set_value(&enc_help);
    }
    else
    {
        DevEncoded *enc_ptr = new DevEncoded;
        enc_ptr->encoded_format = Tango::string_dup(*p_data_str);
        delete[] *p_data_str;
        enc_ptr->encoded_data.replace(size, size, p_data, true);

        set_value(enc_ptr, 1, 0, true);
    }
}

void Attribute::set_value(Tango::EncodedAttribute *attr)
{
    TANGO_LOG_DEBUG << "Attribute::set_value() called " << std::endl;

    CHECK_PTR(attr, name);

    Tango::DevString *f = attr->get_format();
    Tango::DevUChar *d = attr->get_data();
    long size = attr->get_size();

    if(*f == nullptr)
    {
        TangoSys_OMemStream o;
        o << "DevEncoded format for attribute " << name << " not specified" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    if(size == 0 || (d == nullptr))
    {
        TangoSys_OMemStream o;
        o << "DevEncoded data for attribute " << name << " not specified" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    set_value(f, d, size, false);

    if(attr->get_exclusion())
    {
        set_user_attr_mutex(attr->get_mutex());
    }
}

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

void Attribute::set_value_date_quality(
    Tango::DevString *p_data_str, Tango::DevUChar *p_data, long size, time_t t, Tango::AttrQuality qual, bool release)
{
    set_value(p_data_str, p_data, size, release);
    set_quality(qual, false);
    set_date(t);
}

void Attribute::set_value_date_quality(Tango::DevString *p_data_str,
                                       Tango::DevUChar *p_data,
                                       long size,
                                       const TangoTimestamp &t,
                                       Tango::AttrQuality qual,
                                       bool release)
{
    set_value(p_data_str, p_data, size, release);
    set_quality(qual, false);
    set_date(t);
}

/// @endcond

} // namespace Tango
+0 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ set(SOURCES Attr.cpp
            Attribute.cpp
            AttrValue.cpp
            attribute_utils.cpp
            attrsetval.cpp
            AttrManip.cpp
            AutoTangoMonitor.cpp
            basiccommand.cpp

src/server/attrsetval.cpp

deleted100644 → 0
+0 −116
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2013 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <tango/server/Attribute.h>
#include <tango/server/EventSupplier.h>
#include <tango/server/MultiClassAttribute.h>
#include <tango/server/tango_config.h>

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

namespace Tango
{

/// @cond DO_NOT_DOCUMENT

/*
 * method: Attribute::set_value and Attribute::set_value_date_quality for Tango::DevEncoded dtype
 *
 * These are two special realizations of Attribute::set_value and Attribute::set_value_date_quality (see
 * attrsetval_templ.h) for Tango::DevEncoded dtype in case if user calls these method with separate data_str and data.
 *
 * In this case we make an intermediate helper Tango::DevEncoded variable, copy user data there
 * and then call method realizations from attrsetval_templ.h
 */

void Attribute::set_value(Tango::DevString *p_data_str, Tango::DevUChar *p_data, long size, bool release)
{
    TANGO_LOG_DEBUG << "Attribute::set_value() called " << std::endl;

    if(p_data_str == nullptr || p_data == nullptr)
    {
        TangoSys_OMemStream o;
        o << "Data pointer for attribute " << name << " is NULL!" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    if(!release)
    {
        enc_help.encoded_format = Tango::string_dup(*p_data_str);
        enc_help.encoded_data.replace(size, size, p_data, false);

        set_value(&enc_help);
    }
    else
    {
        DevEncoded *enc_ptr = new DevEncoded;
        enc_ptr->encoded_format = Tango::string_dup(*p_data_str);
        delete[] *p_data_str;
        enc_ptr->encoded_data.replace(size, size, p_data, true);

        set_value(enc_ptr, 1, 0, true);
    }
}

void Attribute::set_value(Tango::EncodedAttribute *attr)
{
    TANGO_LOG_DEBUG << "Attribute::set_value() called " << std::endl;

    CHECK_PTR(attr, name);

    Tango::DevString *f = attr->get_format();
    Tango::DevUChar *d = attr->get_data();
    long size = attr->get_size();

    if(*f == nullptr)
    {
        TangoSys_OMemStream o;
        o << "DevEncoded format for attribute " << name << " not specified" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    if(size == 0 || (d == nullptr))
    {
        TangoSys_OMemStream o;
        o << "DevEncoded data for attribute " << name << " not specified" << std::ends;
        TANGO_THROW_EXCEPTION(API_AttrOptProp, o.str());
    }

    set_value(f, d, size, false);

    if(attr->get_exclusion())
    {
        set_user_attr_mutex(attr->get_mutex());
    }
}

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

void Attribute::set_value_date_quality(
    Tango::DevString *p_data_str, Tango::DevUChar *p_data, long size, time_t t, Tango::AttrQuality qual, bool release)
{
    set_value(p_data_str, p_data, size, release);
    set_quality(qual, false);
    set_date(t);
}

void Attribute::set_value_date_quality(Tango::DevString *p_data_str,
                                       Tango::DevUChar *p_data,
                                       long size,
                                       const TangoTimestamp &t,
                                       Tango::AttrQuality qual,
                                       bool release)
{
    set_value(p_data_str, p_data, size, release);
    set_quality(qual, false);
    set_date(t);
}

/// @endcond

} // namespace Tango