<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I am trying to determine the recommended approach to handle a
DBus request to a service that takes a “long” time to complete. From
the client-side (e.g. the DBus service “proxy”) most of the DBus language
bindings allow the client to either block waiting for a response or register a callback
function to handle the response asynchronously at a later time.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>If I am writing a DBus service, however, I have not run
across a binding that allows the server side callback to defer handling the
request to a time beyond the scope of the service callback (e.g. beyond the “return”
at the end of the callback). For example, suppose I provide a service that has
a method which query’s a huge database. Typically querys may take several
seconds and during the time the service is waiting on the response from an
internal database, I don’t want to block the mainloop of the DBus service.
In fact, I want to be able to handle multiple overlapping requests (or at least
queue these requests up for later processing). So my server has a DBus method
that looks like this:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>void getResults(const char* cmd, char** results)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>{<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> //
Issue request to the internal DB<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> //
Either block (do NOT want to do this), or better yet, somehow defer replying to<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> //
this request at some point in the future.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> //
I don’t want the binding/wrapper code to immediately return a result<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> return;<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>If I block waiting on the response from the database, it
ties up the DBus main loop which is not what I want to do. Spawning a thread to
wait on the database doesn’t help much either since when the function
returns most bindings (I think) expect the result to be filled in. Ideally, I’d
like to copy what state information I need related to the request and on-going
database query, stash that somewhere, register a callback for the internal
database to indicate completion, and return WITHOUT the DBus binding
immediately replying to the request. In other proprietary frameworks I
have used there has been a method to “detach” the request in the
service handler and then later re-associate that request with the results. I *<b><span
style='font-weight:bold'>think</span></b>* the lowest level DBus library fundamentally
supports this notion of deferring a response but I am not sure how the more
mature DBus bindings/wrappers handle this. I’d rather NOT have to use a
one-way call where there is no immediate response but a signal is issued later
time containing the results and a key/token used to associate the earlier
request with the later response. It’s cumbersome to design such services.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Can anyone suggest the appropriate way to architect this
pattern (preferably using either the C++ or Glib binding to DBus)?<o:p></o:p></span></font></p>
</div>
</body>
</html>