#include <stdio.h> 
#include <epp/epp.h>

/* Async call example using EPP API */

int callback(int retval, void *userdata) {
    static unsigned int call = 1;
    long *i = (long*) userdata;
    

    if (retval == PL_TRUE) {
	printf("<CALL %u> TRUE:\t %li\n", call++, *i);
    } else if (retval == PL_FALSE) {
	printf("<CALL %u> FALSE\n", call++);
    } else {
	printf("<CALL %u> ERROR\n", call++);
    }

    return(EPP_NEXT_SOLUTION);
}

int main(int argc, char *argv[]) {
    long i;

    /* Initialise Prolog */
    pl_init_from_state(*argv);

    /* EPP: Make a call */
    epp_acall(callback, &i, 0, "counter", "I", &i);
    
    /* EPP: Process Events */
    EPP_Process(-1, 0, 0, EPP_NO_BLOCK);

    /* Shutdown Prolog */
    pl_shutdown();
    return(0);
}
