<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 14, 2015 at 8:28 AM, Daniel Pocock <span dir="ltr"><<a href="mailto:daniel@pocock.pro" target="_blank">daniel@pocock.pro</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 13/10/15 22:51, Gustavo Boiko wrote:<br>
><br>
><br>
> On Tue, Oct 13, 2015 at 5:39 PM, Daniel Pocock <<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a><br>
</span><span class="">> <mailto:<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a>>> wrote:<br>
><br>
><br>
><br>
> On 13/10/15 22:34, Gustavo Boiko wrote:<br>
> > Hi<br>
> ><br>
> > On Tue, Oct 13, 2015 at 5:18 PM, Daniel Pocock <<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a> <mailto:<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a>><br>
</span><div><div class="h5">> > <mailto:<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a> <mailto:<a href="mailto:daniel@pocock.pro">daniel@pocock.pro</a>>>> wrote:<br>
> ><br>
> ><br>
> ><br>
> ><br>
> > If a connection manager uses some library that creates its own threads<br>
> > (it is not a Qt based library either), are there any constraints on how<br>
> > these threads interact with the TelepathyQt API?<br>
> ><br>
> > For example, if the connection is completed in another thread, is it<br>
> > safe to call setStatus() from that thread?<br>
> ><br>
> ><br>
> > It is probably not safe to call that from a different thread. If<br>
> > setStatus() was a Qt slot, you could use QMetaObject::invokeMethod()<br>
> > with Qt::QueuedConnection directly, but that's not the case. So, what<br>
> > you can do is to define a slot to proxy the request and use<br>
> > QMetaObject::invokeMethod() to call that slot.<br>
> ><br>
> ><br>
><br>
><br>
> Thanks for the feedback - could you suggest any example of this in<br>
> another connection manager or similar code that I can look at?<br>
><br>
><br>
> I don't recall seeing another CM with that, but it would be something<br>
> like this:<br>
><br>
> class MyConnection : public Tp::BaseConnection<br>
> {<br>
> ...<br>
> public Q_SLOTS:<br>
> void setStatusSlot(uint newStatus, uint reason) {<br>
> setStatus(newStatus, reason);<br>
> }<br>
> }<br>
><br>
> and then, in the other thread you would call:<br>
> QMetaObject::invokeMethod(myConnectionObject, "setStatusSlot",<br>
> Qt::QueuedConnection, Q_ARG(uint, status), Q_ARG(uint, reason));<br>
><br>
> That should be more or less what you need to do in your CM.<br>
><br>
<br>
<br>
</div></div>Thanks for that example<br>
<br>
The library I'm using (reSIProcate) also lets me run the event loop in a<br>
thread that I create myself<br>
<br>
Does TelepathyQt provide a mechanism to create threads that can be used<br>
this way and if the threads are created by TelepathyQt, is it safe to<br>
make calls to things like setStatus() directly?<br></blockquote><div><br></div><div>TelepathyQt doesn't have any specific threading capabilities. But Qt does. You can look for the documentation of QThread as it explains how threading works in Qt. You can pretty much create this thread using QThread and run the event loop there, but the way Qt synchronizes threads is through events (which is what a queued method invocation does in the end), which is why you need slots.</div><div><br></div><div>It would probably be possible to make Tp::BaseConnection thread safe, but I don't think it is in the scope of TelepathyQt itself, as it only adds extra complexity with little to no gain (as usually the thread synchronization would be handle outside of TelepathyQt anyways).</div><div><br></div><div>Cheers</div><div><br></div><div>Boiko</div></div></div></div>