<div dir="ltr"><div><div>Hi Martin, Hi Thiago,<br><br></div>Thank you all from spent your time in explanation for me. It was very useful for me.<br>Happy New Year and Merry Christmas !!!!!!!!!!!! <br></div><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 28 December 2016 at 22:57, Martin Häfner <span dir="ltr"><<a href="mailto:martinhaefner@web.de" target="_blank">martinhaefner@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Denis,<div><br></div><div>well, you are still too fixated on an evenloop where only dbus is doing I/O. Think about an application which is doing lot of stuff at the same time. Timers, sockets, UI events, and so on. And just one aspect of this app is doing dbus. If dbus was a closed library you would then start a separate thread just for the dbus communication. But threads are superfluid in this case and only make things much more complex. dbus API let's you integrate the dbus sockets and timers to your event loop (and does not compel you to use a certain implementation). So, dbus tells you "I have a socket, you may call poll, epoll, select or whatever and then call me back if something happened on the socket, so I will read out the data and make a message call from it". </div><div><br></div><div>dbus_connection_send will enqueue a new message which can be sent when the socket tells you that it is ready to send - which is probably nearly always the case. dbus_connection_flush indeed breaks your event loop approach since this call will block doing a select just on the dbus socket, so all other events are blocked in this case. You probably never should use this in a eventloop driven dbus application. </div><div><br></div><div>dbus API also supports blocking method calls which also start internal select loops in order to wait for a timeout or a message return, so this is also not favourable in an eventloop driven application. You can think of these functions beeing used in simple batch tools.</div><div><br></div><div>Regards,</div><div>Martin </div><div><br></div></div><div class="gmail-m_8735549589237105637HOEnZb"><div class="gmail-m_8735549589237105637h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-12-28 10:21 GMT+01:00 Денис Котов <span dir="ltr"><<a href="mailto:redradist@gmail.com" target="_blank">redradist@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Martin,<span><div><br></div><div><span style="font-size:12.8px"><i>>> They are just called once. Sockets must be monitored in order to let dbus know when a new message arrives.</i></span></div></span><div><span style="font-size:12.8px">I am only curios why <b>DBus </b>cannot monitor socket by itself. First time when I faced with it it was surprise for me.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">One additional point:</span></div><div><span style="font-size:12.8px">"</span><i><span style="color:rgb(0,0,0);font-family:roboto,sans-serif;font-size:14px">When you use </span><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#gae1cb64f4cf550949b23fd3a756b2f7d0" title="Adds a message to the outgoing message queue." style="color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_connection_send()</a><span style="color:rgb(0,0,0);font-family:roboto,sans-serif;font-size:14px"> or one of its variants to send a message, the message is added to the outgoing queue. It's actually written to the network later; either in </span><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusWatch.html#gac2acdb1794450ac01a43ec4c3e07ebf7" title="Called to notify the D-Bus library when a previously-added watch is ready for reading or writing..." style="color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_watch_handle()</a><span style="color:rgb(0,0,0);font-family:roboto,sans-serif;font-size:14px"> invoked by your main loop, or in </span><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#ga10e68d9d2f41d655a4151ddeb807ff54" title="Blocks until the outgoing message queue is empty." style="color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_connection_flush()</a><span style="color:rgb(0,0,0);font-family:roboto,sans-serif;font-size:14px"> whi<wbr>ch blocks until it can write out the entire outgoing queue. The GLib/Qt add-on libraries again handle the details here for you by setting up watch functions.</span></i><span style="font-size:12.8px">"</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">For this I implemented calling </span><i><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#ga10e68d9d2f41d655a4151ddeb807ff54" title="Blocks until the outgoing message queue is empty." style="text-decoration:underline;color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_connection_flush(<wbr>)</a> </i>on event <b>POLLOUT</b>, but this event never appears. For me it is very strange ... </div><div>But all sent messages by <span style="color:rgb(0,0,0);font-family:roboto,sans-serif;font-size:14px"> </span><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#gae1cb64f4cf550949b23fd3a756b2f7d0" title="Adds a message to the outgoing message queue." style="color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_connection_send()</a> arr<wbr>ives <b>successfully</b> (it even I have not received <b>POLLOUT </b>for making flush).</div><div><br></div><div>Do you know who ca <i><a class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393el" href="https://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#ga10e68d9d2f41d655a4151ddeb807ff54" title="Blocks until the outgoing message queue is empty." style="text-decoration:underline;color:rgb(70,101,162);font-weight:bold;font-family:roboto,sans-serif;font-size:14px" target="_blank">dbus_connection_flush()</a> </i>in this case ?</div></div><div class="gmail-m_8735549589237105637m_-8437179301312885736HOEnZb"><div class="gmail-m_8735549589237105637m_-8437179301312885736h5"><div class="gmail_extra"><br><div class="gmail_quote">On 27 December 2016 at 21:02, Martin Häfner <span dir="ltr"><<a href="mailto:martinhaefner@web.de" target="_blank">martinhaefner@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Denis,<div><br></div><div>the functions are called within this block in the dispatcher.cpp in order to register your callbacks:</div><br>Private(DBusConnection* conn)<br>{<br>#ifdef USE_POLL<br> dbus_connection_set_watch_fun<wbr>ctions(conn, &add_watch, &remove_watch, &toggle_watch, this, nullptr);<br> dbus_connection_set_timeout_f<wbr>unctions (conn, &add_timeout, &remove_timeout, &toggle_timeout, this, nullptr);<br>#endif<br>}<div class="gmail_extra"><br></div><div class="gmail_extra">They are just called once. Sockets must be monitored in order to let dbus know when a new message arrives. But dbus also has timeout handling - if messages do not arrive intime or the daemon is not able to send data on the socket in a certain time. This is why timeouts are needed. Note that in a simple dbus application there is mostly only one socket alive at a time (the bus connection).</div><div class="gmail_extra"><br></div><div class="gmail_extra">Regards,</div><div class="gmail_extra">Martin </div><div><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-12-26 10:59 GMT+01:00 Денис Котов <span dir="ltr"><<a href="mailto:redradist@gmail.com" target="_blank">redradist@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi <span style="font-size:12.8px;white-space:nowrap">Martin,</span><div><span style="font-size:12.8px;white-space:nowrap"><br></span></div><div><span style="font-size:12.8px;white-space:nowrap">Thanks for link, but I have not found where you use the following functions:</span></div><div><span style="font-size:12.8px;white-space:nowrap">dbus_connection_set_watch_func<wbr>tions</span><br></div><div><span style="font-size:12.8px;white-space:nowrap">dbus_connection_set_timeout_fu<wbr>nctions</span><br></div><div><span style="font-size:12.8px;white-space:nowrap"><br></span></div><div><span style="font-size:12.8px;white-space:nowrap">???</span></div><div><span style="font-size:12.8px;white-space:nowrap"><br></span></div><div><span style="font-size:12.8px;white-space:nowrap">From your explanation and this example </span><span style="font-size:12.8px;white-space:nowrap"><a href="https://lists.freedesktop.org/archives/dbus/2007-October/008859.html" target="_blank">https://lists.freedesk<wbr>top.org/archives/dbus/2007-Oct<wbr>ober/008859.html</a> I have understood that </span><font color="#000000">watch - is a file descriptor that needed to be monitored ( for example in a new client has connected to service ), but timeout what is the purpose of this variable ?</font></div><div><font color="#000000">Okay, let's imagine that libdbus asked to create the timer, but for what purposes ? Should I handle file descriptor in that time or what ? And if I would not handle something in that timeout what will happen ?</font></div></div><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-HOEnZb"><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On 25 December 2016 at 22:10, Martin Häfner <span dir="ltr"><<a href="mailto:martinhaefner@web.de" target="_blank">martinhaefner@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Denis,<div><br></div><div>DBusWatch and Timeout are dbus callouts to integrate the dbus library into external event loops. You can write simple dbus driven applications with a simple main loop just calling the <span class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127m_2274272788409583409gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179);font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;white-space:pre-wrap">dbus_connection_read_write<wbr>_dispatch </span>function in a simple main loop. If you develop real world applications you will probably have to integrate the dbus API into a third-party main loop, e.g. from QApplication when implementing a Qt base GUI application. For the Qt example, you will probably make a mapping from a DBusTimeout to a QTimer and from a DBusWatch to QSocketNotifier. So, whenever DBus tells you to create a watch you will create a QSocketNotifier, and whenever DBus calls the callout to create a Timeout you create a QTimer. I have written a template-based C++ wrapper on top of DBus which implements the two different possibilities, once in a simple poll loop: You can have a look into the example at <a href="https://github.com/martinhaefner/simppl/blob/dbus2/src/dispatcher.cpp" target="_blank">https://github.com/martinhaefn<wbr>er/simppl/blob/dbus2/src/dispa<wbr>tcher.cpp</a></div><div><br></div><div>Regards,</div><div>Martin</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127h5">2016-12-24 19:02 GMT+01:00 Денис Котов <span dir="ltr"><<a href="mailto:redradist@gmail.com" target="_blank">redradist@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127h5"><div dir="ltr"><div><div><div><div>Hi All,<br><br></div>Currently I have faced with understanding of watch and timeout functions in libdbus.<br></div>I do not quit understand why they are needed.<br><br></div>From
description I understand they are needed to check state of socket. If
something changes then from libdbus I will receive this message and I
have either to read something or to write something to socket.<br><br></div>It
means that I should not create infinite while loop, but register
callbacks and when will be possibility I will write to out-queue or read
to in-queue, am I right ?<br clear="all"><div><br></div>And maybe some brief explanation what is DBusTimeout function ?<span class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127m_2274272788409583409HOEnZb"><font color="#888888"><br clear="all"><br>-- <br><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127m_2274272788409583409m_5441921365953488477gmail_signature"><div dir="ltr"><b>Best Regards<br>Denis Kotov</b><br></div></div>
</font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
dbus mailing list<br>
<a href="mailto:dbus@lists.freedesktop.org" target="_blank">dbus@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/dbus" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/dbus</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393m_3237982323143988584gmail-m_-9120244656066218127gmail_signature"><div dir="ltr"><b>Best Regards<br>Denis Kotov</b><br></div></div>
</div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail-m_8735549589237105637m_-8437179301312885736m_-6889071297197134393gmail_signature"><div dir="ltr"><b>Best Regards<br>Denis Kotov</b><br></div></div>
</div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail-m_8735549589237105637gmail_signature"><div dir="ltr"><b>Best Regards<br>Denis Kotov</b><br></div></div>
</div></div></div></div></div>