OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::ResolveSocket Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Bonjour.hpp>

Inheritance diagram for Slic3r::ResolveSocket:
Collaboration diagram for Slic3r::ResolveSocket:

Public Member Functions

 ResolveSocket (const std::string &hostname, Bonjour::ReplyFn replyfn, const boost::asio::ip::address &multicast_address, const boost::asio::ip::address &interface_address, std::shared_ptr< boost::asio::io_context > io_service)
 ResolveSocket (const std::string &hostname, Bonjour::ReplyFn replyfn, const boost::asio::ip::address &multicast_address, std::shared_ptr< boost::asio::io_context > io_service)
std::string get_hostname () const
void send ()
void async_receive ()
void cancel ()

Protected Member Functions

SharedSession create_session () const override
void create_requests ()
void receive_handler (SharedSession session, const boost::system::error_code &error, size_t bytes)

Protected Attributes

std::string hostname
Bonjour::ReplyFn replyfn
boost::asio::ip::address multicast_address
boost::asio::ip::udp::socket socket
boost::asio::ip::udp::endpoint mcast_endpoint
std::shared_ptr< boost::asio::io_context > io_service
std::vector< BonjourRequest > requests

Detailed Description

Constructor & Destructor Documentation

◆ ResolveSocket() [1/2]

Slic3r::ResolveSocket::ResolveSocket ( const std::string & hostname,
Bonjour::ReplyFn replyfn,
const boost::asio::ip::address & multicast_address,
const boost::asio::ip::address & interface_address,
std::shared_ptr< boost::asio::io_context > io_service )
inline
255 : UdpSocket(replyfn, multicast_address, interface_address, io_service)
257
258 {
259 assert(!hostname.empty() && replyfn);
261 }
std::string hostname
Definition Bonjour.hpp:296
void create_requests()
Definition Bonjour.hpp:278
std::shared_ptr< boost::asio::io_context > io_service
Definition Bonjour.hpp:185
UdpSocket(Bonjour::ReplyFn replyfn, const boost::asio::ip::address &multicast_address, const boost::asio::ip::address &interface_address, std::shared_ptr< boost::asio::io_context > io_service)
Bonjour::ReplyFn replyfn
Definition Bonjour.hpp:181
boost::asio::ip::address multicast_address
Definition Bonjour.hpp:182

References Slic3r::UdpSocket::UdpSocket(), create_requests(), hostname, Slic3r::UdpSocket::io_service, Slic3r::UdpSocket::multicast_address, and Slic3r::UdpSocket::replyfn.

Here is the call graph for this function:

◆ ResolveSocket() [2/2]

Slic3r::ResolveSocket::ResolveSocket ( const std::string & hostname,
Bonjour::ReplyFn replyfn,
const boost::asio::ip::address & multicast_address,
std::shared_ptr< boost::asio::io_context > io_service )
inline
269
270 {
271 assert(!hostname.empty() && replyfn);
273 }

References Slic3r::UdpSocket::UdpSocket(), create_requests(), hostname, Slic3r::UdpSocket::io_service, Slic3r::UdpSocket::multicast_address, and Slic3r::UdpSocket::replyfn.

Here is the call graph for this function:

Member Function Documentation

◆ async_receive()

void Slic3r::UdpSocket::async_receive ( )
inherited
717{
718 try {
719 // our session to hold the buffer + endpoint
720 auto session = create_session();
721 socket.async_receive_from(asio::buffer(session->buffer, session->buffer.size())
722 , session->remote_endpoint
723 , boost::bind(&UdpSocket::receive_handler, this, session, asio::placeholders::error, asio::placeholders::bytes_transferred));
724 }
725 catch (std::exception& e) {
726 BOOST_LOG_TRIVIAL(error) << e.what();
727 }
728}
void receive_handler(SharedSession session, const boost::system::error_code &error, size_t bytes)
Definition Bonjour.cpp:730
boost::asio::ip::udp::socket socket
Definition Bonjour.hpp:183
virtual SharedSession create_session() const =0

References create_session(), receive_handler(), and socket.

Referenced by receive_handler(), and send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancel()

void Slic3r::UdpSocket::cancel ( )
inlineinherited
176{ socket.cancel(); }

