00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: CommandQueue.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.57 $ $Date: 2019/01/17 21:20:58 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * 00019 * This stores all the Commands to be run in a queue. The idea is that 00020 * the various events add Commands to the command queue then they 00021 * are read off the queue and the UIs are notified. 00022 * 00023 * Commands may be logged to a file, if desired. 00024 * 00025 ***************************************************************************/ 00026 00027 #include "CommandQueue.h" 00028 #include "Command.h" 00029 #include "UIObject.h" 00030 #include "TextEvent.h" 00031 #include "utilities.h" 00032 #include "config.h" 00033 00035 CommandQueue::CommandQueue(void) : cmdlist(64) { 00036 } 00037 00038 00040 // we must remove all commands, and delete them as well. 00041 // if logging, must close file 00042 CommandQueue::~CommandQueue(void) { 00043 for (int i=0; i<cmdlist.num(); i++) 00044 delete cmdlist[i]; 00045 } 00046 00047 void CommandQueue::register_UI(UIObject *ui) { 00048 if (uilist.find(ui) == -1) 00049 uilist.append(ui); 00050 } 00051 00052 void CommandQueue::unregister_UI(UIObject *ui) { 00053 int ind = uilist.find(ui); 00054 if (ind >= 0) 00055 uilist.remove(ind); 00056 } 00057 00059 void CommandQueue::runcommand(Command *cmd) { 00060 // ... and report the action has been done 00061 Command::Cmdtype cmdtype = cmd->gettype(); 00062 int n = uilist.num(); 00063 for (int i=0; i<n; i++) { 00064 UIObject *ui = uilist[i]; 00065 // XXX call act_on_command even if not ui->active() 00066 if (ui->want_command(cmdtype)) 00067 ui->act_on_command(cmdtype, cmd); 00068 } 00069 delete cmd; 00070 } 00071 00073 00074 // add a new command to the list ... always adds to queue, does not 00075 // execute. 00076 void CommandQueue::append(Command *cmd) { 00077 cmdlist.append(cmd); 00078 } 00079 00080 void CommandQueue::execute_all() { 00081 int n = cmdlist.num(); 00082 for (int i=0; i<n; i++) { 00083 runcommand(cmdlist[i]); 00084 } 00085 cmdlist.clear(); 00086 } 00087 00088 void CommandQueue::check_events() { 00089 for (int i=0; i<uilist.num(); i++) { 00090 UIObject *ui = uilist[i]; 00091 if (ui->active()) 00092 ui->check_event(); 00093 } 00094 } 00095 00096