<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>insomnia bytes &#187; api</title>
	<atom:link href="http://bytes.inso.cc/wp/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://bytes.inso.cc/wp</link>
	<description>Imagination is a nightbird's dream</description>
	<lastBuildDate>Sat, 07 Nov 2009 17:13:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Upgrade to rv-split now!</title>
		<link>http://bytes.inso.cc/wp/2008/12/09/upgrade-to-rv-split-now/</link>
		<comments>http://bytes.inso.cc/wp/2008/12/09/upgrade-to-rv-split-now/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 16:49:42 +0000</pubDate>
		<dc:creator>theefer</dc:creator>
				<category><![CDATA[xmms2]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[rv-split]]></category>

		<guid isPermaLink="false">http://bytes.inso.cc/wp/?p=819</guid>
		<description><![CDATA[If you&#8217;ve been hanging around the XMMS2 hype-sphere lately, you&#8217;ve certainly heard &#8220;wait for rv-split to be merged&#8221; almost as often as &#8220;it should be a service client&#8221;.  Well, wait no more, for rv-split has made it into the -devel tree!
It means that all C clients are broken now, and possibly clients in other [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been hanging around the XMMS2 hype-sphere lately, you&#8217;ve certainly heard &#8220;wait for rv-split to be merged&#8221; almost as often as &#8220;it should be a service client&#8221;.  Well, wait no more, for rv-split has made it into the -devel tree!</p>
<p>It means that all C clients are broken now, and possibly clients in other languages too.  Yes, yours too.  It needs fixing, and I&#8217;m going to explain how.</p>
<p>But, you ask, what <em>is</em> rv-split in the first place?</p>
<p>The <strong>result/value-split</strong>, AKA &#8220;rv-split&#8221; or sometimes just &#8220;rv&#8221;, is a change in the XMMS2 clientlib.  Up until now, values returned by the server were kept inside the <code>xmmsc_result_t</code> structure that you got back from the call. The data was to be fetched directly from the result.</p>
<p>In sync mode, it went something like this:</p>
<p>[code lang="c"]<br />
xmmsc_result_t *result;<br />
const char *name;</p>
<p>result = xmmsc_playlist_current_active (conn);<br />
xmmsc_result_wait (result);</p>
<p>if (xmmsc_result_iserror (result)) {<br />
   printf ("Server error: %s\n", xmmsc_result_get_error (result));<br />
   exit (1);<br />
}</p>
<p>// The name is retrieved from the result<br />
if (xmmsc_result_get_string (result, &#038;name)) {<br />
   printf ("Active playlist is %s\n", name);<br />
}</p>
<p>// We free the result, which also frees all the data it referenced,<br />
// i.e. the 'name' string<br />
xmmsc_result_unref (result);<br />
[/code]</p>
<p>The goal of rv-split was to isolate values outside of the result structure (for reasons that will become more obvious when we talk about the async calls).  To do that, we introduced a new structure called <code>xmmsv_t</code> (for &#8220;xmms value&#8221;), that can contain any type of value. Accessor functions are used to extract each type from it, in a similar way to how it was done with result structures.</p>
<p>Let&#8217;s show the sync example again:<br />
[code lang="c"]<br />
xmmsc_result_t *result;<br />
xmmsv_t *value;<br />
const char *name, *errbuf;</p>
<p>result = xmmsc_playlist_current_active (conn);<br />
xmmsc_result_wait (result);<br />
value = xmmsc_result_get_value (result);</p>
<p>if (xmmsv_get_error (value, &#038;errbuf)) {<br />
   printf ("Server error: %s\n", errbuf);<br />
   exit (1);<br />
}</p>
<p>if (xmmsv_get_string (value, &#038;name)) {<br />
   printf ("Active playlist is %s\n", name);<br />
}</p>
<p>// We free the result, which also frees the value it contained,<br />
// i.e. the 'value' variable, and the 'name' string<br />
xmmsc_result_unref (result);<br />
[/code]</p>
<p>All we have to do is extract the <code>xmmsv_t</code> from the <code>xmmsc_result_t</code>.  No raw data is stored in the result structure anymore.</p>
<p>Note that it also affects the error handling: if the server returns an error, it&#8217;s not a special state; it just returns an <code>xmmsv_t</code> of type <code>ERROR</code>.  <code>xmmsv_get_error</code> is used to retrieve the error message, or the function will return <code>FALSE</code> if the value was not an error.  Just like before, the value is freed automatically, so no need to worry about anything, just free the result structure.</p>
<p>Now, let&#8217;s move to the async case.  In async, we don&#8217;t wait on results, we register one (or more) callback (AKA notifier) that will be called when the answer comes back from the server.  Up until now, callbacks received the original result structure in argument (plus a userdata pointer).  Like before, the result contained the value returned by the server.  It could also be used to restart signals or disconnect broadcasts (more on that later).</p>
<p>In code:<br />
[code lang="c"]<br />
void<br />
callback (xmmsc_result_t *result, void *udata)<br />
{<br />
   const char *name;</p>
<p>   if (xmmsc_result_iserror (result)) {<br />
      printf ("Server error: %s\n", xmmsc_result_get_error (result));<br />
      exit (1);<br />
   }</p>
<p>   // The name is retrieved from the result<br />
   if (xmmsc_result_get_string (result, &#038;name)) {<br />
      printf ("Active playlist is %s\n", name);<br />
   }</p>
<p>   // Each notifier holds a reference to the result<br />
   xmmsc_result_unref (result);<br />
}</p>
<p>int<br />
main ()<br />
{<br />
   // [...]</p>
<p>   xmmsc_result *result;</p>
<p>   result = xmmsc_playlist_current_active (conn);<br />
   xmmsc_result_notifier_set (result, callback, NULL);<br />
   xmmsc_result_unref (result);<br />
}<br />
[/code]</p>
<p>One of the arguments for the rv-split refactoring was that the result structure is meant to handle the command and how we treat it, but we don&#8217;t really need it to be passed to the callback.  It allows developers to do weird stuff (wait on the result in the callback, restart a non-signal, etc — don&#8217;t try this at home).</p>
<p>All we need really is the value that the server returned.  That is, the <code>xmmsv_t</code>!</p>
<p>Which gives:<br />
[code lang="c"]<br />
int<br />
callback (xmmsv_t *value, void *udata)<br />
{<br />
   const char *name, *errbuf;</p>
<p>   if (xmmsv_get_error (value, &#038;errbuf)) {<br />
      printf ("Server error: %s\n", errbuf);<br />
      exit (1);<br />
   }</p>
<p>   // The name is retrieved from the value<br />
   if (xmmsv_get_string (value, &#038;name)) {<br />
      printf ("Active playlist is %s\n", name);<br />
   }</p>
<p>   // Note that we do not need to unref anything here!<br />
   // The value will be freed automagically after this!</p>
<p>   // I will explain this in a minute...<br />
   return FALSE;<br />
}</p>
<p>int<br />
main ()<br />
{<br />
   // [...]</p>
<p>   xmmsc_result *result;</p>
<p>   result = xmmsc_playlist_current_active (conn);<br />
   xmmsc_result_notifier_set (result, callback, NULL);<br />
   xmmsc_result_unref (result);<br />
}<br />
[/code]</p>
<p>Easy and safer!</p>
<p>But maybe you noticed a hitch: hey, how do I restart my signals or disconnect my broadcasts from the callback now?</p>
<p>Well, it&#8217;s even easier than before.  Previously, here is how you restarted signals:<br />
[code lang="c"]<br />
void<br />
signal_callback (xmmsc_result_t *result, void *udata)<br />
{<br />
   xmmsc_result_t *newres;</p>
<p>   // [...]</p>
<p>   newres = xmmsc_result_restart (result);<br />
   xmmsc_unref (result);<br />
   xmmsc_unref (newres);<br />
}<br />
[/code]</p>
<p>This simply becomes:<br />
[code lang="c"]<br />
int<br />
signal_callback (xmmsv_t *value, void *udata)<br />
{<br />
   // [...]</p>
<p>   return TRUE;<br />
}<br />
[/code]</p>
<p>That&#8217;s right, it&#8217;s that simple!  The return value of a callback is some sort of &#8220;keep alive&#8221; flag.  If a callback returns <code>TRUE</code>, the signal will be restarted or the broadcast will keep going.  If it returns <code>FALSE</code>, the signal will die off (not restarted) or the broadcast will be disconnected.</p>
<p>Note that the return value has no meaning in the case of regular commands, like the earlier example.</p>
<p>Here are a couple of other things you might need to know about the new API:</p>
<ul>
<li>By default, the <code>xmmsv_t</code> is freed automatically (since it&#8217;s owned by the <code>xmmsc_result_t</code>). If you want to keep it around for some reason, you can ref it using <code>xmmsv_ref</code>, but don&#8217;t forget to unref it again when you&#8217;re done with <code>xmmsv_unref</code>, else your client will leak!</li>
<li>Dict and List accessors have been made more generic and sexy, so check the documentation to learn how to access these types!</li>
<li>PropDicts (returned by <code>xmmsc_medialib_get_info</code>) have been replaced by dict-in-dicts, but you can convert them back to regular Dicts using the <code>xmmsv_propdict_to_dict</code> helper function. Again, use the Doc, Luke!</li>
<li>Check how your favorite bindings handled the upgrade, the upgrade path might be softer depending on the language.</li>
<li>The tutorials have been updated (or will be shortly as soon as my patch for #2018 is merged — you can check it in the meantime). It features some code working with propdicts and list iterators, and other things in general.</li>
</ul>
<p>I think you should now be ready to upgrade your clients to rv-split! It&#8217;s been fun hacking on the new code this summer, and getting help from everyone to improve it and get it into -devel!</p>
<p>Feel free to ask questions on IRC or in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://bytes.inso.cc/wp/2008/12/09/upgrade-to-rv-split-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MP3Tunes contest: XMMS2 support?</title>
		<link>http://bytes.inso.cc/wp/2007/09/21/mp3tunes-contest-xmms2-support/</link>
		<comments>http://bytes.inso.cc/wp/2007/09/21/mp3tunes-contest-xmms2-support/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 05:27:58 +0000</pubDate>
		<dc:creator>theefer</dc:creator>
				<category><![CDATA[xmms2]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[mp3tunes]]></category>
		<category><![CDATA[music.player]]></category>

		<guid isPermaLink="false">http://inso.cc/wp/2007/09/21/mp3tunes-contest-xmms2-support/</guid>
		<description><![CDATA[MP3Tunes may or may not be an Evil (as in Axis of ~) service, but it just announced a developer contest to encourage people to implement its API and create new interfaces (on the desktop, mobile phone, TV, toilet seat, whatever).
The contest page on the official website isn&#8217;t quite as verbose as one would have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mp3tunes.com/">MP3Tunes</a> may or may not be an Evil (as in <em>Axis of ~</em>) service, but it just announced a developer contest to encourage people to implement its API and create new interfaces (on the desktop, mobile phone, TV, toilet seat, whatever).</p>
<p>The <a href="http://www.mp3tunes.com/cb/contest">contest page on the official website</a> isn&#8217;t quite as verbose as one would have hoped, though, and the link to the rules points to a missing webpage. Some more intel is however available in a <a href="http://www.michaelrobertson.com/archive.php?minute_id=244">blog post on Michael Robertson&#8217;s blog</a>. Yes, Michael MP3.Com/Linspire Robertson, who is also Michael MP3Tunes Robertson, obviously.</p>
<p>The deal: you have until November 5th, 2007, to submit an interface to MP3Tunes in one of the ten predefined categories (Desktop Player, Game Console, WebUI, PDA, etc). The winner in each category will receive a cosy $1000. I haven&#8217;t determined whether it&#8217;s a public vote, a closed jury, or some other semi-random algorithm involving <a href="http://www.neilgaiman.com/journal/uploaded_images/IMG_0434-747430.JPG">car-driving girafes</a>.</p>
<p>I haven&#8217;t yet checked what the <a href="http://www.mp3tunes.com/api/">API</a> offers, either, but I sure wonder whether we could hack something together with <a href="http://xmms2.sf.net/">XMMS2</a>. If it could be hooked into the daemon, and apart from the obvious ever satisfying benefit of being neat and fun, it might allow using any of our interfaces (AKA <a href="http://wiki.xmms2.xmms.se/index.php/XMMS2_Clients">clients</a>) to play music from MP3Tunes.</p>
<p>From what I see, MP3Tunes isn&#8217;t much more than an online storage for music files, that you either upload or retrieve from wherever on the web. (Let&#8217;s leave the obvious legal issues to Michael&#8217;s lawyers, shall we?) This means that you have a whole medialib on their server, apparently indexed and searchable and, naturally, playable. If I&#8217;m not mistaken, the &#8220;streaming&#8221; seems to be nothing more than retrieving the music file (original or transcoded to mp3) over HTTP, which XMMS2 already supports.</p>
<p>In the current scheme, our medialib assumes to contain all the media and their metadata, so unless this is extended to support distributed media libraries (hello, Summer of Code 2008?), it means we would have to sync the remote MP3Tunes medialib to the local XMMS2 medialib. Sounds a bit tedious and expensive and ugly, so suggestions are welcome with better solutions!</p>
<p>These are the few implementation considerations I can think of off the top of my head, but overall it doesn&#8217;t sound so complicated, unless we want the support to be very smart (async, allow upload/download media, etc).</p>
<p>Of course, the whole contest looks like a call for devs to code cool interfaces to a money-making online service (mostly) for free, more than anything else, but let&#8217;s just consider the idea for a minute and whether it could justify spending some energy on writing one or several polished clients (which I think most of us agree we need).</p>
<p>And transparently sharing music through a (currently) free, password protected, remote service can&#8217;t be such a useless idea, can it?</p>
]]></content:encoded>
			<wfw:commentRss>http://bytes.inso.cc/wp/2007/09/21/mp3tunes-contest-xmms2-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
