adds client callback API function
This commit is contained in:
@@ -517,6 +517,18 @@ typedef struct Project *EN_Project;
|
||||
|
||||
********************************************************************/
|
||||
|
||||
/**
|
||||
@brief Set a user-supplied callback function for reporting
|
||||
@param ph an EPANET project handle.
|
||||
@param callback a function pointer with declared signature, which gets called by EPANET for reporting.
|
||||
@return an error code.
|
||||
@details The report callback function must have the signature specified - void(void* userData, EN_Project, char*) -
|
||||
use the userData parameter to pass any client context necessary (a context pointer or wrapper object perhaps).
|
||||
Leave un-set or set the report callback to NULL to revert to EPANET's default behavior.
|
||||
**/
|
||||
int DLLEXPORT EN_setReportCallback(EN_Project ph, void (*callback)(void *userData, void *EN_projectHandle, char*));
|
||||
int DLLEXPORT EN_setReportCallbackUserData(EN_Project ph, void *userData);
|
||||
|
||||
/**
|
||||
@brief Writes a line of text to a project's report file.
|
||||
@param ph an EPANET project handle.
|
||||
|
||||
13
src/epanet.c
13
src/epanet.c
@@ -841,6 +841,19 @@ int DLLEXPORT EN_closeQ(EN_Project p)
|
||||
|
||||
********************************************************************/
|
||||
|
||||
|
||||
int DLLEXPORT EN_setReportCallback(EN_Project p, void (*callback)(void*,void*,char*))
|
||||
{
|
||||
p->report.reportCallback = callback;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DLLEXPORT EN_setReportCallbackUserData(EN_Project p, void *userData)
|
||||
{
|
||||
p->report.reportCallbackUserData = userData;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DLLEXPORT EN_writeline(EN_Project p, char *line)
|
||||
/*----------------------------------------------------------------
|
||||
** Input: line = line of text
|
||||
|
||||
@@ -281,6 +281,8 @@ void initpointers(Project *pr)
|
||||
pr->hydraul.smatrix.NZSUB = NULL;
|
||||
pr->hydraul.smatrix.LNZ = NULL;
|
||||
|
||||
pr->report.reportCallback = NULL;
|
||||
|
||||
initrules(pr);
|
||||
}
|
||||
|
||||
|
||||
@@ -885,6 +885,12 @@ void writeline(Project *pr, char *s)
|
||||
**--------------------------------------------------------------
|
||||
*/
|
||||
{
|
||||
if (pr->report.reportCallback != NULL)
|
||||
{
|
||||
pr->report.reportCallback(pr->report.reportCallbackUserData, pr, s);
|
||||
return;
|
||||
}
|
||||
|
||||
Report *rpt = &pr->report;
|
||||
|
||||
if (rpt->RptFile == NULL) return;
|
||||
|
||||
@@ -631,6 +631,9 @@ typedef struct {
|
||||
|
||||
SField Field[MAXVAR]; // Output reporting fields
|
||||
|
||||
void (*reportCallback)(void*,void*,char*); // user-supplied reporting callback
|
||||
void *reportCallbackUserData; // user-supplied reporting context
|
||||
|
||||
} Report;
|
||||
|
||||
// Output File Wrapper
|
||||
|
||||
Reference in New Issue
Block a user