comm_encode.c

Go to the documentation of this file.
00001 
00012 /* $Id: comm_encode.c,v 1.77 2008/12/11 02:06:24 tbrady Exp $ */
00013 /* $UTK_Copyright: $ */
00014 
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 
00019 #include "comm_encode.h"
00020 #include "comm_data.h"
00021 #include "utility.h"
00022 
00035 int
00036 gs_encode_cancel_notification(char **msg,
00037   char *server_cid, char *request_id, int agent_taskid)
00038 { 
00039   if(!server_cid || !request_id) {
00040     *msg = NULL;
00041     return -1;
00042   }
00043 
00044   *msg = dstring_sprintf("%s %s %d", server_cid, request_id, agent_taskid);
00045 
00046   return 0;
00047 }
00048 
00062 int
00063 gs_decode_cancel_notification(char *msg,
00064   char **server_cid, char **request_id, int *agent_taskid)
00065 {
00066   if(!msg)
00067     return -1;
00068 
00069   sscanf(msg, "%s %s %d", *server_cid, *request_id, agent_taskid);
00070   return 0;
00071 }
00072 
00085 int
00086 gs_encode_failure_notification(char **msg,
00087   char *server_cid, char *request_id, int agent_taskid)
00088 { 
00089   if(!server_cid || !request_id) {
00090     *msg = NULL;
00091     return -1;
00092   }
00093 
00094   *msg = dstring_sprintf("%s %s %d", server_cid, request_id, agent_taskid);
00095 
00096   return 0;
00097 }
00098 
00112 int
00113 gs_decode_failure_notification(char *msg,
00114   char **server_cid, char **request_id, int *agent_taskid)
00115 {
00116   if(!msg)
00117     return -1;
00118 
00119   sscanf(msg, "%s %s %d", *server_cid, *request_id, agent_taskid);
00120   return 0;
00121 }
00122 
00136 int
00137 gs_encode_problem_complete_notification(char **msg,
00138   char *server_cid, char *request_id, int agent_taskid, double run_time)
00139 { 
00140   if(!server_cid || !request_id) {
00141     *msg = NULL;
00142     return -1;
00143   }
00144 
00145   *msg = dstring_sprintf("%s %s %d %lf", server_cid, request_id, agent_taskid,
00146      run_time);
00147 
00148   return 0;
00149 }
00150 
00165 int
00166 gs_decode_problem_complete_notification(char *msg,
00167   char **server_cid, char **request_id, int *agent_taskid, double *run_time)
00168 {
00169   if(!msg)
00170     return -1;
00171 
00172   sscanf(msg, "%s %s %d %lf", *server_cid, *request_id, agent_taskid, run_time);
00173   return 0;
00174 }
00175 
00194 int
00195 gs_encode_problem_solve_notification(char **msg, char *problem_name, 
00196   double est_time, char *server_cid, char *user_name,
00197   char *host_name, char *client_cid, char *request_id, int agent_taskid,
00198   double agent_est_time)
00199 {
00200   if(!problem_name) {
00201     *msg = NULL;
00202     return -1;
00203   }
00204 
00205   *msg = dstring_sprintf("%s %lf %s %s %s %s %s %d %lf", problem_name, est_time,
00206      server_cid, user_name, host_name, client_cid, request_id, agent_taskid,
00207      agent_est_time);
00208 
00209   return 0;
00210 }
00211 
00232 int
00233 gs_decode_problem_solve_notification(char *msg, char **problem_name,
00234   double *est_time, char **server_cid, char **user_name,
00235   char **host_name, char **client_cid, char **request_id, int *agent_taskid,
00236   double *agent_est_time)
00237 {
00238   if(!msg)
00239     return -1;
00240 
00241   *problem_name = CALLOC(strlen(msg), sizeof(char));
00242   *server_cid = CALLOC(strlen(msg), sizeof(char));
00243   *user_name = CALLOC(strlen(msg), sizeof(char));
00244   *host_name = CALLOC(strlen(msg), sizeof(char));
00245   *client_cid = CALLOC(strlen(msg), sizeof(char));
00246   *request_id = CALLOC(strlen(msg), sizeof(char));
00247 
00248   sscanf(msg, "%s %lf %s %s %s %s %s %d %lf", *problem_name, est_time, *server_cid,
00249     *user_name, *host_name, *client_cid, *request_id, agent_taskid, agent_est_time);
00250 
00251   return 0;
00252 }
00253 
00271 int 
00272 gs_encode_problem_solve_request(char **msg, char *problem_name, 
00273   char *user_name, char *host_name, char *domain_name, char *client_cid, 
00274   int dsig, int agent_taskid, double agent_est_time)
00275 {
00276   if(!problem_name) {
00277     *msg = NULL;
00278     return -1;
00279   }
00280    
00281   *msg = dstring_sprintf("%s %s %s.%s %s %d %d %lf ", problem_name, user_name,
00282      host_name, domain_name, client_cid, dsig, agent_taskid, agent_est_time);
00283   
00284   return 0;
00285 }
00286 
00307 int 
00308 gs_decode_problem_solve_request(char *msg, char **problem_name, 
00309   char **user_name, char **full_host_name, char **client_cid, int *dsig,
00310   int *agent_taskid, double *agent_est_time)
00311 {
00312   if(!msg)
00313     return -1;
00314 
00315   sscanf(msg, "%s %s %s %s %d %d %lf", *problem_name, *user_name, *full_host_name, 
00316     *client_cid, dsig, agent_taskid, agent_est_time);
00317   return 0;
00318 }
00319 
00345 int
00346 gs_decode_problem_submit_request(char *msg, char **problem_name, int *dsig, char **criteria)
00347 {
00348   int nchars;
00349   
00350   if(!msg)
00351     return -1;
00352     
00353   /* since the message consists of only the problem name, we
00354    * just dup it and return.
00355    */
00356   *problem_name = (char *)CALLOC(strlen(msg), sizeof(char));
00357   sscanf(msg, "%s %d %n", *problem_name, dsig, &nchars);
00358   
00359   if(msg[nchars] != 0) {
00360     *criteria = strdup(msg + nchars);
00361     
00362     if(!*criteria) {
00363       printf("failed to alloc criteria\n");
00364       return -1;
00365     }
00366   } 
00367   else
00368     *criteria = NULL;
00369 
00370   return 0;
00371 }
00372 
00385 int 
00386 gs_encode_problem_submit_request(char **msg, char *problem_name, int dsig, char *criteria)
00387 {
00388   if(!problem_name) 
00389     return -1;
00390 
00391   *msg = dstring_sprintf("%s %d %s", problem_name, dsig, criteria ? criteria : "");
00392 
00393   return 0;
00394 }
00395 
00409 int 
00410 gs_encode_problem_submit_response(char **msg, char **server_list, int num_servers)
00411 {
00412   int i;
00413 
00414   if(!server_list) 
00415     return -1;
00416 
00417   *msg = dstring_sprintf("%d ", num_servers);
00418 
00419   for(i=0;i<num_servers;i++) {
00420 
00421     *msg = dstring_append(*msg, server_list[i]);
00422     *msg = dstring_append(*msg, " ");
00423   }
00424 
00425   return 0;
00426 }
00427 
00440 int 
00441 gs_decode_problem_submit_response(char *msg, char ***server_list, int *num_servers)
00442 {
00443   int i;
00444 
00445   if(!msg) 
00446     return -1;
00447 
00448   *num_servers = atoi(strtok(msg, " "));
00449 
00450   *server_list = (char **)CALLOC(*num_servers, sizeof(char *));
00451 
00452   if(!*server_list) {
00453     ERRPRINTF("decodeProblemSubmitResponse: malloc failed\n");
00454     return -1;
00455   }
00456 
00457   for(i=0;i<*num_servers;i++) 
00458     (*server_list)[i] = strdup(strtok(NULL," " ));
00459 
00460   return 0;
00461 }
00462 
00463 int
00464 gs_decode_model_update(char *strp, char **name, char **expr)
00465 {
00466   int maxlen;
00467   
00468   maxlen = strlen(strp);
00469   
00470   *name = (char *)calloc(maxlen, sizeof(char));
00471   if(!*name) return -1;
00472   
00473   *expr = (char *)calloc(maxlen, sizeof(char));
00474   if(!*expr) return -1;
00475   
00476   sscanf(strp, "<model_update prob_name=\"%[^\"]\" expr=\"%[^\"]\"/>\n",
00477           *name, *expr);
00478 
00479   return 0;
00480 }
00481 
00482 int
00483 gs_encode_model_update(char **s, char *name, char *expr)
00484 {
00485   *s = dstring_sprintf("<model_update prob_name=\"%s\" expr=\"%s\"/>\n",
00486           name, expr);
00487 
00488   return *s ? 0 : -1;
00489 }
00490 
00500 int 
00501 gs_encode_infolist(char **s, gs_info_t *list)
00502 {
00503   int count = 0;
00504   char *stmp = NULL;
00505   gs_info_t* info = NULL;
00506 
00507   for (count=0,info=list; info!=NULL; info=info->next) 
00508     count++;
00509 
00510   stmp = dstring_sprintf(" <infolist count=\"%d\">\n", count);
00511   *s = dstring_append_free(*s, stmp);
00512 
00513 
00514   for (info=list; info!=NULL; info=info->next) {
00515     stmp = dstring_sprintf("  <info type=\"%s\" value=\"%s\" />\n", info->type, info->value);
00516     *s = dstring_append_free(*s, stmp);
00517   }
00518   stmp = dstring_sprintf(" </infolist>\n");
00519 
00520   *s = dstring_append_free(*s, stmp);
00521 
00522   return 0;
00523 }
00524 
00535 int 
00536 gs_decode_infolist(char *strp, gs_info_t **list)
00537 {
00538   int n, nchars, count, idx, maxlen;
00539   gs_info_t *info, *ip;
00540 
00541   maxlen = strlen(strp);
00542 
00543   n = sscanf(strp, " <infolist count=\"%d\">\n %n", &count, &nchars);
00544   strp = strp+nchars;   /* move past processed chars */
00545 
00546   for (nchars=0, idx=0; idx<count; idx++) {
00547     info = (gs_info_t*)CALLOC(1, sizeof(gs_info_t));
00548     if(!info) return -1;
00549 
00550     info->next = NULL;
00551 
00552     info->type = (char *)CALLOC(maxlen, sizeof(char));
00553     if(!info->type) return -1;
00554 
00555     info->value = (char *)CALLOC(maxlen, sizeof(char));
00556     if(!info->value) return -1;
00557 
00558     n = sscanf(strp, "  <info type=\"%[^\"]\" value=\"%[^\"]\" />\n %n", 
00559           info->type, info->value, &nchars);
00560 
00561     strp = strp+nchars; /* move past processed chars */
00562     info->type = REALLOC(info->type, strlen(info->type)+1);
00563     info->value = REALLOC(info->value, strlen(info->value)+1);
00564 
00565     if(!info->type || !info->value) return -1;
00566 
00567     if (*list == NULL)
00568       *list = info;
00569     else {
00570       for (ip=*list; ip->next!=NULL; ip=ip->next) {}
00571       ip->next = info;
00572     }
00573   }
00574   n = sscanf(strp, " </infolist>\n %n", &nchars);
00575   strp = strp+nchars;   /* move past processed chars */
00576 
00577   return 0;
00578 }
00579 
00590 int
00591 gs_encode_smart_info(char **encoding, gs_server_t *server, gs_server_t **server_list, double *times, int count){
00592 
00593   char componentid_string[CID_LEN*2+1];
00594   char *stmp = NULL;
00595   int i;    
00596   gs_server_t **s = server_list;   /* just a shortcut name */
00597   *encoding = dstring_sprintf("<smart_info>\n");
00598   stmp = dstring_sprintf("<count> %d </count>\n", count);
00599   *encoding = dstring_append_free(*encoding , stmp);
00600 
00601   for(i=0;i<count;i++){
00602     if(!s[i]){
00603       return -1;
00604     }
00605     proxy_cid_to_str(componentid_string, s[i]->componentid);
00606     stmp = dstring_sprintf("<componentid> %s </componentid>  <time> %f </time> \n", componentid_string, times[i]);
00607     *encoding = dstring_append_free(*encoding, stmp);
00608   }
00609    stmp = dstring_sprintf("</smart_info>");
00610    *encoding = dstring_append_free(*encoding, stmp);
00611   return 0;
00612 }
00613 
00614 int
00615 gs_decode_smart_info(char *encoding, gs_server_pings_t ***pings, int *np)
00616 {
00617   int i, n, count, maxlen, nchars;
00618   gs_server_pings_t **parr;
00619   char *strp, *cid_tmp;
00620 
00621   *np = 0;
00622   *pings = NULL;
00623 
00624   strp = encoding;
00625   maxlen = strlen(strp);
00626 
00627   cid_tmp = (char *)calloc(maxlen, sizeof(char));
00628   if(!cid_tmp) return -1;
00629 
00630   n = sscanf(strp, "<smart_info>\n %n", &nchars);
00631   strp = strp+nchars;
00632 
00633   n = sscanf(strp, "<count> %d </count>\n %n", &count, &nchars);
00634   strp = strp+nchars;
00635 
00636   parr = (gs_server_pings_t **) malloc(count * sizeof(gs_server_pings_t *));
00637   if(!parr) {
00638     free(cid_tmp);
00639     return -1;
00640   }
00641 
00642   for(i=0;i<count;i++) {
00643     parr[i] = (gs_server_pings_t *) malloc(sizeof(gs_server_pings_t));
00644     if(!parr[i]) {
00645       /* probably need to free parr[1 through i-1] too */
00646       free(parr);
00647       free(cid_tmp);
00648       return -1;
00649     }
00650 
00651     n = sscanf(strp, "<componentid> %s </componentid>  <time> %lg </time>\n %n",
00652           cid_tmp, &(parr[i]->comm_time), &nchars);
00653     strp = strp+nchars;
00654     proxy_str_to_cid(parr[i]->componentid, cid_tmp);
00655   }
00656 
00657   n = sscanf(strp, "</smart_info>\n %n", &nchars);
00658   strp = strp+nchars;
00659 
00660   *np = count;
00661   *pings = parr;
00662 
00663   return 0;
00664 }
00665 
00676 int 
00677 gs_encode_server(char **encoding, gs_server_t *gs_server) 
00678 {
00679   gs_server_t *s = gs_server;   /* just a shortcut name */
00680   char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
00681     proxy_dottedIP[20];
00682 
00683   if(!gs_server)
00684     return -1;
00685 
00686   proxy_cid_to_str(componentid_string, s->componentid);
00687   proxy_ip_to_str(s->ipaddress, server_dottedIP);
00688   proxy_ip_to_str(s->proxyip, proxy_dottedIP);
00689 
00690   *encoding = dstring_sprintf("<server> <hostname> %s </hostname> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> <arch> %s </arch> <data_format> %d </data_format> <kflops> %d </kflops> <workload> %d </workload> <ncpu> %d </ncpu> <status> %d </status> <availcpu> %lg </availcpu> <availmem> %lg </availmem> <nproblems> %d </nproblems> <agenthost> %s </agenthost> <agentport> %d </agentport> <score> %g </score> <smart> %d </smart> </server>\n", s->hostname, server_dottedIP, s->port, proxy_dottedIP, s->proxyport, componentid_string, s->arch, s->data_format, s->kflops, s->workload, s->ncpu, s->status, s->availcpu, s->availmem, s->nproblems, s->agenthost, s->agentport, s->score, s->smart);
00691 
00692   if(gs_encode_infolist(encoding,s->sa_list) < 0)
00693     return -1;
00694  /* 
00695 #ifdef GS_SMART_GRIDSOLVE
00696    *encoding = dstring_sprintf("<smart_info>");
00697    int i =0;
00698    int numSmartServers;
00699    for (i=0; i<numSmartServers; i++) {
00700      *encoding = dstring_sprintf("<componentid> %s </componentid>  <time> %f </time> \n", server[i]->comp_id, server[i]->time);
00701    }
00702   *encoding = dstring_sprintf("</smart_info>");
00703 #endif
00704   */
00705 
00706   DBGPRINTF("server strlen %d encoding %s\n", (int)(strlen(*encoding)), *encoding);
00707   return 0;
00708 }
00709 
00720 int 
00721 gs_decode_server(char *encoding, gs_server_t *gs_server)
00722 {
00723   int rv = -1, nchars;
00724   gs_server_t *s = gs_server;  
00725   char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
00726     proxy_dottedIP[20];
00727 
00728   if(!encoding)
00729     return -1;
00730 
00731   s->hostname = (char *)CALLOC(strlen(encoding)+1, sizeof(char));
00732   s->arch = (char *)CALLOC(strlen(encoding)+1, sizeof(char));
00733   s->agenthost = (char *)CALLOC(strlen(encoding)+1, sizeof(char));
00734 
00735   if(!s->hostname || !s->arch || !s->agenthost) {
00736     if(s->hostname) free(s->hostname);
00737     if(s->arch) free(s->arch);
00738     if(s->agenthost) free(s->agenthost);
00739     return -1;
00740   }
00741 
00742   rv = sscanf(encoding, "<server> <hostname> %s </hostname> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> <arch> %s </arch> <data_format> %d </data_format> <kflops> %d </kflops> <workload> %d </workload> <ncpu> %d </ncpu> <status> %d </status> <availcpu> %lg </availcpu> <availmem> %lg </availmem> <nproblems> %d </nproblems> <agenthost> %s </agenthost> <agentport> %d </agentport> <score> %lg </score> <smart> %d </smart> </server>\n %n", s->hostname, server_dottedIP, &s->port, proxy_dottedIP, &s->proxyport, componentid_string, s->arch, &s->data_format, &s->kflops, &s->workload, &s->ncpu, &s->status, &s->availcpu, &s->availmem, &s->nproblems, s->agenthost, &s->agentport, &s->score, &s->smart, &nchars);
00743 
00744   if (rv != 19) {
00745     ERRPRINTF("Server decoding '%s' failed with %d items decoded \n", 
00746       encoding, rv);
00747     FREE(s->hostname);
00748     FREE(s->arch);
00749     FREE(s->agenthost);
00750     return -1;
00751   }
00752 
00753   s->sa_list = NULL;
00754   
00755   encoding += nchars;
00756   gs_decode_infolist(encoding,&s->sa_list);
00757 
00758   s->hostname = REALLOC(s->hostname, strlen(s->hostname)+1);
00759   s->arch = REALLOC(s->arch, strlen(s->arch)+1);
00760   s->agenthost = REALLOC(s->agenthost, strlen(s->agenthost)+1);
00761 
00762   if(!s->hostname || !s->arch || !s->agenthost) {
00763     ERRPRINTF("Server decoding failed to realloc memory\n");
00764     FREE(s->hostname);
00765     FREE(s->arch);
00766     FREE(s->agenthost);
00767     return -1;
00768   }
00769 
00770   proxy_str_to_cid(s->componentid, componentid_string);
00771   proxy_str_to_ip(&s->ipaddress, server_dottedIP);
00772   proxy_str_to_ip(&s->proxyip, proxy_dottedIP);
00773 
00774   return 0;
00775 }
00776 
00786 int 
00787 gs_encode_availability_request(char **encoding, gs_server_t *gs_server) 
00788 {
00789   gs_server_t *s = gs_server;   /* just a shortcut name */
00790   char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
00791     proxy_dottedIP[20];
00792 
00793   if(!gs_server)
00794     return -1;
00795 
00796   proxy_cid_to_str(componentid_string, s->componentid);
00797   proxy_ip_to_str(s->ipaddress, server_dottedIP);
00798   proxy_ip_to_str(s->proxyip, proxy_dottedIP);
00799 
00800   *encoding = dstring_sprintf("<conn_test> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> </conn_test>\n", server_dottedIP, s->port, proxy_dottedIP, s->proxyport, componentid_string);
00801 
00802   return 0;
00803 }
00804 
00816 int 
00817 gs_decode_availability_request(char *encoding, gs_server_t *gs_server)
00818 {
00819   int rv = -1, nchars;
00820   gs_server_t *s = gs_server;  
00821   char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
00822     proxy_dottedIP[20];
00823 
00824   if(!encoding)
00825     return -1;
00826 
00827   rv = sscanf(encoding, "<conn_test> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> </conn_test>\n %n", server_dottedIP, &s->port, proxy_dottedIP, &s->proxyport, componentid_string, &nchars);
00828 
00829   if (rv != 5) {
00830     ERRPRINTF("Server decoding '%s' failed with %d items decoded \n", 
00831       encoding, rv);
00832     return -1;
00833   }
00834 
00835   s->sa_list = NULL;
00836   
00837   proxy_str_to_cid(s->componentid, componentid_string);
00838   proxy_str_to_ip(&s->ipaddress, server_dottedIP);
00839   proxy_str_to_ip(&s->proxyip, proxy_dottedIP);
00840 
00841   return 0;
00842 }
00843 
00855 int 
00856 gs_encode_workload_report(char **msg, int workload, int nproblems,
00857   char *server_cid)
00858 {
00859   if(!server_cid)
00860     return -1;
00861 
00862   *msg = dstring_sprintf("%d %d %s", workload, nproblems, server_cid);
00863 
00864   return 0;
00865 }
00866 
00877 int 
00878 gs_decode_workload_report(char *msg, int *workload, int *nproblems,
00879   char *server_cid)
00880 {
00881   if(!msg)
00882     return -1;
00883 
00884   sscanf(msg, "%d %d %s", workload, nproblems, server_cid);
00885 
00886   return 0;
00887 }
00888 
00901 int 
00902 gs_encode_problem(char **problemstring, gs_problem_t* problem) 
00903 {
00904   int count = 0, enum_count = 0;
00905   gs_argument_t *arg = NULL;
00906   gs_arg_enum_t *arg_enum = NULL;
00907   char *s = NULL;
00908   char *stmp = NULL;
00909   char *callsig;
00910 
00911   if(!problem)
00912     return -1;
00913   
00914   callsig = problem->callsig ? problem->callsig : GS_NO_CALL_SIG;
00915 
00916   s = dstring_sprintf("<problem name=\"%s\" type=\"%s\" description=\"%s\" major=\"%d\" callsig=\"%s\">\n", problem->name, gs_probtype[problem->type], problem->description, problem->major, callsig);
00917 
00918   for (count=0,arg=problem->arglist; arg!=NULL; arg=arg->next) 
00919     count++;
00920 
00921   stmp = dstring_sprintf(" <arglist count=\"%d\">\n", count);
00922   s = dstring_append_free(s,stmp);
00923 
00924   for (arg=problem->arglist; arg!=NULL; arg=arg->next) {
00925     for (enum_count=0,arg_enum=arg->arg_enum; arg_enum!=NULL; arg_enum=arg_enum->next) 
00926       enum_count++;
00927 
00928     stmp = dstring_sprintf("  <arg name=\"%s\" inout=\"%s\" datatype=\"%s\" objecttype=\"%s\" rowexp=\"%s\" colexp=\"%s\" nnzexp=\"%s\" indices=\"%s\" pointer=\"%s\" enum_count=\"%d\" description=\"%s\">\n", arg->name, gs_inout[arg->inout], gs_c_datatype[arg->datatype], gs_objecttype[arg->objecttype], arg->rowexp, arg->colexp, arg->sparse_attr.nnzexp, arg->sparse_attr.indices, arg->sparse_attr.pointer, enum_count, arg->description);
00929     s = dstring_append_free(s, stmp);
00930 
00931     if(enum_count > 0) {
00932       stmp = dstring_sprintf("    <arg_enum>\n");
00933       s = dstring_append_free(s, stmp);
00934 
00935       for(arg_enum=arg->arg_enum; arg_enum!=NULL; arg_enum=arg_enum->next) {
00936         stmp = dstring_sprintf("      <enum_val val=\"%s\"/>\n", arg_enum->val);
00937         s = dstring_append_free(s, stmp);
00938       }
00939 
00940       stmp = dstring_sprintf("    </arg_enum>\n");
00941       s = dstring_append_free(s, stmp);
00942     }
00943 
00944     stmp = dstring_sprintf("  </arg>\n");
00945     s = dstring_append_free(s, stmp);
00946   }
00947 
00948   stmp = dstring_sprintf(" </arglist>\n");
00949   s = dstring_append_free(s, stmp);
00950  
00951   if(gs_encode_infolist(&s, problem->infolist) <0)
00952     return -1;
00953 
00954   stmp = dstring_sprintf("</problem>");
00955   s = dstring_append_free(s, stmp);
00956 
00957   *problemstring = s;
00958   
00959   return 0;
00960 }
00961 
00975 int 
00976 gs_decode_problem(char *problemstring, gs_problem_t *problem)
00977 {
00978   int n, nchars, count, enum_count, idx, maxlen = strlen(problemstring)+1;
00979   char *strp = problemstring, *inout, *datatype, *objecttype, *ptype;
00980   gs_argument_t *arg, *ap;
00981  
00982   n = nchars = count = enum_count = idx = 0;
00983 
00984   problem->arglist = NULL;
00985   problem->next = NULL;
00986   problem->infolist = NULL;
00987   problem->work = NULL;
00988   problem->worksize = 0;
00989 
00990   ptype = CALLOC(maxlen, sizeof(char));
00991 
00992   problem->name = CALLOC(maxlen, sizeof(char));
00993   problem->description = CALLOC(maxlen, sizeof(char));
00994   problem->callsig = CALLOC(maxlen, sizeof(char));
00995   n = sscanf(strp, "<problem name=\"%[^\"]\" type=\"%[^\"]\" description=\"%[^\"]\" major=\"%d\" callsig=\"%[^\"]\">\n %n", problem->name, ptype, problem->description, &(problem->major), problem->callsig, &nchars);
00996   strp = strp+nchars;   /* move past processed chars */
00997   problem->name = REALLOC(problem->name, strlen(problem->name)+1);
00998   problem->description = REALLOC(problem->description, strlen(problem->description)+1);
00999 
01000   problem->type = gs_parse_probtype(ptype);
01001   free(ptype);
01002   if(problem->type == GS_BAD_PTYPE) {
01003     ERRPRINTF("bad problem type specified.\n");
01004     return -1;
01005   }
01006 
01007   n = sscanf(strp, " <arglist count=\"%d\">\n %n", &count, &nchars);
01008   strp = strp+nchars;   /* move past processed chars */
01009   
01010   inout = CALLOC(maxlen, sizeof(char));
01011   datatype = CALLOC(maxlen, sizeof(char));
01012   objecttype = CALLOC(maxlen, sizeof(char));
01013 
01014   for (nchars=0,idx=0; idx<count; idx++) {
01015     arg = (gs_argument_t*)CALLOC(1, sizeof(gs_argument_t));
01016     arg->data_handle = 0;
01017     arg->pass_back = 1;
01018     arg->next = NULL;
01019     arg->prob = problem;
01020     arg->name = CALLOC(maxlen, sizeof(char));
01021     arg->rowexp = CALLOC(maxlen, sizeof(char));
01022     arg->colexp = CALLOC(maxlen, sizeof(char));
01023     arg->sparse_attr.nnzexp = CALLOC(maxlen, sizeof(char));
01024     arg->sparse_attr.indices = CALLOC(maxlen, sizeof(char));
01025     arg->sparse_attr.pointer = CALLOC(maxlen, sizeof(char));
01026     arg->description = CALLOC(maxlen, sizeof(char));
01027     arg->arg_enum = NULL;
01028 
01029     n = sscanf(strp, "  <arg name=\"%[^\"]\" inout=\"%[^\"]\" datatype=\"%[^\"]\" objecttype=\"%[^\"]\" rowexp=\"%[^\"]\" colexp=\"%[^\"]\" nnzexp=\"%[^\"]\" indices=\"%[^\"]\" pointer=\"%[^\"]\" enum_count=\"%d\" description=\"%[^\"]\">\n %n", arg->name, inout, datatype, objecttype, arg->rowexp, arg->colexp, arg->sparse_attr.nnzexp, arg->sparse_attr.indices, arg->sparse_attr.pointer, &enum_count, arg->description, &nchars);
01030     strp = strp+nchars; /* move past processed chars */
01031 
01032     if(enum_count > 0) {
01033       gs_arg_enum_t *ap;
01034       char *enum_string;
01035       int i;
01036 
01037       enum_string = (char *)malloc(maxlen);
01038       if(!enum_string) {
01039         ERRPRINTF("malloc.\n");
01040         return -1;
01041       }
01042 
01043       n = sscanf(strp, "    <arg_enum>\n %n", &nchars);
01044       strp = strp+nchars;   /* move past processed chars */
01045 
01046       ap = (gs_arg_enum_t *) malloc(enum_count * sizeof(gs_arg_enum_t));
01047       if(!ap) {
01048         ERRPRINTF("malloc.\n");
01049         return -1;
01050       }
01051 
01052       /* i have allocated an array of gs_arg_enum_t, but i'm going to construct
01053        * it sort of like a linked list, linking ap[i].next to the address of
01054        * a[i+1].
01055        */
01056 
01057       for(i=0; i < enum_count; i++) {
01058         n = sscanf(strp, "      <enum_val val=\"%[^\"]\"/>\n %n", enum_string, &nchars);
01059         strp = strp+nchars; /* move past processed chars */
01060 
01061         ap[i].val = strdup(enum_string);
01062         if(!ap[i].val) {
01063           ERRPRINTF("malloc.\n");
01064           return -1;
01065         }
01066     
01067         ap[i].next = &ap[i+1];
01068       }
01069 
01070       ap[i-1].next = NULL;
01071       arg->arg_enum = ap;
01072 
01073       n = sscanf(strp, "    </arg_enum>\n %n", &nchars);
01074       strp = strp+nchars;   /* move past processed chars */
01075 
01076       free(enum_string);
01077     }
01078 
01079     n = sscanf(strp, " </arg>\n %n", &nchars);
01080     strp = strp+nchars; /* move past processed chars */
01081 
01082     arg->name = REALLOC(arg->name, strlen(arg->name)+1);
01083     
01084     arg->inout = gs_parse_inout(inout);
01085     if(arg->inout == GS_BAD_INOUT) {
01086       ERRPRINTF("bad in/out specified.\n");
01087       return -1;
01088     }
01089 
01090     arg->datatype = gs_parse_datatype(datatype);
01091     if(arg->datatype == GS_BAD_DTYPE) {
01092       ERRPRINTF("bad data type specified.\n");
01093       return -1;
01094     }
01095 
01096     arg->objecttype = gs_parse_objecttype(objecttype);
01097     if(arg->objecttype == GS_BAD_OTYPE) {
01098       ERRPRINTF("bad object type specified.\n");
01099       return -1;
01100     }
01101 
01102     arg->rowexp = REALLOC(arg->rowexp, strlen(arg->rowexp)+1);
01103     arg->colexp = REALLOC(arg->colexp, strlen(arg->colexp)+1);
01104     arg->sparse_attr.nnzexp = REALLOC(arg->sparse_attr.nnzexp, 
01105       strlen(arg->sparse_attr.nnzexp)+1);
01106     arg->sparse_attr.indices = REALLOC(arg->sparse_attr.indices, 
01107       strlen(arg->sparse_attr.indices)+1);
01108     arg->sparse_attr.pointer = REALLOC(arg->sparse_attr.pointer, 
01109       strlen(arg->sparse_attr.pointer)+1);
01110     arg->description = REALLOC(arg->description, strlen(arg->description)+1);
01111     if (problem->arglist == NULL) problem->arglist = arg;
01112     else {
01113       for (ap=problem->arglist; ap->next!=NULL; ap=ap->next) {}
01114       ap->next = arg;
01115     }
01116   }
01117 
01118   n = sscanf(strp, " </arglist>\n %n", &nchars);
01119   strp = strp+nchars;   /* move past processed chars */
01120 
01121   gs_decode_infolist(strp, &problem->infolist);
01122 
01123   n = sscanf(strp, " </problem>\n %n", &nchars);
01124   strp = strp+nchars;   /* move past processed chars */
01125   
01126   free(inout);
01127   free(datatype);
01128   free(objecttype);
01129 
01130   return 0;
01131 }
01132 
01146 int
01147 gs_decode_dsi_object(char *encoding, DSI_OBJECT *obj)
01148 {
01149   int nchars;
01150   char *tmp;
01151 
01152   if(!obj) return -1;
01153 
01154   tmp = (char *)malloc(strlen(encoding)+1);
01155 
01156   if(!tmp) return -1;
01157 
01158   obj->dsi_file = (DSI_FILE *)malloc(sizeof(DSI_FILE));
01159 
01160   if(!obj->dsi_file) {
01161     free(tmp);
01162     return -1;
01163   }
01164 
01165   if(sscanf(encoding, "<dsi_object> <flag> %d </flag>\n%n", 
01166        &(obj->dsi_file->flag), &nchars) != 1)
01167     goto scan_error;
01168   encoding += nchars;
01169 
01170   if(sscanf(encoding, "<perm> %d </perm>\n%n", 
01171        &(obj->dsi_file->perm), &nchars) != 1)
01172     goto scan_error;
01173   encoding += nchars;
01174 
01175   if(sscanf(encoding, "<uid> %d </uid>\n%n", 
01176        &(obj->dsi_file->uid), &nchars) != 1)
01177     goto scan_error;
01178   encoding += nchars;
01179 
01180   if(sscanf(encoding, "<written_count> %d </written_count>\n%n",
01181        &(obj->dsi_file->written_count), &nchars) != 1)
01182     goto scan_error;
01183   encoding += nchars;
01184 
01185   if(sscanf(encoding, "<offset> %d </offset>\n%n", 
01186        &(obj->offset), &nchars) != 1)
01187     goto scan_error;
01188   encoding += nchars;
01189 
01190   if(sscanf(encoding, "<storage_system> %d </storage_system>\n%n",
01191        &(obj->dsi_file->storage_system), &nchars) != 1)
01192     goto scan_error;
01193   encoding += nchars;
01194 
01195   if(obj->dsi_file->storage_system == GS_DSI_IBP) {
01196 #ifdef DSI_IBP
01197     obj->dsi_file->dsi_specifics.ibp.depot = 
01198            (IBP_depot)malloc(sizeof(struct ibp_depot));
01199 
01200     if(!obj->dsi_file->dsi_specifics.ibp.depot) {
01201       free(tmp);
01202       if(obj->dsi_file) free(obj->dsi_file);
01203       return -1;
01204     }
01205       
01206     obj->dsi_file->dsi_specifics.ibp.cap = 
01207            (IBP_set_of_caps)malloc(sizeof(struct ibp_set_of_caps));
01208 
01209     if(!obj->dsi_file->dsi_specifics.ibp.cap) {
01210       free(tmp);
01211       if(obj->dsi_file) 
01212         free(obj->dsi_file);
01213       if(obj->dsi_file->dsi_specifics.ibp.depot)
01214         free(obj->dsi_file->dsi_specifics.ibp.depot);
01215       return -1;
01216     }
01217       
01218     if(sscanf(encoding, "<host> %s </host>\n%n", 
01219       obj->dsi_file->dsi_specifics.ibp.depot->host, &nchars) != 1)
01220       goto scan_error;
01221     encoding += nchars;
01222 
01223     if(sscanf(encoding, "<port> %d </port>\n%n",
01224       &(obj->dsi_file->dsi_specifics.ibp.depot->port), &nchars) != 1)
01225       goto scan_error;
01226     encoding += nchars;
01227 
01228     if(sscanf(encoding, "<readcap> %s </readcap>\n%n", tmp, &nchars) != 1)
01229       goto scan_error;
01230     obj->dsi_file->dsi_specifics.ibp.cap->readCap = strdup(tmp);
01231     encoding += nchars;
01232 
01233     if(sscanf(encoding, "<writecap> %s </writecap>\n%n", tmp, &nchars) != 1)
01234       goto scan_error;
01235     obj->dsi_file->dsi_specifics.ibp.cap->writeCap = strdup(tmp);
01236     encoding += nchars;
01237 
01238     if(sscanf(encoding, "<managecap> %s </managecap>\n%n", tmp, &nchars) != 1)
01239       goto scan_error;
01240     obj->dsi_file->dsi_specifics.ibp.cap->manageCap = strdup(tmp);
01241 #endif
01242   }
01243 
01244   free(tmp);
01245 
01246   return 0;
01247 
01248 scan_error:
01249   free(tmp);
01250   return -1;
01251 }
01252 
01265 int
01266 gs_encode_dsi_object(char **msg, DSI_OBJECT *obj)
01267 {
01268   char *tmp;
01269 
01270   *msg = dstring_sprintf("<dsi_object>\n");
01271 
01272   tmp = dstring_sprintf("  <flag> %d </flag>\n", obj->dsi_file->flag);
01273   *msg = dstring_append_free(*msg, tmp);
01274   tmp = dstring_sprintf("  <perm> %d </perm>\n", obj->dsi_file->perm);
01275   *msg = dstring_append_free(*msg, tmp);
01276   tmp = dstring_sprintf("  <uid> %d </uid>\n", obj->dsi_file->uid);
01277   *msg = dstring_append_free(*msg, tmp);
01278   tmp = dstring_sprintf("  <written_count> %d </written_count>\n", 
01279       obj->dsi_file->written_count);
01280   *msg = dstring_append_free(*msg, tmp);
01281   tmp = dstring_sprintf("  <offset> %d </offset>\n", obj->offset);
01282   *msg = dstring_append_free(*msg, tmp);
01283   tmp = dstring_sprintf("  <storage_system> %d </storage_system>\n", 
01284       obj->dsi_file->storage_system);
01285   *msg = dstring_append_free(*msg, tmp);
01286 
01287   if(obj->dsi_file->storage_system == GS_DSI_IBP) {
01288 #ifdef DSI_IBP
01289     tmp = dstring_sprintf("  <host> %s </host>\n", 
01290        obj->dsi_file->dsi_specifics.ibp.depot->host);
01291     *msg = dstring_append_free(*msg, tmp);
01292     tmp = dstring_sprintf("  <port> %d </port>\n", 
01293        obj->dsi_file->dsi_specifics.ibp.depot->port);
01294     *msg = dstring_append_free(*msg, tmp);
01295     tmp = dstring_sprintf("  <readcap> %s </readcap>\n", 
01296        obj->dsi_file->dsi_specifics.ibp.cap->readCap);
01297     *msg = dstring_append_free(*msg, tmp);
01298     tmp = dstring_sprintf("  <writecap> %s </writecap>\n", 
01299        obj->dsi_file->dsi_specifics.ibp.cap->writeCap);
01300     *msg = dstring_append_free(*msg, tmp);
01301     tmp = dstring_sprintf("  <managecap> %s </managecap>\n", 
01302        obj->dsi_file->dsi_specifics.ibp.cap->manageCap);
01303     *msg = dstring_append_free(*msg, tmp);
01304 #endif
01305   }
01306 
01307   tmp = dstring_sprintf("</dsi_object>\n");
01308   *msg = dstring_append_free(*msg, tmp);
01309 
01310   return 0;
01311 }
01312 
01313 
01314 
01315 
01316 #ifdef GS_SMART_GRIDSOLVE
01317 
01329 int
01330 gs_smart_encode_tg_rem_task_node(char **rem_task_node_str, gs_smart_tg_task_node * tg_task_node){
01331   gs_smart_tg_dep_link ** tg_node_frwrd_link;
01332   gs_smart_tg_dep_link ** tg_node_bkwrd_link;
01333   gs_smart_tg_obj_node * obj_node_ptr; 
01334   gs_smart_tg_remote_task_node * tg_rem_task_node;
01335   int i ;
01336   int nb_obj_frwd_links, nb_node_frwd_links, nb_node_bkwd_links;
01337   char *s = NULL;
01338   char *stmp = NULL;
01339 
01340   if((!tg_task_node) || (!tg_task_node->tg_rem_task_node)) return -1;  
01341   tg_rem_task_node=tg_task_node->tg_rem_task_node;
01342 
01343   s = dstring_sprintf("<begin_remote_task>");
01344   
01345 
01346   stmp = dstring_sprintf("<blocking=\"%d\">\n", tg_rem_task_node->blocking);
01347   s = dstring_append_free(s,stmp);
01348   stmp = dstring_sprintf("<nb_flops=\"%f\">\n", tg_rem_task_node->nb_flops);
01349   s = dstring_append_free(s,stmp);
01350   stmp = dstring_sprintf("<nb_servers=\"%d\">\n", tg_rem_task_node->nb_servers);
01351   s = dstring_append_free(s,stmp);
01352   
01353   stmp = dstring_sprintf("<nb_node_frwd_links=\"%d\">\n", 
01354                           tg_rem_task_node->nb_node_frwd_links);
01355   s = dstring_append_free(s,stmp);
01356 
01357   stmp = dstring_sprintf("<nb_node_bkwd_links=\"%d\">\n", 
01358                            tg_rem_task_node->nb_node_bkwd_links);
01359   s = dstring_append_free(s,stmp);
01360   
01361   nb_node_frwd_links=tg_rem_task_node->nb_node_frwd_links;
01362   nb_node_bkwd_links=tg_rem_task_node->nb_node_bkwd_links;
01363 
01364   if(((!tg_rem_task_node->tg_node_frwrd_link) &&  (nb_node_frwd_links>0)) || 
01365      ((!tg_rem_task_node->tg_node_bkwrd_link) &&  (nb_node_bkwd_links>0))){
01366      ERRPRINTF("SMART: Error remote task forward back links is NULL..\n");
01367      return -1;
01368    }
01369   
01370   tg_node_frwrd_link=tg_rem_task_node->tg_node_frwrd_link;
01371   tg_node_bkwrd_link=tg_rem_task_node->tg_node_bkwrd_link;
01372 
01373   
01374   for(i=0;i<nb_node_bkwd_links;i++){
01375 
01376     if(!tg_node_bkwrd_link[i]) return -1; 
01377     if(!tg_node_bkwrd_link[i]->obj_node_ptr) return -1;
01378     if(!tg_node_bkwrd_link[i]->obj_node_ptr->tg_obj_bkwrd_link) return -1;
01379     if(!tg_node_bkwrd_link[i]->obj_node_ptr->tg_obj_bkwrd_link->task_node_ptr) return -1;
01380 
01381     stmp = dstring_sprintf("<back_link_task_id=\"%d\" for_node_link_id=\"%d\" for_obj_link_id=\"%d\">\n", 
01382                            tg_node_bkwrd_link[i]->obj_node_ptr->tg_obj_bkwrd_link->task_node_ptr->id,
01383                            tg_node_bkwrd_link[i]->obj_node_ptr->tg_obj_bkwrd_link->for_link_pos,
01384                            tg_node_bkwrd_link[i]->for_link_pos);
01385     s = dstring_append_free(s,stmp);
01386   }
01387 
01388   for(i=0;i<nb_node_frwd_links;i++){
01389      if(!tg_node_frwrd_link[i]) return -1;
01390      if(!tg_node_frwrd_link[i]->obj_node_ptr) return -1;
01391      obj_node_ptr=tg_node_frwrd_link[i]->obj_node_ptr;
01392 
01393      stmp = dstring_sprintf("<in_call_seq_pos=\"%d\" out_call_seq_pos=\"%d\" data_ptr=\"%d\" byte_size=\"%d\" nb_obj_frwd_links=\"%d\">\n", 
01394                                obj_node_ptr->in_call_seq_pos,
01395                                obj_node_ptr->out_call_seq_pos,
01396                                obj_node_ptr->data_ptr,
01397                                obj_node_ptr->byte_size, 
01398                                obj_node_ptr->nb_obj_frwd_links);
01399      s = dstring_append_free(s,stmp);
01400 
01401      nb_obj_frwd_links=obj_node_ptr->nb_obj_frwd_links;
01402 
01403      stmp = dstring_sprintf("<name=%s\n>", obj_node_ptr->name);
01404      s = dstring_append_free(s,stmp);
01405   }
01406 
01407   stmp = dstring_sprintf("<end_remote_task>");
01408   s = dstring_append_free(s,stmp);
01409   *rem_task_node_str=s;
01410   return 0;
01411 }
01412 
01413 
01414 
01415 
01416 
01435 int
01436 gs_smart_decode_tg_rem_task_node(char *rem_task_node_str, gs_smart_tg * task_graph,
01437                                gs_smart_tg_task_node * tg_task_node){
01438   
01439   gs_smart_tg_dep_link ** tg_node_frwrd_link;
01440   gs_smart_tg_obj_node * obj_node_ptr; 
01441   int n, nchars, i, j;
01442   int nb_node_frwd_links, nb_obj_frwd_links, nb_node_bkwd_links;
01443   int back_link_task_id, for_node_link_id, for_obj_link_id;
01444   char *strp = rem_task_node_str;
01445   gs_smart_tg_task_node * tg_src_task_node;
01446   gs_smart_tg_client_node * tg_src_clnt_node;
01447   gs_smart_tg_remote_task_node * tg_src_rem_task_node;
01448   gs_smart_tg_dep_link * for_task_link, * for_obj_link;
01449   gs_smart_tg_remote_task_node * tg_rem_task_node;
01450   gs_smart_tg_dep_link ** tg_obj_frwrd_link;
01451  
01452   if((!rem_task_node_str) || (!task_graph) || (!tg_task_node)) return -1;
01453   
01454   if(!tg_task_node->tg_rem_task_node) return -1;
01455 
01456   tg_rem_task_node=tg_task_node->tg_rem_task_node;
01457 
01458 
01459   n = sscanf(strp,"<begin_remote_task>%n", 
01460              &nchars);
01461   strp = strp+nchars;
01462   
01463   n = sscanf(strp, "<blocking=\"%d\">\n%n", 
01464              &tg_rem_task_node->blocking, &nchars);
01465   strp = strp+nchars;
01466 
01467   n = sscanf(strp, "<nb_flops=\"%lg\">\n%n", 
01468              &tg_rem_task_node->nb_flops, &nchars);
01469   strp = strp+nchars;
01470 
01471   n = sscanf(strp, "<nb_servers=\"%d\">\n%n",
01472               &tg_rem_task_node->nb_servers, &nchars);
01473   strp = strp+nchars;
01474 
01475   n = sscanf(strp, "<nb_node_frwd_links=\"%d\">\n%n", 
01476              &tg_rem_task_node->nb_node_frwd_links, &nchars);
01477   strp = strp+nchars;
01478 
01479   n = sscanf(strp, "<nb_node_bkwd_links=\"%d\">\n%n", 
01480               &tg_rem_task_node->nb_node_bkwd_links, &nchars);
01481   strp = strp+nchars;
01482 
01483 
01484   nb_node_frwd_links=tg_rem_task_node->nb_node_frwd_links;
01485   nb_node_bkwd_links=tg_rem_task_node->nb_node_bkwd_links;
01486   tg_rem_task_node->tg_node_bkwrd_link=(gs_smart_tg_dep_link **)
01487                     calloc(nb_node_bkwd_links, sizeof (gs_smart_tg_dep_link *));
01488 
01489   if(!tg_rem_task_node->tg_node_bkwrd_link) return -1;
01490 
01491 
01492   for(i=0; i<nb_node_bkwd_links; i++){
01493     n = sscanf(strp, 
01494                "<back_link_task_id=\"%d\" for_node_link_id=\"%d\" for_obj_link_id=\"%d\">\n%n", 
01495                            &back_link_task_id, &for_node_link_id, &for_obj_link_id, &nchars);
01496     strp = strp+nchars;
01497  
01498     if(!task_graph->task_nodes[back_link_task_id]) return -1; 
01499     tg_src_task_node=task_graph->task_nodes[back_link_task_id];
01500    
01501     if(tg_src_task_node->node_type==GS_SMART_TG_CLIENT_NODE){
01502       if(!tg_src_task_node->tg_client_node) return -1;
01503       tg_src_clnt_node=tg_src_task_node->tg_client_node;
01504 
01505       if(!tg_src_clnt_node->tg_node_frwrd_link[for_node_link_id]) return -1;
01506       for_task_link=tg_src_clnt_node->tg_node_frwrd_link[for_node_link_id];
01507 
01508       if(!for_task_link->obj_node_ptr) return -1;
01509       if(!for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id]) return -1;
01510       for_obj_link=for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id];
01511 
01512       tg_rem_task_node->tg_node_bkwrd_link[i]=for_obj_link;     
01513        tg_rem_task_node->tg_node_bkwrd_link[i]->back_link_pos=i;  
01514       for_obj_link->task_node_ptr=tg_task_node;
01515      }
01516      else if(tg_src_task_node->node_type==GS_SMART_TG_REM_TASK_NODE){
01517        if(!tg_src_task_node->tg_rem_task_node) return -1;
01518        tg_src_rem_task_node=tg_src_task_node->tg_rem_task_node;
01519        
01520        if(!tg_src_rem_task_node->tg_node_frwrd_link[for_node_link_id]) return -1;
01521        for_task_link=tg_src_rem_task_node->tg_node_frwrd_link[for_node_link_id];
01522   
01523        if(!for_task_link->obj_node_ptr) return -1;
01524        if(!for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id]) return -1;
01525        for_obj_link=for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id];
01526        tg_rem_task_node->tg_node_bkwrd_link[i]=for_obj_link;   
01527        tg_rem_task_node->tg_node_bkwrd_link[i]->back_link_pos=i;  
01528        for_obj_link->task_node_ptr=tg_task_node;
01529     }
01530   }
01531 
01532 
01533   tg_node_frwrd_link=(gs_smart_tg_dep_link **)
01534                      calloc(nb_node_frwd_links,sizeof(gs_smart_tg_dep_link *));
01535 
01536   if(!tg_node_frwrd_link) return -1;
01537   tg_rem_task_node->tg_node_frwrd_link= tg_node_frwrd_link;
01538   for(i=0; i<nb_node_frwd_links; i++){
01539     tg_node_frwrd_link[i]=(gs_smart_tg_dep_link *)
01540                            calloc(1, sizeof(gs_smart_tg_dep_link ));
01541     tg_node_frwrd_link[i]->task_node_ptr=tg_task_node;
01542 
01543     if(!tg_node_frwrd_link[i]) return -1;
01544     tg_node_frwrd_link[i]->for_link_pos=i;
01545 
01546     tg_node_frwrd_link[i]->obj_node_ptr=(gs_smart_tg_obj_node *)
01547                                          calloc(1,sizeof(gs_smart_tg_obj_node));
01548 
01549     if(!tg_node_frwrd_link[i]->obj_node_ptr) return -1;
01550     
01551     obj_node_ptr=tg_node_frwrd_link[i]->obj_node_ptr;
01552     obj_node_ptr->tg_obj_bkwrd_link=tg_node_frwrd_link[i];
01553 
01554 
01555     n = sscanf(strp, 
01556                "<in_call_seq_pos=\"%d\" out_call_seq_pos=\"%d\" data_ptr=\"%d\" byte_size=\"%d\" nb_obj_frwd_links=\"%d\">\n%n", 
01557                &obj_node_ptr->in_call_seq_pos, &obj_node_ptr->out_call_seq_pos, &obj_node_ptr->data_ptr, 
01558                &obj_node_ptr->byte_size, 
01559                &obj_node_ptr->nb_obj_frwd_links, &nchars);
01560     strp = strp+nchars;
01561 
01562     obj_node_ptr->name = (char *)calloc(strlen(rem_task_node_str)+1, sizeof(char));
01563     if(!obj_node_ptr->name) return -1;
01564 
01565     n = sscanf(strp, "<name=%s\n>%n", obj_node_ptr->name,  &nchars);
01566     strp = strp+nchars;
01567     obj_node_ptr->name = REALLOC(obj_node_ptr->name, strlen(obj_node_ptr->name)+1);
01568 
01569     if(!obj_node_ptr->name) return -1;
01570 
01571 
01572 
01573     nb_obj_frwd_links=obj_node_ptr->nb_obj_frwd_links;
01574 
01575     obj_node_ptr->tg_obj_frwrd_link=(gs_smart_tg_dep_link **)
01576                    calloc(nb_obj_frwd_links, sizeof(gs_smart_tg_dep_link *));
01577 
01578 
01579     tg_obj_frwrd_link =obj_node_ptr->tg_obj_frwrd_link;
01580     for(j=0;j<nb_obj_frwd_links;j++){
01581       tg_obj_frwrd_link[j]=(gs_smart_tg_dep_link *)
01582                    calloc(1, sizeof(gs_smart_tg_dep_link ));
01583       if(!tg_obj_frwrd_link[j]) return -1;
01584 
01585       tg_obj_frwrd_link[j]->for_link_pos=j;
01586       tg_obj_frwrd_link[j]->obj_node_ptr=obj_node_ptr;
01587     }
01588   }
01589   n = sscanf(strp, "<end_remote_task>%n", &nchars);
01590   strp = strp+nchars;
01591   return 0;
01592 }
01593 
01608 int
01609 gs_smart_encode_tg_client_node(char **client_node_string,  gs_smart_tg_task_node * tg_task_node){
01610   gs_smart_tg_dep_link ** tg_node_frwrd_link;
01611   gs_smart_tg_dep_link ** tg_node_bkwrd_link;
01612   gs_smart_tg_obj_node * obj_node_ptr; 
01613   int i ;
01614   int nb_obj_frwd_links, nb_node_frwd_links, nb_node_bkwd_links;
01615   char *s = NULL;
01616   char *stmp = NULL;
01617   gs_smart_tg_client_node * tg_client_node;
01618   
01619   if(!tg_task_node) return -1;
01620 
01621   tg_client_node=tg_task_node->tg_client_node;
01622 
01623   if(!tg_client_node) return -1;
01624 
01625   s = dstring_sprintf("<begin_client_node>");
01626 
01627   stmp = dstring_sprintf("<nb_node_frwd_links=\"%d\">\n", 
01628                           tg_client_node->nb_node_frwd_links);
01629   s = dstring_append_free(s,stmp);
01630 
01631   stmp = dstring_sprintf("<nb_node_bkwd_links=\"%d\">\n", 
01632                            tg_client_node->nb_node_bkwd_links);
01633   s = dstring_append_free(s,stmp);
01634 
01635 
01636   nb_node_frwd_links=tg_client_node->nb_node_frwd_links;
01637   nb_node_bkwd_links=tg_client_node->nb_node_bkwd_links;
01638 
01639  
01640   if(((!tg_client_node->tg_node_frwrd_link) &&  (nb_node_frwd_links>0)) || 
01641      ((!tg_client_node->tg_node_bkwrd_link) &&  (nb_node_bkwd_links>0))){
01642      ERRPRINTF("SMART: Error client forward back links is NULL..\n");
01643      return -1;
01644    }
01645 
01646   tg_node_frwrd_link=tg_client_node->tg_node_frwrd_link;
01647   tg_node_bkwrd_link=tg_client_node->tg_node_bkwrd_link;
01648 
01649   for(i=0;i<nb_node_bkwd_links;i++){
01650     if(!tg_node_bkwrd_link[i]) return -1;
01651     if(!tg_node_bkwrd_link[i]->obj_node_ptr) return -1;
01652     obj_node_ptr=tg_node_bkwrd_link[i]->obj_node_ptr;
01653     if(!obj_node_ptr->tg_obj_bkwrd_link) return -1;
01654     
01655     if(!obj_node_ptr->tg_obj_bkwrd_link->task_node_ptr) return -1;
01656 
01657     stmp = dstring_sprintf("<back_link_task_id=\"%d\" for_node_link_id=\"%d\" for_obj_link_id=\"%d\">\n", 
01658                            obj_node_ptr->tg_obj_bkwrd_link->task_node_ptr->id,
01659                            obj_node_ptr->tg_obj_bkwrd_link->for_link_pos,
01660                            tg_node_bkwrd_link[i]->for_link_pos);
01661     s = dstring_append_free(s,stmp);
01662   }
01663 
01664 
01665   for(i=0;i<nb_node_frwd_links;i++){
01666     if(!tg_node_frwrd_link[i]) return -1;
01667     if(!tg_node_frwrd_link[i]->obj_node_ptr) return -1;
01668     stmp = dstring_sprintf("<in_call_seq_pos=\"%d\" out_call_seq_pos=\"%d\" data_ptr=\"%d\" byte_size=\"%d\" nb_obj_frwd_links=\"%d\">\n", 
01669                                tg_node_frwrd_link[i]->obj_node_ptr->in_call_seq_pos,
01670                                tg_node_frwrd_link[i]->obj_node_ptr->out_call_seq_pos,
01671                                tg_node_frwrd_link[i]->obj_node_ptr->data_ptr,
01672                                tg_node_frwrd_link[i]->obj_node_ptr->byte_size,
01673                                tg_node_frwrd_link[i]->obj_node_ptr->nb_obj_frwd_links);
01674     s = dstring_append_free(s,stmp);
01675  
01676      
01677     nb_obj_frwd_links=tg_node_frwrd_link[i]->obj_node_ptr->nb_obj_frwd_links;
01678 
01679     obj_node_ptr=tg_node_frwrd_link[i]->obj_node_ptr;
01680 
01681     if(!obj_node_ptr->name) return -1;
01682     
01683     stmp = dstring_sprintf("<name=%s\n>", obj_node_ptr->name);
01684     s = dstring_append_free(s,stmp);
01685   }
01686 
01687   stmp = dstring_sprintf("<end_client_node>");
01688   s = dstring_append_free(s,stmp);
01689   *client_node_string=s;
01690 
01691   return 0;
01692 
01693 }
01694 
01695 
01696 
01715 int
01716 gs_smart_decode_tg_client_node(char *client_node_str, gs_smart_tg * task_graph,
01717                                gs_smart_tg_task_node * tg_task_node){
01718 
01719   gs_smart_tg_dep_link ** tg_node_frwrd_link;
01720   gs_smart_tg_obj_node * obj_node_ptr; 
01721   int n, nchars, i, j;
01722   int nb_node_frwd_links, nb_obj_frwd_links, nb_node_bkwd_links;
01723   int back_link_task_id, for_node_link_id, for_obj_link_id;
01724   char *strp = client_node_str;
01725   gs_smart_tg_task_node * tg_src_task_node;
01726   gs_smart_tg_client_node * tg_src_clnt_node;
01727   gs_smart_tg_remote_task_node * tg_src_rem_task_node;
01728   gs_smart_tg_dep_link * for_task_link, * for_obj_link;
01729   gs_smart_tg_dep_link ** bkwd_task_links;
01730   gs_smart_tg_dep_link ** tg_obj_frwrd_link;
01731   gs_smart_tg_client_node * tg_client_node;
01732 
01733   if((!client_node_str) || (!task_graph) || (!tg_task_node)) return -1;
01734 
01735   if(!tg_task_node->tg_client_node) return -1;
01736 
01737   tg_client_node=tg_task_node->tg_client_node;
01738  
01739   n = sscanf(strp,"<begin_client_node>%n", 
01740              &nchars);
01741   strp = strp+nchars;
01742 
01743   n = sscanf(strp, "<nb_node_frwd_links=\"%d\">\n%n", 
01744              &tg_client_node->nb_node_frwd_links, &nchars);
01745   strp = strp+nchars;
01746 
01747   n = sscanf(strp, "<nb_node_bkwd_links=\"%d\">\n%n", 
01748               &tg_client_node->nb_node_bkwd_links, &nchars);
01749   strp = strp+nchars;
01750 
01751   nb_node_frwd_links=tg_client_node->nb_node_frwd_links;
01752   nb_node_bkwd_links=tg_client_node->nb_node_bkwd_links;
01753 
01754 
01755   /*
01756    * **********************************
01757    * Constructing backward links
01758    * **********************************
01759    */
01760 
01761   tg_client_node->tg_node_bkwrd_link=(gs_smart_tg_dep_link **)calloc(nb_node_bkwd_links, sizeof (gs_smart_tg_dep_link *));
01762   
01763   if(!tg_client_node->tg_node_bkwrd_link) return -1;
01764 
01765   bkwd_task_links=tg_client_node->tg_node_bkwrd_link;
01766 
01767 
01768   for(i=0; i<nb_node_bkwd_links; i++){
01769     bkwd_task_links[i] = (gs_smart_tg_dep_link *)calloc(1, sizeof(gs_smart_tg_dep_link));
01770     if(!bkwd_task_links[i]) return -1;
01771      bkwd_task_links[i]->back_link_pos=i;
01772    
01773     /*
01774      * Receiving information of which obj node this back link points back to..
01775      */   
01776     n = sscanf(strp, 
01777                "<back_link_task_id=\"%d\" for_node_link_id=\"%d\" for_obj_link_id=\"%d\">\n%n", 
01778                            &back_link_task_id, &for_node_link_id, &for_obj_link_id, &nchars);
01779     strp = strp+nchars;
01780 
01781     if(!task_graph->task_nodes[back_link_task_id]) return -1;
01782   
01783    /*
01784     * Source task node of obj node that this back link points back to..
01785     */
01786     
01787     tg_src_task_node=task_graph->task_nodes[back_link_task_id];
01788 
01789     if(!tg_client_node->tg_node_bkwrd_link) return -1;
01790 
01791     bkwd_task_links=tg_client_node->tg_node_bkwrd_link;
01792     
01793     if(tg_src_task_node->node_type==GS_SMART_TG_CLIENT_NODE){
01794 
01795       if(!tg_src_task_node->tg_client_node) return -1;
01796  
01797       /*
01798        * Source client node of the obj node that this back link points back to..
01799        */
01800       tg_src_clnt_node=tg_src_task_node->tg_client_node;
01801 
01802       if(!tg_src_clnt_node->tg_node_frwrd_link[for_node_link_id]) return -1;
01803 
01804       /*
01805        * The forward task link that points to the obj node 
01806        * that this back link points back to..
01807        */
01808 
01809       for_task_link=tg_src_clnt_node->tg_node_frwrd_link[for_node_link_id];
01810      
01811       if(!for_task_link->obj_node_ptr) return -1;
01812       if(!for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id]) return -1;
01813 
01814       /*
01815        * The forward obj link that points from the obj node that this back link
01816        *  points back to.
01817        */
01818       for_obj_link=for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id];
01819 
01820       /*
01821        * This for object link points from the obj node to this task node
01822        */ 
01823       for_obj_link->task_node_ptr=tg_task_node;
01824 
01825 
01826       /* 
01827        * This forward object link points from the object node to this task node.
01828        * Therefore the twoway pointer of this forward object link is the 
01829        * exact same as the two way pointers of this backward object link.  
01830        */
01831 
01832       bkwd_task_links[i]=for_obj_link;    
01833 
01834      }
01835      else if(tg_src_task_node->node_type==GS_SMART_TG_REM_TASK_NODE){
01836       
01837        if(!tg_src_task_node->tg_rem_task_node) return -1;
01838 
01839       /*
01840        * Source remote node of the obj node that this back link points back to..
01841        */
01842        tg_src_rem_task_node=tg_src_task_node->tg_rem_task_node;
01843 
01844        if(!tg_src_rem_task_node->tg_node_frwrd_link[for_node_link_id]) return -1;
01845        /*
01846         * The forward task link that points to the obj node 
01847         * that this back link points back to..
01848         */  
01849        for_task_link=tg_src_rem_task_node->tg_node_frwrd_link[for_node_link_id];
01850 
01851        if(!for_task_link->obj_node_ptr) return -1;
01852        if(!for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id]) return -1;
01853 
01854       /*
01855        * The forward obj link that points from the obj node that this back link
01856        *  points back to.
01857        */
01858        for_obj_link=for_task_link->obj_node_ptr->tg_obj_frwrd_link[for_obj_link_id];
01859      
01860 
01861        /*
01862        * This for object link points from the obj node to this task node
01863        */ 
01864        for_obj_link->task_node_ptr=tg_task_node;
01865 
01866 
01867       /* 
01868        * This forward object link points from the object node to this task node.
01869        * Therefore the twoway pointer of this forward object link is the 
01870        * exact same as the two way pointers of this backward object link.  
01871        */
01872        bkwd_task_links[i]=for_obj_link;     
01873     }
01874   }
01875 
01876 
01877   /*
01878    * **********************************
01879    * Constructing forward links
01880    * **********************************
01881    */
01882 
01883   tg_node_frwrd_link=(gs_smart_tg_dep_link **)
01884                      calloc(nb_node_frwd_links,sizeof(gs_smart_tg_dep_link *));
01885 
01886   if(!tg_node_frwrd_link) return -1;
01887 
01888   tg_client_node->tg_node_frwrd_link= tg_node_frwrd_link;
01889 
01890   /*
01891    * Constructing forward node links
01892    */  
01893   for(i=0; i<nb_node_frwd_links; i++){
01894     tg_node_frwrd_link[i]=(gs_smart_tg_dep_link *)
01895                            calloc(1, sizeof(gs_smart_tg_dep_link ));
01896 
01897 
01898     tg_node_frwrd_link[i]->task_node_ptr=tg_task_node;
01899   /*
01900    * Allocating object node that this for obj link points to
01901    */ 
01902     if(!tg_node_frwrd_link[i]) return -1;
01903     tg_node_frwrd_link[i]->obj_node_ptr=(gs_smart_tg_obj_node *)
01904                                          calloc(1,sizeof(gs_smart_tg_obj_node));
01905     
01906     
01907 
01908     if(!tg_node_frwrd_link[i]->obj_node_ptr) return -1;
01909     obj_node_ptr=tg_node_frwrd_link[i]->obj_node_ptr;
01910 
01911     
01912     obj_node_ptr->tg_obj_bkwrd_link=tg_node_frwrd_link[i];
01913 
01914   /*
01915    * Receiving information on object node attributes
01916    */  
01917     n = sscanf(strp, 
01918                "<in_call_seq_pos=\"%d\" out_call_seq_pos=\"%d\" data_ptr=\"%d\" byte_size=\"%d\" nb_obj_frwd_links=\"%d\">\n%n", 
01919                &obj_node_ptr->in_call_seq_pos, &obj_node_ptr->out_call_seq_pos, &obj_node_ptr->data_ptr, &obj_node_ptr->byte_size, 
01920                &obj_node_ptr->nb_obj_frwd_links, &nchars);
01921     strp = strp+nchars;
01922 
01923     obj_node_ptr->name = (char *)calloc(strlen(client_node_str)+1, sizeof(char));
01924     if(!obj_node_ptr->name) return -1;
01925 
01926   /*
01927    * Receiving object node name.
01928    */  
01929     n = sscanf(strp, "<name=%s\n>%n", obj_node_ptr->name,  &nchars);
01930     strp = strp+nchars;
01931    
01932     obj_node_ptr->name = REALLOC(obj_node_ptr->name, strlen(obj_node_ptr->name)+1);
01933     if(!obj_node_ptr->name) return -1;
01934 
01935     
01936     nb_obj_frwd_links=obj_node_ptr->nb_obj_frwd_links;
01937 
01938     tg_obj_frwrd_link=(gs_smart_tg_dep_link **)
01939                    calloc(nb_obj_frwd_links, sizeof(gs_smart_tg_dep_link *));
01940 
01941     if(!tg_obj_frwrd_link) return -1;
01942 
01943     obj_node_ptr->tg_obj_frwrd_link=tg_obj_frwrd_link;
01944  
01945   /*
01946    * Constructing forward object  links which point from the object node
01947    * to a task node.
01948    */  
01949 
01950     for(j=0;j<nb_obj_frwd_links;j++){
01951       tg_obj_frwrd_link[j]=(gs_smart_tg_dep_link *)
01952                    calloc(1, sizeof(gs_smart_tg_dep_link ));
01953 
01954       if(!tg_obj_frwrd_link[j]) return -1;
01955 
01956       tg_obj_frwrd_link[j]->for_link_pos=j;
01957       tg_obj_frwrd_link[j]->obj_node_ptr=obj_node_ptr;
01958     }
01959   }
01960 
01961   n = sscanf(strp, "<end_client>%n", &nchars);
01962   strp = strp+nchars;
01963   return 0;
01964 }
01965 
01966 
01967 
01984 int
01985 gs_smart_encode_app_pm(char **app_pm_str, gs_smart_app_pm * app_pm){
01986   int i, j ;
01987   char *s = NULL;
01988   char *stmp = NULL;
01989   if(!app_pm){
01990     ERRPRINTF("SMART: Error encoding app pm, app pm NULL\n");
01991     return -1;
01992   }
01993 
01994   s = dstring_sprintf("<number tasks=\"%d\" >\n", app_pm->nb_tasks);
01995   for(i=0; i<app_pm->nb_tasks;i++){
01996     stmp = dstring_sprintf("<task node id=\"%d\" local=\"%d\">", i, app_pm->tasks[i]->local);
01997     s = dstring_append_free(s,stmp);
01998     if(app_pm->tasks[i]->local==1){
01999       stmp = dstring_sprintf("<nb_args=\"%d\">", app_pm->tasks[i]->nb_args);
02000       s = dstring_append_free(s,stmp);
02001       for(j=0; j<app_pm->tasks[i]->nb_args; j++){
02002         stmp = dstring_sprintf("<id=\"%d\">", app_pm->tasks[i]->args[j]->id);
02003         s = dstring_append_free(s,stmp);
02004       }
02005     }else{
02006       stmp = dstring_sprintf("<nickname=%s\n>", app_pm->tasks[i]->nickname);
02007       s = dstring_append_free(s,stmp);
02008       stmp = dstring_sprintf("<blocking=%d>", app_pm->tasks[i]->blocking);
02009       s = dstring_append_free(s,stmp);
02010       stmp = dstring_sprintf("<nb_args=\"%d\">", app_pm->tasks[i]->nb_args);
02011       s = dstring_append_free(s,stmp);
02012       for(j=0; j<app_pm->tasks[i]->nb_args; j++){
02013         stmp = dstring_sprintf("<id=\"%d\" scalar=\"%d\" type=\"%d\">", app_pm->tasks[i]->args[j]->id, app_pm->tasks[i]->args[j]->scalar, app_pm->tasks[i]->args[j]->type);
02014         s = dstring_append_free(s,stmp);
02015         if(app_pm->tasks[i]->args[j]->type==GS_INT){
02016           stmp = dstring_sprintf("<uvalue=\"%d\">", app_pm->tasks[i]->args[j]->uvalue.i);
02017           s = dstring_append_free(s,stmp);
02018         }
02019 
02020       }
02021     }
02022   }
02023   *app_pm_str = s;
02024   return 0;
02025 }
02026 
02027 
02028 
02029 
02030 
02031 
02050 int
02051 gs_smart_decode_app_pm(char *app_pm_str, gs_smart_app_pm * app_pm){
02052   int id, i, j;
02053   char *strp = app_pm_str;
02054   int n, nchars;
02055   if(!app_pm){
02056     ERRPRINTF("SMART: Error decode string for app pm is NULL\n");
02057     return -1;
02058   }
02059 
02060   n = sscanf(strp,"<number tasks=\"%d\" >\n %n", &app_pm->nb_tasks, &nchars);
02061   strp = strp+nchars;
02062   app_pm->tasks=(gs_smart_app_pm_task **)calloc(app_pm->nb_tasks ,sizeof(gs_smart_app_pm_task *));
02063   for(i=0; i<app_pm->nb_tasks; i++){
02064     app_pm->tasks[i] = (gs_smart_app_pm_task *)calloc(1 ,sizeof(gs_smart_app_pm_task));
02065     if(!app_pm->tasks[i]) return -1;
02066     app_pm->tasks[i]->t_anayl=(gs_smart_t_dep_anayl *)calloc(1, sizeof(gs_smart_t_dep_anayl));
02067     if(!app_pm->tasks[i]->t_anayl) return -1;
02068   }
02069   for(i=0; i<app_pm->nb_tasks;i++){
02070     n = sscanf(strp, "<task node id=\"%d\" local=\"%d\">%n", &id, &app_pm->tasks[i]->local,&nchars);
02071     strp = strp+nchars;
02072     if(app_pm->tasks[i]->local==1){
02073       n = sscanf(strp, "<nb_args=\"%d\">%n", &app_pm->tasks[i]->nb_args,&nchars);
02074       strp = strp+nchars;
02075       app_pm->tasks[i]->args =(gs_smart_app_pm_args **)calloc(app_pm->tasks[i]->nb_args ,sizeof(gs_smart_app_pm_args * ));
02076       if(!app_pm->tasks[i]->args){
02077         ERRPRINTF("SMART: Error allocating memory to args\n");
02078         return -1;
02079       }
02080 
02081       for(j=0;j<app_pm->tasks[i]->nb_args;j++){
02082         app_pm->tasks[i]->args[j] = (gs_smart_app_pm_args *)calloc(1 ,sizeof(gs_smart_app_pm_args));
02083         if(!app_pm->tasks[i]->args[j]){
02084           ERRPRINTF("SMART: Error allocating to arg %d\n", j);
02085           return -1;
02086         }
02087         
02088         app_pm->tasks[i]->args[j]->a_anayl=(gs_smart_a_dep_anayl *)calloc(1, sizeof(gs_smart_a_dep_anayl)); 
02089         if(!app_pm->tasks[i]->args[j]->a_anayl){
02090           ERRPRINTF("SMART: Error allocating to arg anayl %d\n", j);
02091           return -1;
02092         }
02093 
02094         n = sscanf(strp, "<id=\"%d\">%n", &app_pm->tasks[i]->args[j]->id,  &nchars);
02095         strp = strp+nchars;
02096       }
02097     }
02098     else{
02099       app_pm->tasks[i]->nickname = (char *)calloc(strlen(app_pm_str)+1, sizeof(char));
02100       n = sscanf(strp, "<nickname=%s\n>%n", app_pm->tasks[i]->nickname,  &nchars);
02101       strp = strp+nchars;
02102       n = sscanf(strp, "<blocking=%d>%n", &app_pm->tasks[i]->blocking,  &nchars);
02103       strp = strp+nchars;
02104       app_pm->tasks[i]->nickname = REALLOC(app_pm->tasks[i]->nickname, strlen(app_pm->tasks[i]->nickname)+1);
02105       if(!app_pm->tasks[i]->nickname){
02106         ERRPRINTF("SMART: XML info decode error. Failed to allocate memory\n");
02107         return -1;
02108       }
02109      
02110       if(!app_pm->tasks[i]->nickname){
02111         ERRPRINTF("SMART: Failed to decode app_pm\n");
02112         return -1;
02113       }
02114      
02115       n = sscanf(strp, "<nb_args=\"%d\">%n",&app_pm->tasks[i]->nb_args, &nchars);
02116       strp = strp+nchars;
02117 
02118       app_pm->tasks[i]->args =(gs_smart_app_pm_args **)calloc(app_pm->tasks[i]->nb_args ,sizeof(gs_smart_app_pm_args * ));
02119       if(!app_pm->tasks[i]->args){
02120         ERRPRINTF("SMART: Failed to allocate memory for args\n");
02121         return -1;
02122       }
02123       for(j=0; j<app_pm->tasks[i]->nb_args; j++){
02124         app_pm->tasks[i]->args[j] = (gs_smart_app_pm_args *)calloc(1 ,sizeof(gs_smart_app_pm_args));
02125         if(!app_pm->tasks[i]->args[j]){
02126           ERRPRINTF("SMART: Failed to allocate memory for arg %d\n", j);
02127           return -1;
02128         }
02129 
02130         
02131         app_pm->tasks[i]->args[j]->a_anayl=(gs_smart_a_dep_anayl *)calloc(1, sizeof(gs_smart_a_dep_anayl)); 
02132         if(!app_pm->tasks[i]->args[j]->a_anayl){
02133           ERRPRINTF("SMART: Error allocating to arg anayl %d\n", j);
02134           return -1;
02135         }
02136 
02137         n = sscanf(strp, "<id=\"%d\" scalar=\"%d\" type=\"%d\">%n",&app_pm->tasks[i]->args[j]->id, &app_pm->tasks[i]->args[j]->scalar, &app_pm->tasks[i]->args[j]->type, &nchars);
02138         strp = strp+nchars;
02139       
02140         if(app_pm->tasks[i]->args[j]->type==GS_INT){
02141           n = sscanf(strp, "<uvalue=\"%d\">%n", &app_pm->tasks[i]->args[j]->uvalue.i, &nchars);
02142           strp = strp+nchars;
02143         }
02144       }
02145     }
02146   }
02147   return 0;
02148 }
02149 
02150 
02151 
02152 
02153 
02154 
02169 int gs_smart_encode_arg_map_info(char **arg_map_info,  gs_argument_t * argptr){
02170   char *s = NULL;
02171   char *stmp = NULL;
02172   if(!argptr) return -1;
02173   s = dstring_sprintf("<begin_arg_map_info>\n");
02174   stmp = dstring_sprintf("<input_stored_remotely=\" %d \">\n", argptr->input_arg_stored);
02175   s = dstring_append_free(s,stmp);
02176   stmp = dstring_sprintf("<input_arg_received_remotely=\" %d \">\n", argptr->input_arg_received_remotely);
02177   s = dstring_append_free(s,stmp);
02178   stmp = dstring_sprintf("<input_arg_deleted=\" %d \">\n", argptr->input_arg_deleted);
02179   s = dstring_append_free(s,stmp);
02180   stmp = dstring_sprintf("<output_arg_sent_remotely=\" %d \">\n", argptr->output_arg_sent_remotely);
02181   s = dstring_append_free(s,stmp);
02182   stmp = dstring_sprintf("<output_arg_cached=\" %d \">\n", argptr->output_cached);
02183   s = dstring_append_free(s,stmp);
02184   if(argptr->output_arg_sent_remotely){
02185     stmp = dstring_sprintf("<output_nb_dest_servers=\" %d \">\n", argptr->output_nb_dest_servers);
02186     s = dstring_append_free(s,stmp);
02187   }
02188   
02189   *arg_map_info=s;
02190 
02191   return 0;
02192 }
02193 
02194 
02208 int gs_smart_decode_arg_map_info(char *smart_arg_info, gs_argument_t * argptr){
02209   int n, nchars;
02210   char *strp = smart_arg_info;
02211   if(!argptr) return -1;
02212   n = sscanf(strp, "<begin_arg_map_info>\n%n", &nchars);
02213   strp = strp+nchars;
02214   n = sscanf(strp, "<input_stored_remotely=\" %d \">\n%n", &argptr->input_arg_stored, &nchars);
02215   strp = strp+nchars;
02216   n = sscanf(strp, "<input_arg_received_remotely=\" %d \">\n%n", &argptr->input_arg_received_remotely, &nchars);
02217   strp = strp+nchars;
02218   n = sscanf(strp, "<input_arg_deleted=\" %d \">\n%n", &argptr->input_arg_deleted, &nchars);
02219   strp = strp+nchars;
02220   n = sscanf(strp, "<output_arg_sent_remotely=\" %d \">\n%n", &argptr->output_arg_sent_remotely, &nchars);
02221   strp = strp+nchars;
02222   n = sscanf(strp, "<output_arg_cached=\" %d \">\n%n", &argptr->output_cached, &nchars);
02223   strp = strp+nchars;
02224   if(argptr->output_arg_sent_remotely){
02225     n = sscanf(strp, "<output_nb_dest_servers=\" %d \">\n%n", &argptr->output_nb_dest_servers, &nchars);
02226     strp = strp+nchars;
02227   }
02228   return 0;
02229 }
02230 
02231 
02232 
02233 
02234 
02235 
02246 int
02247 gs_smart_encode_ping_info(char **encoding, gs_server_t *server, gs_server_t **server_list, double *times, int count){
02248 
02249   char componentid_string[CID_LEN*2+1];
02250   char *stmp = NULL;
02251   int i;    
02252   gs_server_t **s = server_list;   /* just a shortcut name */
02253   *encoding = dstring_sprintf("<smart_info>\n");
02254   stmp = dstring_sprintf("<count> %d </count>\n", count);
02255   *encoding = dstring_append_free(*encoding , stmp);
02256 
02257   for(i=0;i<count;i++){
02258     if(!s[i]){
02259       return -1;
02260     }
02261     proxy_cid_to_str(componentid_string, s[i]->componentid);
02262     stmp = dstring_sprintf("<componentid> %s </componentid>  <time> %f </time> \n", componentid_string, times[i]);
02263     *encoding = dstring_append_free(*encoding, stmp);
02264   }
02265    stmp = dstring_sprintf("</smart_info>");
02266    *encoding = dstring_append_free(*encoding, stmp);
02267   return 0;
02268 }
02269 
02270 
02271 
02283 int
02284 gs_smart_decode_ping_info(char *encoding, gs_server_pings_t ***pings, int *np)
02285 {
02286   int i, n, count, maxlen, nchars;
02287   gs_server_pings_t **parr;
02288   char *strp, *cid_tmp;
02289 
02290   *np = 0;
02291   *pings = NULL;
02292 
02293   strp = encoding;
02294   maxlen = strlen(strp);
02295 
02296   cid_tmp = (char *)calloc(maxlen, sizeof(char));
02297   if(!cid_tmp) return -1;
02298 
02299    if(strcmp(strp, "<no_pings>")==0){
02300     return 0;
02301   }
02302 
02303   n = sscanf(strp, "<smart_info>\n %n", &nchars);
02304   strp = strp+nchars;
02305 
02306   n = sscanf(strp, "<count> %d </count>\n %n", &count, &nchars);
02307   strp = strp+nchars;
02308 
02309   parr = (gs_server_pings_t **) malloc(count * sizeof(gs_server_pings_t *));
02310   if(!parr) {
02311     free(cid_tmp);
02312     return -1;
02313   }
02314 
02315   for(i=0;i<count;i++) {
02316     parr[i] = (gs_server_pings_t *) malloc(sizeof(gs_server_pings_t));
02317     if(!parr[i]) {
02318       /* probably need to free parr[1 through i-1] too */
02319       free(parr);
02320       free(cid_tmp);
02321       return -1;
02322     }
02323 
02324     n = sscanf(strp, "<componentid> %s </componentid>  <time> %lg </time>\n %n",
02325           cid_tmp, &(parr[i]->comm_time), &nchars);
02326     strp = strp+nchars;
02327     proxy_str_to_cid(parr[i]->componentid, cid_tmp);
02328   }
02329 
02330   n = sscanf(strp, "</smart_info>\n %n", &nchars);
02331   strp = strp+nchars;
02332 
02333   *np = count;
02334   *pings = parr;
02335 
02336   return 0;
02337 }
02338 
02339 
02340 
02341 
02342 
02343 #endif
02344 
02345