Example #1
0
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
}
Example #2
0
void Timed::system_owner_changed(const QString &name, const QString &oldowner, const QString &newowner)
{
  log_debug() ;
  bool name_match = name==Maemo::Timed::Voland::service() ;
  if(name_match && oldowner.isEmpty() && !newowner.isEmpty())
    emit voland_registered() ;
  else if(name_match && !oldowner.isEmpty() && newowner.isEmpty())
    emit voland_unregistered() ;
#define __qstr(a) (a.isEmpty()?"<empty>":a.toStdString().c_str())
  if(name_match)
    log_info("Service %s owner changed from %s to %s", __qstr(name), __qstr(oldowner), __qstr(newowner)) ;
  else
    log_error("expecing notification about '%s' got about '%s'", Maemo::Timed::Voland::service(), name.toStdString().c_str()) ;
#undef __qstr
}
Example #3
0
machine_t::machine_t(const Timed *daemon) : timed(daemon)
{
  log_debug() ;
  // T = transition state
  // IO = waiting for i/o state
  // G = gate state
  // C = concentrating gate state
  // F = filtering state
  // A = actions allowed
  // -->NEW loaded as new
  // -->DUE loaded as due
  abstract_state_t *S[] =
  {
    state_start = new state_start_t(this),                     // T
    state_epoch = new state_epoch_t(this),                     // T
    state_waiting = new state_waiting_t(this),                 // IO G
    state_new = new state_new_t(this),                         // T
    state_scheduler = new state_scheduler_t(this),             // T
    state_qentry = new state_qentry_t(this),                   // T
    state_flt_conn = new state_flt_conn_t(this),               // IO G F -->NEW
    state_flt_alrm = new state_flt_alrm_t(this),               // IO G F -->NEW
    state_flt_user = new state_flt_user_t(this),               // IO G F -->NEW
    state_queued = new state_queued_t(this),                   // IO A   -->NEW

    state_due = new state_due_t(this),                         // T

    state_missed = new state_missed_t(this),                   // T A
    state_skipped = new state_skipped_t(this),                 // T

    state_armed = new state_armed_t(this),                     // IO G
    state_triggered = new state_triggered_t(this),             // T A

    state_dlg_wait = new state_dlg_wait_t(this),               // IO G   -->DUE
    state_dlg_cntr = new state_dlg_cntr_t(this),               // IO C   -->DUE
    state_dlg_requ = new state_dlg_requ_t(this),               // IO G   -->DUE
    state_dlg_user = new state_dlg_user_t(this),               // IO G   -->DUE
    state_dlg_resp = new state_dlg_resp_t(this),               // T

   /* state_buttons: below */                                  // T A

    state_snoozed = new state_snoozed_t(this),                 // T
    state_recurred = new state_recurred_t(this),               // T
    state_served = new state_served_t(this),                   // T
    state_tranquil = new state_tranquil_t(this),               // IO A -->DUE

    state_removed = new state_removed_t(this),                 // T
    state_aborted = new state_aborted_t(this),                 // T
    state_finalized = new state_finalized_t(this),             // T A
    NULL
  } ;
  log_debug() ;
  for(int i=0; S[i]; ++i)
    states.insert(S[i]) ;

  log_debug() ;
  for(int i=0; i<=Maemo::Timed::Number_of_Sys_Buttons; ++i)
    states.insert(buttons[-i] = new state_button_t(this, -i)) ;

  log_debug() ;
  for(int i=1; i<=Maemo::Timed::Max_Number_of_App_Buttons; ++i)
    states.insert(buttons[i] = new state_button_t(this, i)) ;

  for (set<abstract_state_t*>::iterator it=states.begin(); it!=states.end(); ++it)
    (*it)->resolve_names() ;

  log_debug() ;
  state_triggered->set_action_mask(ActionFlags::State_Triggered) ;
  state_queued->set_action_mask(ActionFlags::State_Queued) ;
  state_missed->set_action_mask(ActionFlags::State_Missed) ;
  state_tranquil->set_action_mask(ActionFlags::State_Tranquil) ;
  state_finalized->set_action_mask(ActionFlags::State_Finalized) ;
  state_due->set_action_mask(ActionFlags::State_Due) ;
  state_snoozed->set_action_mask(ActionFlags::State_Snoozed) ;
  state_served->set_action_mask(ActionFlags::State_Served) ;
  state_aborted->set_action_mask(ActionFlags::State_Aborted) ;
  // states_failed->set_action_mask(ActionFlags::State_Failed) ;

#if 0
  log_debug() ;
  io_state *queued = dynamic_cast<io_state*> (states["QUEUED"]) ;
  log_assert(queued!=NULL) ;

  gate_state *armed = dynamic_cast<gate_state*> (states["ARMED"]) ;
  log_assert(armed!=NULL) ;
  armed->open() ; // will be closed in some very special situations

  log_debug() ;
  gate_state *dlg_wait = dynamic_cast<gate_state*> (states["DLG_WAIT"]) ;
  gate_state *dlg_requ = dynamic_cast<gate_state*> (states["DLG_REQU"]) ;
  gate_state *dlg_user = dynamic_cast<gate_state*> (states["DLG_USER"]) ;
  gate_state *dlg_cntr = dynamic_cast<gate_state*> (states["DLG_CNTR"]) ;
  log_assert(dlg_wait!=NULL) ;
  log_assert(dlg_requ!=NULL) ;
  log_assert(dlg_user!=NULL) ;
  log_assert(dlg_cntr!=NULL) ;
#endif

  state_armed->open() ;

  QObject::connect(state_dlg_wait, SIGNAL(voland_needed()), this, SIGNAL(voland_needed())) ;

  QObject::connect(state_dlg_wait, SIGNAL(closed()), state_dlg_requ, SLOT(open())) ;
  QObject::connect(state_dlg_wait, SIGNAL(closed()), state_dlg_user, SLOT(open())) ;
  QObject::connect(state_dlg_requ, SIGNAL(closed()), state_dlg_wait, SLOT(open())) ;

  QObject::connect(this, SIGNAL(voland_registered()), state_dlg_requ, SLOT(close())) ;
  QObject::connect(this, SIGNAL(voland_registered()), state_dlg_user, SLOT(close())) ;
  QObject::connect(this, SIGNAL(voland_unregistered()), state_dlg_wait, SLOT(close())) ;
  QObject::connect(this, SIGNAL(voland_unregistered()), state_dlg_cntr, SLOT(send_back())) ;

  QObject::connect(state_queued, SIGNAL(sleep()), state_dlg_cntr, SLOT(open()), Qt::QueuedConnection) ;
  QObject::connect(state_dlg_wait, SIGNAL(opened()), state_dlg_cntr, SLOT(open()), Qt::QueuedConnection) ;

#if 0
  log_debug() ;
  filter_state *flt_conn = dynamic_cast<filter_state*> (states["FLT_CONN"]) ;
  filter_state *flt_alrm = dynamic_cast<filter_state*> (states["FLT_ALRM"]) ;
  filter_state *flt_user = dynamic_cast<filter_state*> (states["FLT_USER"]) ;
  log_assert(flt_conn) ;
  log_assert(flt_alrm) ;
  log_assert(flt_user) ;
#endif

  QObject::connect(state_flt_conn, SIGNAL(closed(abstract_filter_state_t*)), state_queued, SLOT(filter_closed(abstract_filter_state_t*))) ;
  QObject::connect(state_flt_alrm, SIGNAL(closed(abstract_filter_state_t*)), state_queued, SLOT(filter_closed(abstract_filter_state_t*))) ;
  QObject::connect(state_flt_user, SIGNAL(closed(abstract_filter_state_t*)), state_queued, SLOT(filter_closed(abstract_filter_state_t*))) ;

  log_debug() ;
  QObject::connect(this, SIGNAL(engine_pause(int)), state_queued, SLOT(engine_pause(int))) ;
  log_debug() ;
  initial_pause = new pause_t(this) ;
  log_debug() ;

  cluster_queue = new cluster_queue_t(this) ;
  log_debug() ;
  clusters[cluster_queue->bit] = cluster_queue ;
  log_debug() ;

  cluster_dialog = new cluster_dialog_t(this) ;
  log_debug() ;
  clusters[cluster_dialog->bit] = cluster_dialog ;
  log_debug() ;
  signalled_bootup = -1 ; // no signal sent yet
  signalled_non_boot_event = -1;
  log_debug() ;

  log_debug("machine->settings->alarms_are_enabled=%d", timed->settings->alarms_are_enabled) ;
  log_debug() ;
  alarm_gate(timed->settings->alarms_are_enabled) ;
  log_debug() ;

  transition_start_time = ticker_t(0) ;
  transition_time_adjustment.set(0) ;
  log_debug() ;
  next_cookie = 1 ;
  log_debug() ;
  context_changed = false ;
  log_debug("last line") ;
}