<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>stacked file interfaces</title>
		<link>http://www.allegro.cc/forums/view/605824</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 15 Dec 2010 11:35:59 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How does one create a stacked file interface without having to know about the internals of the <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a></span> format?</p><p>It seems like there needs to be a function like:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>f <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"blah.txt"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_new_file_interface"><span class="a">al_set_new_file_interface</span></a><span class="k2">(</span>foo<span class="k2">)</span><span class="k2">;</span>
al_fopen_f<span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span> <span class="c">// calls foo.fi_fopen_f(f)</span>
</pre></div></div><p>

Now the <span class="source-code">foo</span> file interface gets passed a reference to the <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a></span>. So basically it acts as a filter or wrapper over top of an existing file interface.</p><p>The function could return <span class="source-code">NULL</span> if there is no reasonable implementation.</p><p>Some applications:
</p><ul><li><p>file slices - overrides seeking, then passes reads/writes through
</p></li><li><p>compression - compress data on the fly
</p></li><li><p>encryption - encrypt data on the fly</p></li></ul><p>Edit: removed second question.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 15 Dec 2010 10:44:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>All ALLEGRO_FILEs store the interface they were created with. If you change the current interface, opened files won&#39;t just stop working.</p><p>Which is why you can have memory files and disk files open at the same time.</p><p>The memfile addon currently uses that feature to provide its own open api call, which creates its own ALLEGRO_FILE setup with its special hooks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 15 Dec 2010 11:00:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605824/894867#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> All ALLEGRO_FILEs store the interface they were created with. If you change the current interface, opened files won&#39;t just stop working.
</p></div></div><p>I know. That&#39;s not what I&#39;m talking about...</p><p>Look at the memfile implementation. It has a <span class="source-code">NULL</span> <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a></span> entry because it makes no sense. memfile doesn&#39;t open a <span class="source-code"><span class="k1">char</span><span class="k3">*</span></span> filename, it opens a file handle. So it  must include the internal Allegro file header to set the vtable by hand. If there was an <span class="source-code">al_fopen_f</span> function and related hook in the interface, it wouldn&#39;t have to do that.</p><p>Edit: Although this would also require something like <span class="source-code">al_set<span class="k3">/</span>get_file_data<span class="k2">(</span><span class="k2">)</span></span> function that would return a <span class="source-code"><span class="k1">void</span><span class="k3">*</span></span> pointer to attach custom user data or something similar to accomplish that. </p><p>So it would look like:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">struct</span> <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k2">{</span>
  ... vtable<span class="k2">;</span>
  <span class="k1">void</span> <span class="k3">*</span>data<span class="k2">;</span>
<span class="k2">}</span>

<span class="k1">static</span> <span class="k1">size_t</span> memfile_fwrite<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>fp, <span class="k1">const</span> <span class="k1">void</span> <span class="k3">*</span>ptr, <span class="k1">size_t</span> size<span class="k2">)</span>
<span class="k2">{</span>
   ALLEGRO_FILE_MEMFILE <span class="k3">*</span>mf <span class="k3">=</span> al_get_file_data<span class="k2">(</span>fp<span class="k2">)</span><span class="k2">;</span>
...
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 15 Dec 2010 11:19:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605824/894871#target">Matthew Leverton</a> said:</div><div class="quote"><p>I know. That&#39;s not what I&#39;m talking about...</p></div></div><p>No but it does provide what you need.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Look at the memfile implementation. It has a NULL fopen entry because it makes no sense. memfile doesn&#39;t open a char* filename, it opens a file handle. So it must include the internal Allegro file header to set the vtable by hand. If there was an al_fopen_f function and related hook in the interface, it wouldn&#39;t have to do that.</p></div></div><p>

Sure a helper to play with the vtable may help. But I don&#39;t think anything more than that is required. It sounded to me like you were asking for a bunch of new api calls just to support something you can do now.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>So it would look like:</p></div></div><p>I don&#39;t think thats necessary or useful at all.</p><p>append:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>memfile doesn&#39;t open a char* filename, it opens a file handle. </p></div></div><p>It actually needs to provide a memory buffer and a length, so it can&#39;t just use an al_fopen_f method.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 15 Dec 2010 11:28:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605824/894874#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> It actually needs to provide a memory buffer and a length, so it can&#39;t just use an al_fopen_f method.
</p></div></div><p>The <span class="source-code">al_open_memfile</span> function would call <span class="source-code">al_fopen_f</span> internally. </p><p>This is the principle concept: <i>Hide the Allegro internals</i>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 15 Dec 2010 11:33:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605824/894877#target">Matthew Leverton</a> said:</div><div class="quote"><p>This is the principle concept: Hide the Allegro internals.</p></div></div><p>Eh I suppose. I don&#39;t really see a huge point in doing so though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 15 Dec 2010 11:35:59 +0000</pubDate>
	</item>
</rss>
