Redirecting the Mosel output
When integrating a Mosel model into an application it may be desirable to be able to redirect any output produced by the model to the application. This can be done by the means of a callback function. This function takes a predefined signature as shown in the following C program. If it is called from outside of the execution of any Mosel model, its parameter model will be NULL. In our example the callback function prefixes the printout of every line of Mosel output with Mosel:.
#include <stdio.h> #include "xprm_mc.h" /**** Callback function to handle output ****/ long XPRM_RTC cbmsg(XPRMmodel model, void *info, char *buf, unsigned long size) { printf("Mosel: %.*s", (int)size, buf); return 0; } int main() { int result; char outfile_name[40]; /* File name of output stream */ if(XPRMinit()) /* Initialize Mosel */ return 1; /* Prepare file name for output stream */ /* using 'cb' driver */ sprintf(outfile_name, "cb:%p", cbmsg); /* Set default output stream to callback */ XPRMsetdefstream(NULL, XPRM_F_WRITE, outfile_name); /* Execute = compile/load/run a model */ if(XPRMexecmod(NULL, "burglar2.mos", NULL, &result, NULL)) return 2; return 0; }
The same procedure that has been presented here for redirecting the Mosel output can also be applied to redirect any error messages produced by Mosel—the only required modification consists in replacing the constant XPRM_F_WRITE by XPRM_F_ERROR in the argument of function XPRMsetdefstream.
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.