#ifndef SEARCH_DEV_HPP_
#define SEARCH_DEV_HPP_
#include <boost/container/detail/singleton.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/asio.hpp>
#include <json/json.h>
#include "common/global.hpp"
#include "common/common_func.hpp"


class SearchDev {
public:
    SearchDev(boost::asio::io_service &ioservice);
    ~SearchDev();
    void MultiCastRecv();
    void MultiCastRecv_1();
    void Run();
    void Stop();
    void Restart();

private:
    void Init();
    void GwRouteInit();
    void HandleRecv_1(const boost::system::error_code &pEc, size_t pBytesRecv);
    void HandleSend_1(const char *pMsg, const boost::system::error_code &pEc);

private:
    enum { BUF_LENGTH = 128 };
    boost::asio::ip::udp::socket mSockRecv_1; //组播地址1
    boost::asio::ip::udp::endpoint mRecvEP1;
    boost::asio::ip::udp::endpoint mListenEP1;
    boost::asio::ip::udp::endpoint mSendEndpoint1; //组播发送端点
    char mRecvBuf1[BUF_LENGTH];
    char mSendBuf1[BUF_LENGTH];
};

typedef boost::container::dtl::singleton_default<SearchDev> search_dev;

#endif // SEARCH_DEV_HPP_