References socket.

◆ create_requests()

void Slic3r::ResolveSocket::create_requests ( )
inlineprotected
279 {
280 requests.clear();
281 // BonjourRequest::make_A / AAAA is now implemented to add .local correctly after the hostname.
282 // If that is unsufficient, we need to change make_A / AAAA and pass full hostname.
283 std::string trimmed_hostname = hostname;
284 if (size_t dot_pos = trimmed_hostname.find_first_of('.'); dot_pos != std::string::npos)
285 trimmed_hostname = trimmed_hostname.substr(0, dot_pos);
286 if (auto rqst = BonjourRequest::make_A(trimmed_hostname); rqst)
287 requests.push_back(std::move(rqst.get()));
288
289 trimmed_hostname = hostname;
290 if (size_t dot_pos = trimmed_hostname.find_first_of('.'); dot_pos != std::string::npos)
291 trimmed_hostname = trimmed_hostname.substr(0, dot_pos);
292 if (auto rqst = BonjourRequest::make_AAAA(trimmed_hostname); rqst)
293 requests.push_back(std::move(rqst.get()));
294 }
std::vector< BonjourRequest > requests
Definition Bonjour.hpp:186
static boost::optional< BonjourRequest > make_A(const std::string &hostname)
Definition Bonjour.cpp:554
static boost::optional< BonjourRequest > make_AAAA(const std::string &hostname)
Definition Bonjour.cpp:589

References hostname, Slic3r::BonjourRequest::make_A(), Slic3r::BonjourRequest::make_AAAA(), and Slic3r::UdpSocket::requests.

Referenced by ResolveSocket(), and ResolveSocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_session()

SharedSession Slic3r::ResolveSocket::create_session ( ) const
overrideprotectedvirtual

Implements Slic3r::UdpSocket.

791{
792 return std::shared_ptr< ResolveSession > (new ResolveSession(this, replyfn));
793}

References Slic3r::UdpSocket::replyfn.

◆ get_hostname()

std::string Slic3r::ResolveSocket::get_hostname ( ) const
inline
275{ return hostname; }

References hostname.

◆ receive_handler()

void Slic3r::UdpSocket::receive_handler ( SharedSession session,
const boost::system::error_code & error,
size_t bytes )
protectedinherited
731{
732 // let io_service to handle the datagram on session
733 // from boost documentation io_service::post:
734 // The io_service guarantees that the handler will only be called in a thread in which the run(), run_one(), poll() or poll_one() member functions is currently being invoked.
735 boost::asio::post(*io_service, boost::bind(&UdpSession::handle_receive, session, error, bytes));
736 // immediately accept new datagrams
738}
virtual void handle_receive(const boost::system::error_code &error, size_t bytes)=0
void async_receive()
Definition Bonjour.cpp:716

References async_receive(), Slic3r::UdpSession::handle_receive(), and io_service.

Referenced by async_receive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

void Slic3r::UdpSocket::send ( )
inherited
703{
704 try {
705 for (const auto& request : requests)
706 socket.send_to(asio::buffer(request.m_data), mcast_endpoint);
707
708 // Should we care if this is called while already receiving? (async_receive call from receive_handler)
710 }
711 catch (std::exception& e) {
712 BOOST_LOG_TRIVIAL(error) << e.what();
713 }
714}
boost::asio::ip::udp::endpoint mcast_endpoint
Definition Bonjour.hpp:184

References async_receive(), mcast_endpoint, requests, and socket.

Here is the call graph for this function:

Member Data Documentation

◆ hostname

std::string Slic3r::ResolveSocket::hostname
protected

◆ io_service

std::shared_ptr< boost::asio::io_context > Slic3r::UdpSocket::io_service
protectedinherited

◆ mcast_endpoint

boost::asio::ip::udp::endpoint Slic3r::UdpSocket::mcast_endpoint
protectedinherited

Referenced by send().

◆ multicast_address

◆ replyfn

◆ requests

std::vector<BonjourRequest> Slic3r::UdpSocket::requests
protectedinherited

◆ socket

boost::asio::ip::udp::socket Slic3r::UdpSocket::socket
protectedinherited

Referenced by async_receive(), cancel(), and send().


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