OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Bonjour::priv Struct Reference
Collaboration diagram for Slic3r::Bonjour::priv:

Public Member Functions

 priv (std::string &&service)
void lookup_perform ()
void resolve_perform ()

Public Attributes

const std::string service
std::string protocol
std::string service_dn
TxtKeys txt_keys
unsigned timeout
unsigned retries
std::string hostname
std::vector< char > buffer
std::thread io_thread
Bonjour::ReplyFn replyfn
Bonjour::CompleteFn completefn
Bonjour::ResolveFn resolvefn

Detailed Description

Constructor & Destructor Documentation

◆ priv()

Slic3r::Bonjour::priv::priv ( std::string && service)
880 : service(std::move(service))
881 , protocol("tcp")
882 , timeout(10)
883 , retries(1)
884{
886}
std::vector< char > buffer
Definition Bonjour.cpp:866
std::string protocol
Definition Bonjour.cpp:857
unsigned retries
Definition Bonjour.cpp:861
const std::string service
Definition Bonjour.cpp:856
unsigned timeout
Definition Bonjour.cpp:860
@ MAX_SIZE
Definition Bonjour.cpp:415

References buffer, Slic3r::DnsMessage::MAX_SIZE, protocol, retries, service, and timeout.

Member Function Documentation

◆ lookup_perform()

void Slic3r::Bonjour::priv::lookup_perform ( )
889{
890 service_dn = (boost::format("_%1%._%2%.local") % service % protocol).str();
891
892 std::shared_ptr< boost::asio::io_context > io_service(new boost::asio::io_context);
893
894 std::vector<LookupSocket*> sockets;
895
896 // resolve interfaces - from PR#6646
897 std::vector<boost::asio::ip::address> interfaces;
898 asio::ip::udp::resolver resolver(*io_service);
899 boost::system::error_code ec;
900 // ipv4 interfaces
901 auto results = resolver.resolve(udp::v4(), asio::ip::host_name(), "", ec);
902 if (!ec) {
903 for (const auto & r : results) {
904 const auto addr = r.endpoint().address();
905 if (addr.is_loopback()) continue;
906 interfaces.emplace_back(std::move(addr));
907 }
908 // create ipv4 socket for each interface
909 // each will send to querry to for both ipv4 and ipv6
910 for (const auto& intrfc : interfaces)
911 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP4, intrfc, io_service));
912 } else {
913 BOOST_LOG_TRIVIAL(info) << "Failed to resolve ipv4 interfaces: " << ec.message();
914 }
915 if (sockets.empty())
916 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP4, io_service));
917 // ipv6 interfaces
918 interfaces.clear();
919 //udp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::numeric_service);
920 results = resolver.resolve(udp::v6(), asio::ip::host_name(), "", ec);
921 if (!ec)
922 {
923 for (const auto& r : results) {
924 const auto addr = r.endpoint().address();
925 if (addr.is_loopback()) continue;
926 interfaces.emplace_back(std::move(addr));
927 }
928 // create ipv6 socket for each interface
929 // each will send to querry to for both ipv4 and ipv6
930 for (const auto& intrfc : interfaces)
931 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP6, intrfc, io_service));
932 if (interfaces.empty())
933 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP6, io_service));
934 } else {
935 BOOST_LOG_TRIVIAL(info)<< "Failed to resolve ipv6 interfaces: " << ec.message();
936 }
937
938 try {
939 // send first queries
940 for (auto * socket : sockets)
941 socket->send();
942
943 // timer settings
944 asio::steady_timer timer(*io_service);
945 retries--;
946 std::function<void(const error_code&)> timer_handler = [&](const error_code& error) {
947 // end
948 if (retries == 0 || error) {
949 // is this correct ending?
950 io_service->stop();
951 if (completefn) {
952 completefn();
953 }
954 // restart timer
955 } else {
956 retries--;
957 timer.expires_after(std::chrono::seconds(timeout));
958 timer.async_wait(timer_handler);
959 // trigger another round of queries
960 for (auto * socket : sockets)
961 socket->send();
962 }
963 };
964 // start timer
965 timer.expires_after(std::chrono::seconds(timeout));
966 timer.async_wait(timer_handler);
967 // start io_service, it will run until it has something to do - so in this case until stop is called in timer
968 io_service->run();
969 }
970 catch (std::exception& e) {
971 BOOST_LOG_TRIVIAL(error) << e.what();
972 }
973}
static const boost::asio::ip::address_v4 MCAST_IP4
Definition Bonjour.hpp:108
static const boost::asio::ip::address_v6 MCAST_IP6
Definition Bonjour.hpp:109
Bonjour::ReplyFn replyfn
Definition Bonjour.cpp:868
TxtKeys txt_keys
Definition Bonjour.cpp:859
std::string service_dn
Definition Bonjour.cpp:858
Bonjour::CompleteFn completefn
Definition Bonjour.cpp:869

References completefn, Slic3r::BonjourRequest::MCAST_IP4, Slic3r::BonjourRequest::MCAST_IP6, protocol, replyfn, retries, service, service_dn, timeout, and txt_keys.

◆ resolve_perform()

