int aslFindValidNetworkBinding( AsNetworkAddress n, AsMediaAddress m, AsTime t ) { // Check if the logic layer is disabled if (aslDisableLogicFlag == 1) return 0; // Local variables int i; int sol_num = 0; PlTerm arg[10]; char *sol[GPC_MAX_SOLUTION_NUM]; PlBool res; // Start processing, if needed if ( ! aslogic_initialized ) aslInitLogic(); // Do the GPC query Pl_Query_Begin(PL_TRUE); arg[0] = Pl_Mk_Variable(); arg[1] = Pl_Mk_String(m); arg[2] = Pl_Mk_Integer(t); res = Pl_Query_Call(gpc_func_valid_binding_num, 3, arg); while (res) { sol[sol_num++] = Pl_Rd_String(arg[0]); res = Pl_Query_Next_Solution(); if (sol_num >= GPC_MAX_SOLUTION_NUM) { asLogMessage("Error: aslFindValidNetworkBinding got more than [%d] solutions - searching stopped", GPC_MAX_SOLUTION_NUM); break; } } Pl_Query_End(PL_KEEP_FOR_PROLOG); // Parse out the solutions asLogMessage("Info: aslFindValidNetworkBinding got [%d] solutions in total", sol_num); for (i = 0; i < sol_num; i++) { // Copy and remove trailing space strncpy( n, sol[i], MAX_NETADDR_LENGTH ); asLogMessage( "Find valid network binding successfully (%s,%lu)->[%s]", m, t, n ); // Return we found it - currently is the first solution we have found return( 1 ); } // Return successfully return( 0 ); }
/*-------------------------------------------------------------------------* * MAIN * * * * See comments in EnginePl/main.c about the use of the wrapper function. * *-------------------------------------------------------------------------*/ static int Main_Wrapper(int argc, char *argv[]) { int func; PlTerm arg[10]; char str[100]; char *sol[100]; int i, nb_sol = 0; PlBool res; Pl_Start_Prolog(argc, argv); func = Pl_Find_Atom("anc"); for (;;) { printf("\nEnter a name (or 'end' to finish): "); fflush(stdout); if (scanf("%s", str)) /* avoid gcc warning warn_unused_result */ ; if (strcmp(str, "end") == 0) break; Pl_Query_Begin(PL_TRUE); arg[0] = Pl_Mk_Variable(); arg[1] = Pl_Mk_String(str); nb_sol = 0; res = Pl_Query_Call(func, 2, arg); while (res) { sol[nb_sol++] = Pl_Rd_String(arg[0]); res = Pl_Query_Next_Solution(); } Pl_Query_End(PL_RECOVER); for (i = 0; i < nb_sol; i++) printf(" solution: %s\n", sol[i]); printf("%d solution(s)\n", nb_sol); } Pl_Stop_Prolog(); return 0; }