Load an entire class from an external file.
MCO_RET mco_db_xml_import( /*IN*/ mco_trans_h t,
/*IN*/ void *stream_handle,
/*IN*/ mco_stream_read input_stream_reader );
t
mco_trans_h transaction handle returned by mco_trans_start().stream_handle
input_stream_reader
This function imports database data from an input stream. The runtime calls the application-defined handler to manage the input stream.
It is the application’s responsibility to open the input stream in the proper mode to read binary data and to ensure that there is adequate memory to hold the database. See the control structure stream reader for further details.
MCO_S_OK
MCO_E_NOINSTANCE
MCO_E_NOMEM
MCO_E_LOAD_DATA
Application snippet:
mco_size_sig_t file_reader( void *stream_handle /* FILE * */, /* OUT */void *to, mco_size_t max_nbytes )
{
FILE *f = (FILE *)stream_handle;
mco_size_sig_t nbs;
nbs = fread( to, 1, max_nbytes, f );
return nbs;
}
int main(int argc, char** argv)
{
mco_db_h db;
MCO_RET rc;
mco_device_t dev;
mco_db_params_t db_params;
mco_trans_h t;
FILE * f;
...
if( (rc = mco_runtime_start()) != MCO_S_OK)
exit(-1);
rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
if ( MCO_S_OK != rc )
{
rc = mco_db_connect(dbname, &db);
...
/* Import database */
f = fopen( "db.xml", "rb" );
if ( f == 0 )
{
printf( "\n\t Can't open input file for streaming\n");
}
else
{
rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
if ( MCO_S_OK == rc )
{
rc = mco_db_xml_import( t, f, file_reader );
if ( MCO_S_OK == rc )
{
rc = mco_trans_commit( t );
...
}
fclose( f );
...
}
}
...
}
}