コード例 #1
0
ファイル: machine.cpp プロジェクト: deztructor/timed
void machine_t::process_transition_queue()
{
  if(transition_in_progress())
  {
    log_debug("process_transition_queue() is already in progress, returning") ;
    return ; // never do it recursively
  }
  // log_debug("begin processing, states: %s tqueue: %s" , s_states().c_str(), s_transition_queue().c_str()) ;
  transition_start_time = ticker_t(now()) ;
  bool queue_changed = false ;
  for(; not transition_queue.empty(); queue_changed = true, transition_queue.pop_front())
  {
#define state_name(p) (p?p->name():"null")
    event_t *e = transition_queue.front().first ;
    abstract_state_t *new_state = transition_queue.front().second ;
    if (not is_event_registered(e))
    {
      log_error("requested to move destroyed event %p to state '%s'", e, state_name(new_state)) ;
      continue ;
    }
    abstract_state_t *old_state = e->get_state() ;
    log_notice("State transition %d:'%s'->'%s'", e->cookie.value(), state_name(old_state), state_name(new_state)) ;
    if (new_state==old_state)
      log_critical("Event %d: new_state=old_state='%s'", e->cookie.value(), old_state->name()) ;
#undef state_name
    if(old_state)
      old_state->leave(e) ;
    e->set_state(new_state) ;
    if(new_state)
    {
      new_state->enter(e) ;
      e->sort_and_run_actions(new_state->get_action_mask()) ;
    }
    else
    {
      log_notice("Destroying the event %u (event object %p)", e->cookie.value(), e) ;
      unregister_event(e) ;
      delete e ;
    }
  }
  // log_debug("processing done,  states: %s tqueue: %s" , s_states().c_str(), s_transition_queue().c_str()) ;
  transition_start_time = ticker_t(0) ;
  transition_time_adjustment.set(0) ;
  if(queue_changed)
    emit queue_to_be_saved() ;
  if(context_changed)
    send_queue_context() ;
  send_bootup_signal() ;
}
コード例 #2
0
ファイル: timed.cpp プロジェクト: special/timed
void Timed::init_create_event_machine()
{
  am = new machine_t(this) ;
  log_debug("am=new machine done") ;
  q_pause = NULL ;

  // The following call is commented out: device mode will be known later
#if 0
  am->device_mode_detected(not act_dead_mode) ; // TODO: avoid "not" here
#endif

  short_save_threshold_timer = new simple_timer(threshold_period_short) ;
  long_save_threshold_timer = new simple_timer(threshold_period_long) ;
  QObject::connect(short_save_threshold_timer, SIGNAL(timeout()), this, SLOT(queue_threshold_timeout())) ;
  QObject::connect(long_save_threshold_timer, SIGNAL(timeout()), this, SLOT(queue_threshold_timeout())) ;

  QObject::connect(am, SIGNAL(child_created(unsigned,int)), this, SLOT(register_child(unsigned,int))) ;
  clear_invokation_flag() ;

  ping = new pinguin_t(ping_period, ping_max_num, this) ;
  QObject::connect(am, SIGNAL(voland_needed()), ping, SLOT(voland_needed())) ;
  QObject::connect(this, SIGNAL(voland_registered()), ping, SLOT(voland_registered())) ;

  QObject::connect(am, SIGNAL(queue_to_be_saved()), this, SLOT(event_queue_changed())) ;

#if 0
  QDBusConnectionInterface *bus_ifc = Maemo::Timed::Voland::bus().interface() ;

  voland_watcher = new QDBusServiceWatcher((QString)Maemo::Timed::Voland::service(), Maemo::Timed::Voland::bus()) ;
  QObject::connect(voland_watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), this, SLOT(system_owner_changed(QString,QString,QString))) ;
#else
  voland_watcher = NULL ;
#endif
  QObject::connect(this, SIGNAL(voland_registered()), am, SIGNAL(voland_registered())) ;
  QObject::connect(this, SIGNAL(voland_unregistered()), am, SIGNAL(voland_unregistered())) ;

#if 0
  bool voland_present = bus_ifc->isServiceRegistered(Maemo::Timed::Voland::service()) ;

  if(voland_present)
  {
    log_info("Voland service %s detected", Maemo::Timed::Voland::service()) ;
    emit voland_registered() ;
  }
#endif
}