00001
00002
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <libicl.h>
00006 #include <liboaa.h>
00007
00008 #define AGENT_NAME "AddClient_C"
00009
00010 int setup_oaa_connection(int argc, char *argv[]);
00011
00012 int main(int argc, char *argv[]) {
00013 int solve_success = 0;
00014 ICLTerm *Addend1 = NULL;
00015 ICLTerm *Addend2 = NULL;
00016 ICLTerm *Sum = NULL;
00017 ICLTerm *goal = NULL;
00018 ICLTerm *in_params = NULL;
00019 ICLTerm *out_params = NULL;
00020 ICLTerm *solutions = NULL;
00021
00022
00023
00024
00025
00026 if (argc != 3) {
00027 printf("Please supply exactly two integer arguments to add on the command line.\n");
00028 return EXIT_FAILURE;
00029 }
00030
00031
00032 oaa_Init(argc, argv);
00033
00034
00035
00036 if (!setup_oaa_connection(argc, argv)) {
00037 printf("Could not setup OAA connections...exiting.\n");
00038 return EXIT_FAILURE;
00039 }
00040
00041
00042
00043 Addend1 = icl_NewTermFromData(argv[1], strlen(argv[1]));
00044
00045
00046 Addend2 = icl_NewTermFromData(argv[2], strlen(argv[2]));
00047
00048
00049
00050 Sum = icl_NewVar("Sum");
00051
00052
00053
00054
00055
00056 goal = icl_NewStruct("add", 3, Addend1, Addend2, Sum);
00057
00058
00059 in_params = icl_NewList(NULL);
00060
00061
00062
00063
00064
00065
00066
00067
00068 solve_success = oaa_Solve(goal, in_params, &out_params, &solutions);
00069
00070
00071
00072 if (solve_success) {
00073 int addend1 = icl_Int(Addend1);
00074 int addend2 = icl_Int(Addend2);
00075
00076
00077 ICLTerm *solution = icl_NthTerm(solutions, 1);
00078 ICLTerm *SolvedSum = icl_NthTerm(solution, 3);
00079 int sum = icl_Int(SolvedSum);
00080
00081 printf("\nThe sum of %d and %d is %d.\n\n", addend1, addend2, sum);
00082 }
00083 else {
00084 printf("\nThere was an OAA failure; no solution found.\n\n");
00085 }
00086
00087
00088 icl_Free(goal);
00089 icl_Free(in_params);
00090 icl_Free(out_params);
00091 icl_Free(solutions);
00092
00093
00094 oaa_Disconnect(NULL, NULL);
00095 return EXIT_SUCCESS;
00096 }
00097
00105 int setup_oaa_connection(int argc, char *argv[]) {
00106 ICLTerm* mySolvablesAsTerm = NULL;
00107
00108
00109 if (!oaa_SetupCommunication(AGENT_NAME)) {
00110 printf("Could not connect\n");
00111 return FALSE;
00112 }
00113
00114
00115
00116
00117
00118 mySolvablesAsTerm = icl_NewList(NULL);
00119 if (!oaa_Register("parent", AGENT_NAME, mySolvablesAsTerm)) {
00120 printf("Could not register\n");
00121 return FALSE;
00122 }
00123
00124
00125 icl_Free(mySolvablesAsTerm);
00126
00127
00128 oaa_Ready(TRUE);
00129
00130 return TRUE;
00131 }
00132
00133