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

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

#include <tango/server/DServer.h>
#include <tango/server/Util.h>

namespace Tango
{

//+-------------------------------------------------------------------------
//
// method:       StartTelemetry::StartTelemetry
//
// description:  Constructor for Command class StartTelemetry
//
//--------------------------------------------------------------------------
StartTelemetry::StartTelemetry(const char *name,
                               Tango::CmdArgType in,
                               Tango::CmdArgType out,
                               const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       StartTelemetry::execute
//
// description:  Trigger the method implementing StartTelemetry
//
//--------------------------------------------------------------------------
CORBA::Any *StartTelemetry::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "StartTelemetry::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->start_telemetry(argin);

    CORBA::Any *ret = return_empty_any("StartTelemetry");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       StopTelemetry::StopTelemetry
//
// description:  Constructor for Command class StopTelemetry
//
//--------------------------------------------------------------------------
StopTelemetry::StopTelemetry(const char *name,
                             Tango::CmdArgType in,
                             Tango::CmdArgType out,
                             const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       StopTelemetry::execute
//
// description:  Trigger the method implementing StopTelemetry
//
//--------------------------------------------------------------------------
CORBA::Any *StopTelemetry::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "StopTelemetry::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->stop_telemetry(argin);

    CORBA::Any *ret = return_empty_any("StopTelemetry");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       IsTelemetryEnabled::IsTelemetryEnabled
//
// description:  Constructor for Command class IsTelemetryEnabled
//
//--------------------------------------------------------------------------
IsTelemetryEnabled::IsTelemetryEnabled(const char *name,
                                       Tango::CmdArgType in,
                                       Tango::CmdArgType out,
                                       const std::string &in_desc,
                                       const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       IsTelemetryEnabled::execute
//
// description:  Trigger the method implementing IsTelemetryEnabled
//
//--------------------------------------------------------------------------
CORBA::Any *IsTelemetryEnabled::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "IsTelemetryEnabled::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->is_telemetry_enabled_ds(argin));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTopics::SetTelemetryTopics
//
// description:  Constructor for Command class SetTelemetryTopics
//
//--------------------------------------------------------------------------
SetTelemetryTopics::SetTelemetryTopics(const char *name,
                                       Tango::CmdArgType in,
                                       Tango::CmdArgType out,
                                       const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTopics::execute
//
// description:  Trigger the method implementing SetTelemetryTopics
//
//--------------------------------------------------------------------------
CORBA::Any *SetTelemetryTopics::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "SetTelemetryTopics::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->set_telemetry_topics_ds(argin);

    CORBA::Any *ret = return_empty_any("SetTelemetryTopics");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTopics::GetTelemetryTopics
//
// description:  Constructor for Command class GetTelemetryTopics
//
//--------------------------------------------------------------------------
GetTelemetryTopics::GetTelemetryTopics(const char *name,
                                       Tango::CmdArgType in,
                                       Tango::CmdArgType out,
                                       const std::string &in_desc,
                                       const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTopics::execute
//
// description:  Trigger the method implementing GetTelemetryTopics
//
//--------------------------------------------------------------------------
CORBA::Any *GetTelemetryTopics::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "GetTelemetryTopics::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->get_telemetry_topics_ds(argin));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTracing::SetTelemetryTracing
//
// description:  Constructor for Command class SetTelemetryTracing
//
//--------------------------------------------------------------------------
SetTelemetryTracing::SetTelemetryTracing(const char *name,
                                         Tango::CmdArgType in,
                                         Tango::CmdArgType out,
                                         const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTracing::execute
//
// description:  Trigger the method implementing SetTelemetryTracing
//
//--------------------------------------------------------------------------
CORBA::Any *SetTelemetryTracing::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "SetTelemetryTracing::execute() entry" << std::endl;

    const DevVarLongStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarLongStringArray");
    }

    (static_cast<DServer *>(device))->set_telemetry_tracing_ds(argin);

    CORBA::Any *ret = return_empty_any("SetTelemetryTracing");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTracing::GetTelemetryTracing
//
// description:  Constructor for Command class GetTelemetryTracing
//
//--------------------------------------------------------------------------
GetTelemetryTracing::GetTelemetryTracing(const char *name,
                                         Tango::CmdArgType in,
                                         Tango::CmdArgType out,
                                         const std::string &in_desc,
                                         const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTracing::execute
//
// description:  Trigger the method implementing GetTelemetryTracing
//
//--------------------------------------------------------------------------
CORBA::Any *GetTelemetryTracing::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "GetTelemetryTracing::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->get_telemetry_tracing(argin));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTracingEndpoints::SetTelemetryTracingEndpoints
//
// description:  Constructor for Command class SetTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
SetTelemetryTracingEndpoints::SetTelemetryTracingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryTracingEndpoints::execute
//
// description:  Trigger the method implementing SetTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *SetTelemetryTracingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "SetTelemetryTracingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->set_telemetry_tracing_endpoints_ds(argin);

    CORBA::Any *ret = return_empty_any("SetTelemetryTracingEndpoints");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTracingEndpoints::GetTelemetryTracingEndpoints
//
// description:  Constructor for Command class GetTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
GetTelemetryTracingEndpoints::GetTelemetryTracingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc,
                                                           const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryTracingEndpoints::execute
//
// description:  Trigger the method implementing GetTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *GetTelemetryTracingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "GetTelemetryTracingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->get_telemetry_tracing_endpoints_ds(argin));
}

//+-------------------------------------------------------------------------
//
// method:       AddTelemetryTracingEndpoints::AddTelemetryTracingEndpoints
//
// description:  Constructor for Command class AddTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
AddTelemetryTracingEndpoints::AddTelemetryTracingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       AddTelemetryTracingEndpoints::execute
//
// description:  Trigger the method implementing AddTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *AddTelemetryTracingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "AddTelemetryTracingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->add_telemetry_tracing_endpoints(argin);

    CORBA::Any *ret = return_empty_any("AddTelemetryTracingEndpoints");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       RemoveTelemetryTracingEndpoints::RemoveTelemetryTracingEndpoints
//
// description:  Constructor for Command class RemoveTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
RemoveTelemetryTracingEndpoints::RemoveTelemetryTracingEndpoints(const char *name,
                                                                 Tango::CmdArgType in,
                                                                 Tango::CmdArgType out,
                                                                 const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       RemoveTelemetryTracingEndpoints::execute
//
// description:  Trigger the method implementing RemoveTelemetryTracingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *RemoveTelemetryTracingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "RemoveTelemetryTracingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->remove_telemetry_tracing_endpoints(argin);

    CORBA::Any *ret = return_empty_any("RemoveTelemetryTracingEndpoints");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryLogging::SetTelemetryLogging
//
// description:  Constructor for Command class SetTelemetryLogging
//
//--------------------------------------------------------------------------
SetTelemetryLogging::SetTelemetryLogging(const char *name,
                                         Tango::CmdArgType in,
                                         Tango::CmdArgType out,
                                         const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryLogging::execute
//
// description:  Trigger the method implementing SetTelemetryLogging
//
//--------------------------------------------------------------------------
CORBA::Any *SetTelemetryLogging::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "SetTelemetryLogging::execute() entry" << std::endl;

    const DevVarLongStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarLongStringArray");
    }

    (static_cast<DServer *>(device))->set_telemetry_logging_ds(argin);

    CORBA::Any *ret = return_empty_any("SetTelemetryLogging");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryLogging::GetTelemetryLogging
//
// description:  Constructor for Command class GetTelemetryLogging
//
//--------------------------------------------------------------------------
GetTelemetryLogging::GetTelemetryLogging(const char *name,
                                         Tango::CmdArgType in,
                                         Tango::CmdArgType out,
                                         const std::string &in_desc,
                                         const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryLogging::execute
//
// description:  Trigger the method implementing GetTelemetryLogging
//
//--------------------------------------------------------------------------
CORBA::Any *GetTelemetryLogging::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "GetTelemetryLogging::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->get_telemetry_logging(argin));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryLoggingEndpoints::SetTelemetryLoggingEndpoints
//
// description:  Constructor for Command class SetTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
SetTelemetryLoggingEndpoints::SetTelemetryLoggingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       SetTelemetryLoggingEndpoints::execute
//
// description:  Trigger the method implementing SetTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *SetTelemetryLoggingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "SetTelemetryLoggingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->set_telemetry_logging_endpoints_ds(argin);

    CORBA::Any *ret = return_empty_any("SetTelemetryLoggingEndpoints");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryLoggingEndpoints::GetTelemetryLoggingEndpoints
//
// description:  Constructor for Command class GetTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
GetTelemetryLoggingEndpoints::GetTelemetryLoggingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc,
                                                           const std::string &out_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
    set_out_type_desc(const_cast<std::string &>(out_desc));
}

//+-------------------------------------------------------------------------
//
// method:       GetTelemetryLoggingEndpoints::execute
//
// description:  Trigger the method implementing GetTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *GetTelemetryLoggingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "GetTelemetryLoggingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    return insert((static_cast<DServer *>(device))->get_telemetry_logging_endpoints_ds(argin));
}

//+-------------------------------------------------------------------------
//
// method:       AddTelemetryLoggingEndpoints::AddTelemetryLoggingEndpoints
//
// description:  Constructor for Command class AddTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
AddTelemetryLoggingEndpoints::AddTelemetryLoggingEndpoints(const char *name,
                                                           Tango::CmdArgType in,
                                                           Tango::CmdArgType out,
                                                           const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       AddTelemetryLoggingEndpoints::execute
//
// description:  Trigger the method implementing AddTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *AddTelemetryLoggingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "AddTelemetryLoggingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->add_telemetry_logging_endpoints(argin);

    CORBA::Any *ret = return_empty_any("AddTelemetryLoggingEndpoints");
    return ret;
}

//+-------------------------------------------------------------------------
//
// method:       RemoveTelemetryLoggingEndpoints::RemoveTelemetryLoggingEndpoints
//
// description:  Constructor for Command class RemoveTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
RemoveTelemetryLoggingEndpoints::RemoveTelemetryLoggingEndpoints(const char *name,
                                                                 Tango::CmdArgType in,
                                                                 Tango::CmdArgType out,
                                                                 const std::string &in_desc) :
    Command(name, in, out)
{
    set_in_type_desc(const_cast<std::string &>(in_desc));
}

//+-------------------------------------------------------------------------
//
// method:       RemoveTelemetryLoggingEndpoints::execute
//
// description:  Trigger the method implementing RemoveTelemetryLoggingEndpoints
//
//--------------------------------------------------------------------------
CORBA::Any *RemoveTelemetryLoggingEndpoints::execute(DeviceImpl *device, const CORBA::Any &in_any)
{
    TANGO_LOG_DEBUG << "RemoveTelemetryLoggingEndpoints::execute() entry" << std::endl;

    const DevVarStringArray *argin;
    if(!(in_any >>= argin))
    {
        TANGO_THROW_EXCEPTION(API_IncompatibleCmdArgumentType,
                              "Imcompatible command argument type, expected type is: DevVarStringArray");
    }

    (static_cast<DServer *>(device))->remove_telemetry_logging_endpoints(argin);

    CORBA::Any *ret = return_empty_any("RemoveTelemetryLoggingEndpoints");
    return ret;
}

} // namespace Tango