void Slic3r::Bonjour::priv::resolve_perform ( )
976{
977 // reply callback is shared to every UDPSession which is called on same thread as io_service->run();
978 // thus no need to mutex replies in reply_callback, same should go with the timer
979 std::vector<BonjourReply> replies;
980 // examples would store [self] to the lambda (and the timer one), is it ok not to do it? (Should be c++03)
981 const auto reply_callback = [&rpls = replies](BonjourReply&& reply)
982 {
983 if (std::find(rpls.begin(), rpls.end(), reply) == rpls.end())
984 rpls.push_back(reply);
985 };
986
987 std::shared_ptr< boost::asio::io_context > io_service(new boost::asio::io_context);
988 std::vector<ResolveSocket*> sockets;
989
990 // resolve interfaces - from PR#6646
991 std::vector<boost::asio::ip::address> interfaces;
992 asio::ip::udp::resolver resolver(*io_service);
993 boost::system::error_code ec;
994 // ipv4 interfaces
995 auto results = resolver.resolve(udp::v4(), asio::ip::host_name(), "", ec);
996 if (!ec) {
997 for (auto const& r : results) {
998 auto const addr = r.endpoint().address();
999 if (addr.is_loopback()) continue;
1000 interfaces.emplace_back(addr);
1001 }
1002 // create ipv4 socket for each interface
1003 // each will send to querry to for both ipv4 and ipv6
1004 for (const auto& intrfc : interfaces)
1005 sockets.emplace_back(new ResolveSocket(hostname, reply_callback, BonjourRequest::MCAST_IP4, intrfc, io_service));
1006 } else {
1007 BOOST_LOG_TRIVIAL(info) << "Failed to resolve ipv4 interfaces: " << ec.message();
1008 }
1009 if (sockets.empty())
1010 sockets.emplace_back(new ResolveSocket(hostname, reply_callback, BonjourRequest::MCAST_IP4, io_service));
1011
1012 // ipv6 interfaces
1013 interfaces.clear();
1014 results = resolver.resolve(udp::v6(), asio::ip::host_name(), "", ec);
1015 if (!ec) {
1016 for (auto const& r : results) {
1017 auto const addr = r.endpoint().address();
1018 if (addr.is_loopback()) continue;
1019 interfaces.emplace_back(addr);
1020 }
1021 // create ipv6 socket for each interface
1022 // each will send to querry to for both ipv4 and ipv6
1023 for (const auto& intrfc : interfaces)
1024 sockets.emplace_back(new ResolveSocket(hostname, reply_callback, BonjourRequest::MCAST_IP6, intrfc, io_service));
1025 if (interfaces.empty())
1026 sockets.emplace_back(new ResolveSocket(hostname, reply_callback, BonjourRequest::MCAST_IP6, io_service));
1027 } else {
1028 BOOST_LOG_TRIVIAL(info) << "Failed to resolve ipv6 interfaces: " << ec.message();
1029 }
1030
1031 try {
1032 // send first queries
1033 for (auto * socket : sockets)
1034 socket->send();
1035
1036 // timer settings
1037 asio::steady_timer timer(*io_service);
1038 retries--;
1039 std::function<void(const error_code&)> timer_handler = [&](const error_code& error) {
1040 int replies_count = replies.size();
1041 // end
1042 if (retries == 0 || error || replies_count > 0) {
1043 // is this correct ending?
1044 io_service->stop();
1045 if (replies_count > 0 && resolvefn) {
1046 resolvefn(replies);
1047 }
1048 // restart timer
1049 } else {
1050 retries--;
1051 timer.expires_after(std::chrono::seconds(timeout));
1052 timer.async_wait(timer_handler);
1053 // trigger another round of queries
1054 for (auto * socket : sockets)
1055 socket->send();
1056 }
1057 };
1058 // start timer
1059 timer.expires_after(std::chrono::seconds(timeout));
1060 timer.async_wait(timer_handler);
1061 // start io_service, it will run until it has something to do - so in this case until stop is called in timer
1062 io_service->run();
1063 }
1064 catch (std::exception& e) {
1065 BOOST_LOG_TRIVIAL(error) << e.what();
1066 }
1067}
Bonjour::ResolveFn resolvefn
Definition Bonjour.cpp:870
std::string hostname
Definition Bonjour.cpp:862

References hostname, Slic3r::BonjourRequest::MCAST_IP4, Slic3r::BonjourRequest::MCAST_IP6, resolvefn, retries, and timeout.

Member Data Documentation

◆ buffer

std::vector<char> Slic3r::Bonjour::priv::buffer

Referenced by priv().

◆ completefn

Bonjour::CompleteFn Slic3r::Bonjour::priv::completefn

Referenced by lookup_perform().

◆ hostname

std::string Slic3r::Bonjour::priv::hostname

Referenced by resolve_perform().

◆ io_thread

std::thread Slic3r::Bonjour::priv::io_thread

◆ protocol

std::string Slic3r::Bonjour::priv::protocol

Referenced by priv(), and lookup_perform().

◆ replyfn

Bonjour::ReplyFn Slic3r::Bonjour::priv::replyfn

Referenced by lookup_perform().

◆ resolvefn

Bonjour::ResolveFn Slic3r::Bonjour::priv::resolvefn

Referenced by resolve_perform().

◆ retries

unsigned Slic3r::Bonjour::priv::retries

◆ service

const std::string Slic3r::Bonjour::priv::service

Referenced by priv(), and lookup_perform().

◆ service_dn

std::string Slic3r::Bonjour::priv::service_dn

Referenced by lookup_perform().

◆ timeout

unsigned Slic3r::Bonjour::priv::timeout

◆ txt_keys

TxtKeys Slic3r::Bonjour::priv::txt_keys

Referenced by lookup_perform().


The documentation for this struct was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Bonjour.cpp