Create a user-defined stream class
You can provide a stream I/O interface to create your own protocol for reciprocal reading and writing of SQL data and other data streams.
- The calling code can use the exact same syntax to access different kinds of data.
- The underlying data can be transparent to the calling code.
- A type-specific stream-open function
Each type of data to which a stream provides access usually has a unique way of being opened. Its stream-open function must accept as arguments the information required to open the data so that the mi_stream_init() function can initialize the stream.
- Type-specific implementations for the generic stream I/O functions
You must implement the generic stream I/O functions that your stream supports so that they correctly handle the format of your stream data.
MI_STREAM *mi_stream_open_mytype(void *mydata)
{
MI_STREAM *strm_desc; /* can be passed in as input to open()
* also.
*/
/* Code to process any stream-open arguments */
...
/* Call to mi_stream_init() to allocate and initialize
* the stream descriptor
*/
strm_desc = mi_stream_init(stream_ops_mytype, mydata, NULL);
/* Return pointer to newly allocated stream descriptor */
return strm_desc;
}
Because mi_stream_init() receives a NULL-valued pointer as its stream descriptor, it allocates the stream descriptor in the current memory duration. The mi_stream_init() function then returns a pointer to this newly allocated structure, which the mi_stream_open_mytype() function also returns.