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

#ifndef TANGO_CLIENT_GROUPELEMENTFACTORY_H
#define TANGO_CLIENT_GROUPELEMENTFACTORY_H

#include <tango/client/GroupElement.h>

#include <string>
#include <vector>

namespace Tango
{
//=============================================================================
// Misc. Typedefs
//=============================================================================
typedef std::vector<std::string> DeviceNames;

//=============================================================================
// class GroupElementFactory : a GroupElement factory
//=============================================================================
class GroupElementFactory
{
  public:
    //- instantiate the GroupElement which name matches the specified pattern with the specified timeout
    //- timeout = -1 => do not change the timeout
    static GroupElements instanciate(const std::string &name_or_pattern, int timeout_millis = -1);

  private:
    static void parse_name(const std::string &p, std::string &db_host, int &db_port, std::string &dev_pattern);

    static GroupElements create_group_elements(const DeviceNames &, int timeout_millis);
    static DeviceNames resolve_device_names(const std::string &name_or_pattern);
    static DeviceNames resolve_local_device_names(const std::string &name_or_pattern);
    static DeviceNames
        resolve_remote_device_names(int db_port, std::string &db_host, std::string &name_or_pattern_without_host);
    static DeviceNames add_host_and_port_to_device_names(const DeviceNames &, const std::string &db_host, int db_port);
    static std::string build_full_device_name(const std::string &host, int port, const std::string &device_name);

    //- forbidden methods
    GroupElementFactory();
    ~GroupElementFactory();
    GroupElementFactory &operator=(const GroupElementFactory &other);
};

} // namespace Tango

#endif /* TANGO_CLIENT_GROUPELEMENTFACTORY_H */
