<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div>Yes, what you describe is what I am implementing.  I have also called it "persistence" in my application. Normally, when all audio ports are disconnected, my application quits.  But I have an command line option to keep it running and have it "persist," not quit, try to reconnect.</div><div><br></div><div>I just implemented a simple queue of jack_port_ids.  Callbacks add their relevant port_ids into the queue, with my main thread checking the queue periodically, to further check the queued ports for re-connection.  This was not as hard as I though it would be, and works well so far.  Just queueing the port id is a lot simpler that what you are doing in MusE, but it is sufficient for my application.</div><div><br></div><div>One remaining question: Am I safe assuming that jack2 will call my callbacks one at a time from a single thread, or do I need to make my port id queue writing function thread safe, just in case jack2 calls my callbacks concurrently?</div><div><br></div><div>Ethan...</div><div><br></div><div>On Fri, 2019-08-09 at 01:52 -0400, Tim wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>On 8/8/19 10:20 PM, Ethan Funk wrote:</pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>In an application I am writing, I am getting an error message out stderr </pre><pre>(see email subject), and a connection failure return result, when I try </pre><pre>to use jack_connect() from inside a jack_set_port_registration_callback </pre><pre>function, using Jack2. My goal is to have the application remember and </pre><pre>re-connect to a disconnected port if/when it "comes back." Am I going to </pre><pre>need to create a mostly sleeping thread just for port re-connections </pre><pre>attempts, or is there something obvious I am missing?</pre><pre><br></pre><pre>Thanks,</pre><pre>Ethan...</pre></blockquote><pre><br></pre><pre>If I understand your goal, I did this in MusE.</pre><pre>I called it 'persistent connections', or 'persistent ports'.</pre><pre><br></pre><pre>For example you can unplug a USB midi device currently</pre><pre>  in use by MusE as a 'Jack device', then re-plug it,</pre><pre>  and MusE will automatically reconnect to its ports</pre><pre>  as if nothing happened and you may continue playing.</pre><pre>(I made our 'ALSA devices' do the same thing!)</pre><pre>It should also work with other Jack clients.</pre><pre><br></pre><pre>Look in our driver/jack.cpp, at:</pre><pre>   static void registration_callback(...),</pre><pre>   static void port_connect_callback(...),</pre><pre>  and</pre><pre>   static int graph_callback(...),</pre><pre>   // This is called in the gui context,</pre><pre>   //  triggered by graph_callback()</pre><pre>   void JackAudioDevice::graphChanged().</pre><pre><br></pre><pre>It was complicated. Very. I needed to support Jack 1 and 2.</pre><pre>So there are a few sequences of calls and resulting</pre><pre>  sequences of callbacks for example that are different</pre><pre>  in Jack 1 and 2. Several tricks and traps. See comments.</pre><pre><br></pre><pre>My system relies HEAVILY on the jack port 'alias names',</pre><pre>  because it was pretty much the ONLY thing you can rely on,</pre><pre>  because the regular port names and port numbers change</pre><pre>  upon re-plugging. It automatically chooses which alias is</pre><pre>  best or falls back to the not so good canonical port name.</pre><pre><br></pre><pre>So, that's what it 'remembers' between device plug ins -</pre><pre>  simply the port alias or name text.</pre><pre><br></pre><pre>HTH.</pre><pre>Tim.</pre><pre>_______________________________________________</pre><pre>Jack-Devel mailing list</pre><a href="mailto:Jack-Devel@lists.jackaudio.org"><pre>Jack-Devel@lists.jackaudio.org</pre></a><pre><br></pre><a href="http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org"><pre>http://lists.jackaudio.org/listinfo.cgi/jack-devel-jackaudio.org</pre></a><pre><br></pre></blockquote></body></html>