Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionQueue.cpp

    r29b52b r11d433  
    5555using namespace MoleCuilder;
    5656
    57 const Action* ActionQueue::_lastchangedaction = NULL;
    58 
    5957ActionQueue::ActionQueue() :
    60     Observable("ActionQueue"),
    6158    AR(new ActionRegistry()),
    6259    history(new ActionHistory),
     
    6966    run_thread_isIdle(true)
    7067#endif
    71 {
    72   // channels of observable
    73   Channels *OurChannel = new Channels;
    74   NotificationChannels.insert( std::make_pair(static_cast<Observable *>(this), OurChannel) );
    75   // add instance for each notification type
    76   for (size_t type = 0; type < NotificationType_MAX; ++type)
    77     OurChannel->addChannel(type);
    78 }
     68{}
    7969
    8070ActionQueue::~ActionQueue()
     
    8474#endif
    8575
    86   // free all actions contained in actionqueue
    87   for (ActionQueue_t::iterator iter = actionqueue.begin(); !actionqueue.empty(); iter = actionqueue.begin()) {
    88     delete *iter;
    89     actionqueue.erase(iter);
    90   }
     76  clearQueue();
    9177
    9278  delete history;
     
    9682void ActionQueue::queueAction(const std::string &name, enum Action::QueryOptions state)
    9783{
    98   queueAction(AR->getActionByName(name), state);
    99 }
    100 
    101 void ActionQueue::queueAction(Action *_action, enum Action::QueryOptions state)
    102 {
    103   OBSERVE;
    104   NOTIFY(ActionQueued);
     84  const Action * const registryaction = AR->getActionByName(name);
     85  queueAction(registryaction, state);
     86}
     87
     88void ActionQueue::queueAction(const Action * const _action, enum Action::QueryOptions state)
     89{
    10590  Action *newaction = _action->clone(state);
    10691  newaction->prepare(state);
     
    116101    std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
    117102    World::getInstance().setExitFlag(5);
    118     actionqueue.clear();
    119     tempqueue.clear();
     103    clearQueue();
     104    lastActionOk = false;
     105    std::cerr << "ActionQueue cleared." << std::endl;
     106  } catch (std::exception &e) {
     107    pushStatus("FAIL: General exception caught, aborting.");
     108    World::getInstance().setExitFlag(134);
     109    clearQueue();
    120110    lastActionOk = false;
    121111    std::cerr << "ActionQueue cleared." << std::endl;
     
    128118  mtx_queue.unlock();
    129119#endif
    130   _lastchangedaction = newaction;
    131120}
    132121
     
    180169        pushStatus("FAIL: Action "+*boost::get_error_info<ActionNameString>(e)+" has failed.");
    181170        World::getInstance().setExitFlag(5);
    182         actionqueue.clear();
    183         tempqueue.clear();
     171        clearQueue();
    184172        lastActionOk = false;
     173        std::cerr << "ActionQueue cleared." << std::endl;
     174        CurrentAction = (size_t)-1;
     175      } catch (std::exception &e) {
     176        pushStatus("FAIL: General exception caught, aborting.");
     177        World::getInstance().setExitFlag(134);
     178        clearQueue();
    185179        std::cerr << "ActionQueue cleared." << std::endl;
    186180        CurrentAction = (size_t)-1;
     
    302296}
    303297
     298void ActionQueue::clearQueue()
     299{
     300  // free all actions contained in actionqueue
     301  for (ActionQueue_t::iterator iter = actionqueue.begin();
     302      !actionqueue.empty(); iter = actionqueue.begin()) {
     303    delete *iter;
     304    actionqueue.erase(iter);
     305  }
     306  // free all actions contained in tempqueue
     307  for (ActionQueue_t::iterator iter = tempqueue.begin();
     308      !tempqueue.empty(); iter = tempqueue.begin()) {
     309    delete *iter;
     310    tempqueue.erase(iter);
     311  }
     312}
    304313
    305314const ActionQueue::ActionTokens_t ActionQueue::getListOfActions() const
Note: See TracChangeset for help on using the changeset viewer.