class ugcs::vsm::Service_discovery_processor

Overview

#include <service_discovery_processor.h>

class Service_discovery_processor: public ugcs::vsm::Request_context
{
public:
    // typedefs

    typedef std::shared_ptr<Service_discovery_processor> Ptr;
    typedef std::weak_ptr<Service_discovery_processor> Weak_ptr;
    typedef Callback_proxy<void, std::string, std::string, std::string, std::string, bool> Detection_handler;

    // construction

    Service_discovery_processor(Socket_address::Ptr muticast_adress = Socket_address::Create(DEFAULT_DISCOVERY_ADDRESS, DEFAULT_DISCOVERY_PORT));

    // methods

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename... Args>
    static Ptr Get_instance(Args&&... args);

    template <class __Callable, typename... __Args>
    __DEFINE_CALLBACK_BUILDER_BODY(
        Make_detection_handler,
        (std::string, std::string, std::string, std::string, bool),
        ("", "", "", "", true)
        );

    void Advertise_service(
        const std::string& type,
        const std::string& name,
        const std::string& location
        );

    void Unadvertise_service(
        const std::string& type,
        const std::string& name,
        const std::string& location
        );

    void Subscribe_for_service(const std::string& type, Detection_handler handler, Request_processor::Ptr context);
    void Search_for_service(const std::string& type);
    void Unsubscribe_from_service(const std::string& type);
};

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<Request_container> Ptr;
    typedef std::weak_ptr<Request_container> Weak_ptr;
    typedef std::shared_ptr<Request_context> Ptr;
    typedef std::weak_ptr<Request_context> Weak_ptr;

    // enums

    enum Type;

    // classes

    class Request;
    class Request_waiter;

    // methods

    template <typename... Args>
    static Ptr Create(Args&&... args);

    virtual Type Get_type() const;
    bool Check_type(Type mask);
    void Submit_request(Request::Ptr request);
    void Submit_request_locked(Request::Ptr request, Request_waiter::Locker locker);
    int Process_requests(int requests_limit = 0);
    int Process_requests(std::unique_lock<std::mutex>& lock, int requests_limit = 0);
    void Set_waiter(Request_waiter::Ptr waiter);
    Request_waiter::Ptr Get_waiter() const;
    const std::string& Get_name();
    void Enable();
    void Disable();
    bool Is_enabled() const;

    template <typename... Args>
    static Ptr Create(Args&&... args);

    virtual Type Get_type() const;
    Request_container(const std::string& name, Request_waiter::Ptr waiter = Request_waiter::Create());

Detailed Documentation

Typedefs

typedef std::shared_ptr<Service_discovery_processor> Ptr

Pointer type.

typedef std::weak_ptr<Service_discovery_processor> Weak_ptr

Pointer type.

typedef Callback_proxy<void, std::string, std::string, std::string, std::string, bool> Detection_handler

Detector function.

User must supply this function via Subscribe_for_service() call. It should follow the signature:

void Handler(string type, string name, string location, string instance_id, bool alive)

Handler parameters: The Handler will get invoked when NOTIFY or M-SEARCH response is received for given service type.

Parameters:

type

service type

name

service name

location

location uri

instance_id

random (unique) string which can be used to distinguish services with equal names to prevent multiple connections to the same service via multiple locations.

alive

true if message is ssdp::alive. false if message is ssdp::byebye.

Methods

template <typename... Args>
static Ptr Create(Args&&... args)

Create an instance.

template <typename... Args>
static Ptr Get_instance(Args&&... args)

Get global or create new object instance.

template <class __Callable, typename... __Args>
__DEFINE_CALLBACK_BUILDER_BODY(
    Make_detection_handler,
    (std::string, std::string, std::string, std::string, bool),
    ("", "", "", "", true)
    )

Builder for detection handler.

void Advertise_service(
    const std::string& type,
    const std::string& name,
    const std::string& location
    )

Sends out the NOTIFY ssdp:alive on all available interfaces.

Responds to M-SEARCH requests for given type.

Parameters:

location

Can contain special tag {local_address}, which will be replaced by the address of interface when sending out responses and notifications. Thus user application does not need to know local ip addresses even if dns is not used. Example: “http://{local_address}:12345/my_service/location.point” The broadcasted packet will have ‘Location:’ header like this: “Location: http://192.168.1.112:12345/my_service/location.point

void Unadvertise_service(
    const std::string& type,
    const std::string& name,
    const std::string& location
    )

Sends out the NOTIFY ssdp:byebye on all available interfaces.

Stop responding to M-SEARCH requests for given type.

void Subscribe_for_service(const std::string& type, Detection_handler handler, Request_processor::Ptr context)

Sends out the M-SEARCH on all available interfaces.

Calls handler on each NOTIFY ssdp:alive and M-SEARCH response for given service type. handler must be valid callback until Unsubscribe_from_service() called.

void Search_for_service(const std::string& type)

Sends out the M-SEARCH on all available interfaces.

In order to receive responses Subscribe_for_service() must be called beforehand. Does nothing if there are no active subscriptions.

void Unsubscribe_from_service(const std::string& type)

Remove service type from subscription list.

Detection handlers will not be called for this service type.