Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::detail::gntp_notifier_impl Class Reference
Collaboration diagram for fc::detail::gntp_notifier_impl:

Public Member Functions

 gntp_notifier_impl (const std::string &host_to_notify="127.0.0.1", uint16_t port=23053, const std::optional< std::string > &password=std::optional< std::string >())
 
void send_gntp_message (const std::string &message)
 

Public Attributes

std::string hostname
 
uint16_t port
 
std::optional< std::string > password
 
std::string application_name
 
gntp_icon_ptr application_icon
 
gntp_notification_type_list notification_types
 
std::optional< boost::asio::ip::tcp::endpoint > endpoint
 
bool connection_failed
 
bool is_registered
 

Detailed Description

Definition at line 45 of file gntp.cpp.

Constructor & Destructor Documentation

◆ gntp_notifier_impl()

fc::detail::gntp_notifier_impl::gntp_notifier_impl ( const std::string & host_to_notify = "127.0.0.1",
uint16_t port = 23053,
const std::optional< std::string > & password = std::optional<std::string>() )

Definition at line 68 of file gntp.cpp.

69 :
70 hostname(host_to_notify),
71 port(port),
72 password(password),
73 connection_failed(false),
74 is_registered(false)
75 {
76 }
std::optional< std::string > password
Definition gntp.cpp:53

Member Function Documentation

◆ send_gntp_message()

void fc::detail::gntp_notifier_impl::send_gntp_message ( const std::string & message)

Definition at line 78 of file gntp.cpp.

79 {
80 std::shared_ptr<boost::asio::ip::tcp::socket> sock(new boost::asio::ip::tcp::socket(asio::default_io_service()));
81
82 bool connected = false;
83 if (endpoint)
84 {
85 // we've successfully connected before, connect to the same endpoint that worked last time
86 try
87 {
88 asio::tcp::connect(*sock, *endpoint);
89 connected = true;
90 }
91 catch (exception& er)
92 {
93 ilog("Failed to connect to GNTP service using an endpoint that previously worked: ${error_report}",
94 ("error_report", er.to_detail_string()));
95 sock->close();
96 // clear the cached endpoint and fall through to the full connection procedure
97 endpoint = std::optional<boost::asio::ip::tcp::endpoint>();
98 }
99 catch (...)
100 {
101 ilog("Failed to connect to GNTP service using an endpoint that previously worked");
102 sock->close();
103 // clear the cached endpoint and fall through to the full connection procedure
104 endpoint = std::optional<boost::asio::ip::tcp::endpoint>();
105 }
106 }
107 if (!connected)
108 {
109 // do the full connection procedure
110 auto eps = asio::tcp::resolve(hostname, boost::lexical_cast<std::string>(port));
111 if (eps.size() == 0)
112 FC_THROW("Unable to resolve host '${host}'", ("host", hostname));
113
114 for (uint32_t i = 0; i < eps.size(); ++i)
115 {
116 try
117 {
118 boost::system::error_code ec;
119 ilog("Attempting to connect to GNTP srvice");
120 asio::tcp::connect(*sock, eps[i]);
121 endpoint = eps[i];
122 connected = true;
123 break;
124 }
125 catch (const exception& er)
126 {
127 ilog("Failed to connect to GNTP service: ${error_reprot}",
128 ("error_report", er.to_detail_string()) );
129 sock->close();
130 }
131 catch (...)
132 {
133 ilog("Failed to connect to GNTP service");
134 sock->close();
135 }
136 }
137 }
138 if (!connected)
139 FC_THROW("Unable to connect to any resolved endpoint for ${host}:${port}",
140 ("host", hostname)("port", port));
141 try
142 {
143 asio::ostream<boost::asio::ip::tcp::socket> write_stream(sock);
144 write_stream.write(message.c_str(), message.size());
145 write_stream.flush();
146 write_stream.close();
147 }
148 catch (exception& er)
149 {
150 FC_RETHROW_EXCEPTION(er, warn, "Caught an exception while sending data to GNTP service");
151 }
152 catch (...)
153 {
154 FC_THROW("Caught an exception while sending data to GNTP service");
155 }
156 }
std::optional< boost::asio::ip::tcp::endpoint > endpoint
Definition gntp.cpp:60
#define FC_THROW( ...)
#define FC_RETHROW_EXCEPTION(ER, LOG_LEVEL, FORMAT,...)
Appends a log_message to the exception ER and rethrows it.
#define ilog(FORMAT,...)
Definition logger.hpp:118
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:

Member Data Documentation

◆ application_icon

gntp_icon_ptr fc::detail::gntp_notifier_impl::application_icon

Definition at line 56 of file gntp.cpp.

◆ application_name

std::string fc::detail::gntp_notifier_impl::application_name

Definition at line 55 of file gntp.cpp.

◆ connection_failed

bool fc::detail::gntp_notifier_impl::connection_failed

Definition at line 62 of file gntp.cpp.

◆ endpoint

std::optional<boost::asio::ip::tcp::endpoint> fc::detail::gntp_notifier_impl::endpoint

Definition at line 60 of file gntp.cpp.

◆ hostname

std::string fc::detail::gntp_notifier_impl::hostname

Definition at line 51 of file gntp.cpp.

◆ is_registered

bool fc::detail::gntp_notifier_impl::is_registered

Definition at line 63 of file gntp.cpp.

◆ notification_types

gntp_notification_type_list fc::detail::gntp_notifier_impl::notification_types

Definition at line 58 of file gntp.cpp.

◆ password

std::optional<std::string> fc::detail::gntp_notifier_impl::password

Definition at line 53 of file gntp.cpp.

◆ port

uint16_t fc::detail::gntp_notifier_impl::port

Definition at line 52 of file gntp.cpp.


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