static void Print (Widget entry, XtPointer name, XtPointer data) { name = name; /* unused; suppress compiler warning */ data = data; PrintAction ((Widget)NULL, (XEvent *) 0, (String *) 0, (Cardinal *) 0); ResetMenuEntry (entry); }
/* Generate the "y.output" log file */ void ReportOutput(struct lmno *lmnop) { int i; struct state *stp; struct config *cfp; struct action *ap; FILE *fp; fp = file_open(lmnop,".out","w"); if(fp==0) return; fprintf(fp," \b"); for(i=0; i<lmnop->nstate; i++) { stp = lmnop->sorted[i]; fprintf(fp,"State %d:\n",stp->index); if(lmnop->basisflag) cfp=stp->bp; else cfp=stp->cfp; while(cfp) { char buf[20]; if(cfp->dot==cfp->rp->nrhs) { sprintf(buf,"(%d)",cfp->rp->index); fprintf(fp," %5s ",buf); } else { fprintf(fp," "); } ConfigPrint(fp,cfp); fprintf(fp,"\n"); #ifdef TEST SetPrint(fp,cfp->fws,lmnop); PlinkPrint(fp,cfp->fplp,"To "); PlinkPrint(fp,cfp->bplp,"From"); #endif if(lmnop->basisflag) cfp=cfp->bp; else cfp=cfp->next; } fprintf(fp,"\n"); for(ap=stp->ap; ap; ap=ap->next) { if(PrintAction(ap,fp,30)) fprintf(fp,"\n"); } fprintf(fp,"\n"); } fclose(fp); return; }
//receive the time from QOMET and do actions //ActionRecord array must be orderred void do_actions(int accept_sd,ActionRecord *ac,int ac_count, action_mapping *am, id_ip *p) { printf("\n in do action\n"); float buffer ; buffer =0; int index_ac =0; int i =0; int rc; char *argv[4]; argv[0] = "/usr/local/bin/bash"; for(i=0;i<ac_count;i++) PrintAction(&ac[i]); while(1) { /* Receive a message from the client */ //printf("\nI am waiting client(s) to send message(s) to me...\n"); rc = recv(accept_sd,&buffer, sizeof(float), 0); //printf("\n number byte rec %d\n",rc); //printf("\n time %f\n",buffer); if(rc <= 0) { perror("TCP_QO_ACTION server - recv() error"); goto bad_do_action; } else { //if there is any action in this time, run it if(index_ac > ac_count) continue; while(ac[index_ac].time == buffer) { printf("\ncall action\n"); printf("\n time %f\n",buffer); PrintAction(&ac[index_ac]); //create a process for start an action process *pr; //printf("\ncreate a process"); pr = create_process(); if(pr == NULL) { printf("\nerror in create a process"); return; } pr->expire_time = ac[index_ac].time + ac[index_ac].duration; //build argument for action argv[1] = look_up_action_file(am,ac[index_ac].id); if(argv[1] == NULL) { printf("\n cannot find action file of action id:%d",ac[index_ac].id); //goto bad_do_action; index_ac++; continue; } printf("\naction file:%s",argv[1]); if (ac[index_ac].target != -1) { argv[2] = (char *)look_up_ip(p,ac[index_ac].target); if(argv[2] == NULL) { printf("\n cannot find ip adress of target id:%d",ac[index_ac].target); index_ac++; continue; } argv[3] =(char*)0; } else argv[2] = (char*)0; run_process(pr,main_p->pgid,argv); index_ac++; if(index_ac > ac_count) break; //printf("\nindex :%d and ac[index_ac].time:%f",index_ac,ac[index_ac].time); //add the process into process list add_process_to_list(pr); //print_processes(); } //if there is any processes that needs close because of deadline, close them if(main_p->first_child_process != NULL) while(find_process(buffer)!=NULL) { printf("\nkill a process with time:%d\n",buffer); kill_a_process(buffer); } } //if the value is -1 , the program will be terminated if(buffer == (float)-1) { index_ac =0; } } bad_do_action: return ; }