Version 9 introduced the WolframStreamsLibrary.h header for LibraryLink. It contains MInputStream and MOutputStream.
What can I do with this header? How can I use these functions? Are the documented anywhere?
Possibly related:
Update 2018 March: Partial spelunking results, someone else may want to pick up the trail.
Currently, my best guess is that this is for extending Mathematica with new streams. I believe it to be the analogue of DefineInputStreamMethod and DefineOutputStreamMethod. The struct MInputStream contains most of the functions that would be passed to DefineInputStreamMethod. The actual analogue is registerInputStreamMethod in WolframLibray.h, which I believe sets the equivalents of the ConstructorFunction and NameTestFunction. My (unverified!) guesses for the parameters of registerInputStreamMethod are:
const char *name, same asnameinDefineInputStreamMethodvoid (*ctor)(MInputStream, const char* msgHead, void* optionsIn), same as"ConstructorFunction". Should fill out theMInputStreamstruct passed to it. But in what format does it receive the options?mbool (*handlerTest)(void*, char*), probably the same as"NameTestFunction". But what is thevoid *parameter for? ThemethodData?void* methodData, possibly pointer to private data used by the stream implementation.void (*destroyMethod)(void* methodData), possibly for freeing themethodData? This is not the"CloseFunction".
There are still many key questions remaining before one could actually implement everything that is needed.
What is the methodData? A state unique to each instance of the stream, or shared by all of them? (I assume this is shared, and the individual state is in the MInputStream struct.) What exactly should each of these functions do?
An example implementation is woefully needed. After some more spelunking, I found one in SystemFiles/Links/SocketLink/Source/C. This example may provide enough information for us to write our own implementation, but I have not yet had the time/motivation to do all this. I still wanted to share my findings with others who may be interested in continuing the spelunking.
Note that the SocketLink example won't answer all questions: it often passes NULL pointers or simply ignores arguments (e.g the options in the constructor).
Comments
Post a Comment