<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="319926" data-post-id="319926">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="tj0" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  tj0
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="stevensonmt" data-post="11" data-topic="61972">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/48/20503_2.png" class="avatar"> stevensonmt:</div>
<blockquote>
<p>This question has been shockingly hard to find answers for on google.</p>
</blockquote>
</aside>
<p>Yah, that is very true regarding dbus.  <img src="https://forum.elixirforum.com/images/emoji/apple/cry.png?v=15" title=":cry:" class="emoji" alt=":cry:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="stevensonmt" data-post="11" data-topic="61972">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/48/20503_2.png" class="avatar"> stevensonmt:</div>
<blockquote>
<p>Have you figured out how/where to define your interfaces and services?</p>
</blockquote>
</aside>
<p>I have not made a program that publishes events, but this seems to be per-program from what I’ve seen when I was debugging the interface.</p>
<p>The only reference I could find which supports this is at <a href="https://freedesktop.org/wiki/IntroductionToDBus/" rel="noopener nofollow ugc">https://freedesktop.org/wiki/IntroductionToDBus/</a><br>
</p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/6/2/622c7250ef43c6f0babe1c5681190b0378428331.jpeg" data-download-href="https://forum.elixirforum.com/uploads/default/622c7250ef43c6f0babe1c5681190b0378428331" title="image" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/optimized/3X/6/2/622c7250ef43c6f0babe1c5681190b0378428331_2_690x179.jpeg" alt="image" data-base62-sha1="e0u18HvLae5kn9Y4HboRXg0DJLj" width="690" height="179" srcset="https://forum.elixirforum.com/uploads/default/optimized/3X/6/2/622c7250ef43c6f0babe1c5681190b0378428331_2_690x179.jpeg, https://forum.elixirforum.com/uploads/default/optimized/3X/6/2/622c7250ef43c6f0babe1c5681190b0378428331_2_1035x268.jpeg 1.5x, https://forum.elixirforum.com/uploads/default/original/3X/6/2/622c7250ef43c6f0babe1c5681190b0378428331.jpeg 2x" data-dominant-color="E7E6E6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1200×312 53.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="319926" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-319926" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="319926"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="320561" data-post-id="320561">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="stevensonmt" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/120/20503_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  stevensonmt
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Plan to update this thread with a more thorough breakdown when I wrap up the project but I just wanted to mention that in order to get the functionality out of dbus that I really wanted I had to break down and use Rustler to wrap dbus-rs bindings. The interaction can then be handled with busctl from scripts or from within the app using the dbus-rs calls. I’m sure there are other ways but this is the only workable solution I could find.</p>
<p>To anyone interested, I wanted to use the zbus crate instead of dbus-rs because the documentation on that crate is so good, but zbus is async first, so much that even the blocking API requires use of async. Async functions with Rustler were a layer of complexity beyond my current capacity.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="320561" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-320561" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="320561"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="320579" data-post-id="320579">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I haven’t touched Rust in several months but if memory serves there are two ways:</p>
<ol>
<li>Use a global convenience function:</li>
</ol>
<pre data-code-wrap="rust"><code class="lang-rust">async fn do_async_stuff() -&gt; usize {
  return 7;
}

fn main() {
  let future = do_async_stuff();
  futures::executor::block_on(future);
}
</code></pre>
<ol start="2">
<li>If you have access to the Tokio runtime (which you absolutely can get by <em>not</em> using the <code>#[tokio::main]</code> macro and just put the 3-4 lines of boilerplate code in yourself, see here for info: <a href="https://docs.rs/tokio/latest/tokio/attr.main.html#usage" class="inline-onebox" rel="noopener nofollow ugc">main in tokio - Rust</a> – I have copied the runtime initialization code from there) then you can just use it like this:</li>
</ol>
<pre data-code-wrap="rust"><code class="lang-rust">async fn do_async_stuff() -&gt; usize {
  return 7;
}

fn main() {
  let mut rt = tokio::runtime::Builder::new_multi_thread()
    .enable_all()
    .build()
    .unwrap();

  let future = do_async_stuff();
  rt.block_on(future);
}
</code></pre>
<p>Rust async allows you to introduce those crossing points between async and sync code.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="320579" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-320579" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="320579"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="320585" data-post-id="320585">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="stevensonmt" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/120/20503_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  stevensonmt
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks. The issue was around implementing Encoder trait or something like that. Not really the async logic itself. I just want sure how to implement for a Future.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="320585" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-320585" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="320585"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="320586" data-post-id="320586">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well if you send more info I can try my hand at it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="320586" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-320586" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="320586"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="345011" data-post-id="345011">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adamwight" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/adamwight/120/26503_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adamwight
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you for the sample code, it was helpful to get started!  Trying this out, I would lean towards using a library for anything non-trivial.  First impressions from my armchair are that D-Bus has a non-standard data and type wire <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling" rel="noopener nofollow ugc">format</a> that I would not like to learn, the protocol can be used to publish a service, and processes can notify one another.  The spec is a bit big, for example defining its own authentication on top of SASL, and it seems that none of the BEAM libraries implement the whole spec yet.</p>
<p>For now though, I have similarly limited needs as others here and I can hide the ad-hoc bits in a single-purpose module.  I’m trying to detect and integrate with a local music player, so I wanted the session pointed to by the logged-in user’s <code>DBUS_SESSION_BUS_ADDRESS</code> environment variable, which is passed through to the System.cmd transparently.  This makes the send method simpler,</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def send(dest, object_name, action, message \\ nil) do
  {output, 0} =
    System.cmd(
      "dbus-send",
      [
        "--session",
        "--print-reply=literal",
        "--dest=#{dest}",
        object_name,
        action
      ] ++ if(message, do: [message], else: [])
    )

  output
end
</code></pre>
<p>My usage can ignore the custom data serialization for now,</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def mediaplayer2_available?() do
  send(
    "org.freedesktop.DBus",
    "/org/freedesktop/DBus",
    "org.freedesktop.DBus.ListNames"
  )
  |&gt; String.match?(~r/MediaPlayer2/)
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="345011" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-345011" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="345011"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="345024" data-post-id="345024">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adamwight" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/adamwight/120/26503_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adamwight
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><s>Deleted post</s></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="345024" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-interact-with-d-bus-from-an-elixir-app/61972/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-345024" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="345024"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>