Prusa Slicer 2.6.0
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)
858 : service(std::move(service))
859 , protocol("tcp")
860 , timeout(10)
861 , retries(1)
862{
864}
std::vector< char > buffer
Definition Bonjour.cpp:844
std::string protocol
Definition Bonjour.cpp:835
unsigned retries
Definition Bonjour.cpp:839
const std::string service
Definition Bonjour.cpp:834
unsigned timeout
Definition Bonjour.cpp:838
@ MAX_SIZE
Definition Bonjour.cpp:393

References buffer, and Slic3r::DnsMessage::MAX_SIZE.

Member Function Documentation

◆ lookup_perform()

void Slic3r::Bonjour::priv::lookup_perform ( )
867{
868 service_dn = (boost::format("_%1%._%2%.local") % service % protocol).str();
869
870 std::shared_ptr< boost::asio::io_service > io_service(new boost::asio::io_service);
871
872 std::vector<LookupSocket*> sockets;
873
874 // resolve intefaces - from PR#6646
875 std::vector<boost::asio::ip::address> interfaces;
876 asio::ip::udp::resolver resolver(*io_service);
877 boost::system::error_code ec;
878 // ipv4 interfaces
879 auto results = resolver.resolve(udp::v4(), asio::ip::host_name(), "", ec);
880 if (!ec) {
881 for (const auto & r : results) {
882 const auto addr = r.endpoint().address();
883 if (addr.is_loopback()) continue;
884 interfaces.emplace_back(std::move(addr));
885 }
886 // create ipv4 socket for each interface
887 // each will send to querry to for both ipv4 and ipv6
888 for (const auto& intrfc : interfaces)
889 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP4, intrfc, io_service));
890 } else {
891 BOOST_LOG_TRIVIAL(info) << "Failed to resolve ipv4 interfaces: " << ec.message();
892 }
893 if (sockets.empty())
894 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP4, io_service));
895 // ipv6 interfaces
896 interfaces.clear();
897 //udp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::numeric_service);
898 results = resolver.resolve(udp::v6(), asio::ip::host_name(), "", ec);
899 if (!ec)
900 {
901 for (const auto& r : results) {
902 const auto addr = r.endpoint().address();
903 if (addr.is_loopback()) continue;
904 interfaces.emplace_back(std::move(addr));
905 }
906 // create ipv6 socket for each interface
907 // each will send to querry to for both ipv4 and ipv6
908 for (const auto& intrfc : interfaces)
909 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP6, intrfc, io_service));
910 if (interfaces.empty())
911 sockets.emplace_back(new LookupSocket(txt_keys, service, service_dn, protocol, replyfn, BonjourRequest::MCAST_IP6, io_service));
912 } else {
913 BOOST_LOG_TRIVIAL(info)<< "Failed to resolve ipv6 interfaces: " << ec.message();
914 }
915
916 try {
917 // send first queries
918 for (auto * socket : sockets)
919 socket->send();
920
921 // timer settings
922 asio::deadline_timer timer(*io_service);
923 retries--;
924 std::function<void(const error_code&)> timer_handler = [&](const error_code& error) {
925 // end
926 if (retries == 0 || error) {
927 // is this correct ending?
928 io_service->stop();
929 if (completefn) {
930 completefn();
931 }
932 // restart timer
933 } else {
934 retries--;
935 timer.expires_from_now(boost::posix_time::seconds(timeout));
936 timer.async_wait(timer_handler);
937 // trigger another round of queries
938 for (auto * socket : sockets)
939 socket->send();
940 }
941 };
942 // start timer
943 timer.expires_from_now(boost::posix_time::seconds(timeout));
944 timer.async_wait(timer_handler);
945 // start io_service, it will run until it has something to do - so in this case until stop is called in timer
946 io_service->run();
947 }
948 catch (std::exception& e) {
949 BOOST_LOG_TRIVIAL(error) << e.what();
950 }
951}
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
Bonjour::ReplyFn replyfn
Definition Bonjour.cpp:846
TxtKeys txt_keys
Definition Bonjour.cpp:837
std::string service_dn
Definition Bonjour.cpp:836
Bonjour::CompleteFn completefn
Definition Bonjour.cpp:847
static const boost::asio::ip::address_v4 MCAST_IP4
Definition Bonjour.hpp:95
static const boost::asio::ip::address_v6 MCAST_IP6
Definition Bonjour.hpp:96
static char error[256]
Definition tga.cpp:50

References error, Slic3r::BonjourRequest::MCAST_IP4, Slic3r::BonjourRequest::MCAST_IP6, and void().

+ Here is the call graph for this function:

◆ resolve_perform()

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

References error, Slic3r::BonjourRequest::MCAST_IP4, Slic3r::BonjourRequest::MCAST_IP6, and void().

+ Here is the call graph for this function:

Member Data Documentation

◆ buffer

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

Referenced by priv().

◆ completefn

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

◆ hostname

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

◆ io_thread

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

◆ protocol

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

◆ replyfn

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

◆ resolvefn

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

◆ retries

unsigned Slic3r::Bonjour::priv::retries

◆ service

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

◆ service_dn

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

◆ timeout

unsigned Slic3r::Bonjour::priv::timeout

◆ txt_keys

TxtKeys Slic3r::Bonjour::priv::txt_keys

The documentation for this struct was generated from the following file: