1 / 8

Analysis of bdeReplay

Analysis of bdeReplay.cc. I. 03f522 Project Ideas II. Analysis for Refactoring III. Source Code of Keypress() IV. Simplifying the Keypress Callback V. Generic (bde-independent) actions (pr_log.c) Notes on bdeReplay: bdeReplay Content |Approx lines (rounded ) |

carina
Download Presentation

Analysis of bdeReplay

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Analysis of bdeReplay.cc I. 03f522 Project Ideas II. Analysis for Refactoring III. Source Code of Keypress() IV. Simplifying the Keypress Callback V. Generic (bde-independent) actions (pr_log.c) • Notes on bdeReplay: bdeReplay Content|Approx lines (rounded) | • Revision History | 100 • Declarations | 50 • replay_log() code | 85 • Keypress() code | 65 • Comments | 200 totals | 500 lines [RJLRef: ~/03f522RefactoringProjects.doc] KeypressSTD.ppt – RJL 031022

  2. Pre-conditions: (#defined BDELOG && ReplayReady) Keypress State Model STATE0 (Initial) “SR” ~ (“SP”|EOF) STATE1 (Command) “SP” | EOF Events: Keypress is the only event; Transition labels are guard conditions, expressed as token values: Token string: Command code “SR” StartCmd “SP” StopCmd STATE2 (Final) KeypressSTD.ppt – RJL 031022

  3. replay_log (1) int replay_log(void) // RJL: void { switch(replayState) { case STATE0: logfile_fp = fopen(logfile, "r"); hcg_ascii_fp = logfile_fp; hcg_read_next(); /* read first line of log file */ idx = 0; // char index to hcg_parse input buffer hcg_parse(hcg_buffer,token, &idx); // alters idx command = encode_token(token); // string to integer, in pr_log.c if (command != StartCmd) { return -5; // error report: pre-condition is “SR” } else dprint("Found StartReplay command\n"); //#ifdef DEBUG printf…. replayState = STATE1; break; // STATE0 KeypressSTD.ppt – RJL 031022

  4. replay_log (2) case STATE1: /* pre-condition: file is non-empty; STATE0 token was "SR" */ hcg_read_next(); // get next command if (feof(hcg_ascii_fp)) { // no more commands (not even "SP") replayState = STATE2 break; } command = do_command(hcg_buffer, token, &idx); /* in pr_log.c */ /* do_command calls encode_token and interprets command */ switch(command) { case SetFltCmd: case SetIntCmd: case SetKeyCmd: case SetStrCmd: case AddRowCmd: case DeleteCmd: #ifdef BDELOG clearObjects(); HG_pkey = HGcurr->HGid; /* where used? - RJL 031018 */ updatedisplaylist(HGcurr); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<< */ ReDraw(); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<< */ #endif break; // SetTypCmd cases KeypressSTD.ppt – RJL 031022

  5. replay_log (3) //case STATE1, switch(command) (continued) case WaitCmd: case StartCmd: case FreeCmd: case InitCmd: case LoadCmd: case ViewNameCmd: break; // no-op: no need to redraw - RJL 020506 case StopCmd: // Split out for state update - RJL 031019 replayState = STATE2; break; default: . . . } // end 2nd switch(command) break; // end STATE1 KeypressSTD.ppt – RJL 031022

  6. Replay_log (4) case STATE2: // in switch(replayState) if (feof(hcg_ascii_fp)) // non-fatal error – warn no StopCmd “SP” replayStatus = -7; else {// else is probably a bug – why not unconditional?? assert (command == StopCmd); int linecnt = 0; while (!feof(hcg_ascii_fp)) { ++linecnt; hcg_read_next(); } if (linecnt>0) replayStatus = -9; //. . . junk after "SP“ fclose(hcg_ascii_fp); //was logfile_fp; hcg_log = 0; // allows more logging or replay I/O. if (take_endsnapshot==1) { /* end snapshot */ // call pr_dump(viewname, tempvar,0,"w"); break; // end of STATE2 default: . . . } // end switch(replayState) return replayStatus; /* to client pr_replay or Keypress */ } // end replay_log in bdeReplay.cc KeypressSTD.ppt – RJL 031022

  7. Keypress (1) void Keypress(Widget w, XtPointer input, XEvent *event, Boolean *continue_dispatch) { #ifdef BDELOG extern int ReplayReady; //in init.cc; used in dialog.cc, bdeReplay.cc KeySym keysym; Modifiers dummy; int replayStatus; /* local var? also in fileio.cc */ if(event -> type == KeyPress) { XtTranslateKeycode(XtDisplay(w), event->xkey.keycode, event-> xkey.state, &dummy, &keysym); if ((strcmp (XKeysymToString(keysym),"s") == 0) && (ReplayReady == 1)) replayStatus = replay_log(); /* <<<<<<<<<<<<<<<<<<< */ if (replayStatus < 0) {. . .} //report error code if negative (FAIL) else { //switch(replayState) // { /*New - RJL 031019: State sequence: (0 1* 2) */ switch(replayState) { . . . } // continued KeypressSTD.ppt – RJL 031022

  8. Keypress (2) switch(replayState) { /* State sequence: (0 1* 2) */ case STATE0: /* "SR" command */ replayState = STATE1; case STATE1: /* while not EOF, do_command under Keypress control */ if (command == StopCmd) replayState = STATE2; // stop the iteration at EOF break; case STATE2 : /* "SP" command or EOF */ ReplayReady = 0; // ignore Keypress from now on // Alt?: allow a new "SR” (to concat. mult. replay logs) dprint("bdeReplay: Keypress: STATE2: End of Replay \n"); break; default: //warn of invalid replayState }; // end switch(replayState) } // end if replayStatus } // end if event->type==KeyPress #endif /* ifdef BDELOG */ } // end KeyPress KeypressSTD.ppt – RJL 031022

More Related