Exemple #1
0
void Maemo::Timed::Event::setTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned minute)
{
  check_interval(__PRETTY_FUNCTION__, year, 1970, 2037) ;
  check_interval(__PRETTY_FUNCTION__, month, 1, 12) ;
  check_interval(__PRETTY_FUNCTION__, day, 1, broken_down_t::month_length(year,month)) ;
  check_interval(__PRETTY_FUNCTION__, hour, 0, 23) ;
  check_interval(__PRETTY_FUNCTION__, minute, 0, 59) ;
  p->eio.t_year = year ;
  p->eio.t_month = month ;
  p->eio.t_day = day ;
  p->eio.t_hour = hour ;
  p->eio.t_minute = minute ;
}
void CheckpointDaemon::run() {

  std::cout << "CheckpointDaemon started..." << std::endl;

  // bind to numa node
  bindCurrentThreadToNumaNode(0);

  struct timeval time_start, time_cur;
  unsigned long long elapsed_usec;
  gettimeofday(&time_start, NULL);
  std::chrono::milliseconds check_interval(500);

  while (_running) {

    std::this_thread::sleep_for(check_interval);

    gettimeofday(&time_cur, NULL);
    elapsed_usec = (time_cur.tv_sec * 1000000 + time_cur.tv_usec) - (time_start.tv_sec * 1000000 + time_start.tv_usec);

    if (elapsed_usec > _checkpointing_interval_in_ms * 1000) {
      doCheckpoint();
      time_start = time_cur;
    }
  }
}
Exemple #3
0
static
#endif
int run_timer_internal(
	const char *cname,
	struct sdirs *sdirs,
	struct strlist *timer_args,
	char *day_now,
	char *hour_now,
	time_t time_now
)
{
	int ret=-1;
	struct strlist *interval=NULL;
	struct strlist *timebands=NULL;
	char *ctimestamp=NULL;

	logp("Running timer for %s\n", cname);

	interval=timer_args;
	if(timer_args)
		timebands=timer_args->next;

	switch((ret=check_manual_file(sdirs, cname)))
	{
		case -1:
			goto end;
		case 0:
			goto end;
	}

	switch(check_timebands(day_now, hour_now, timebands))
	{
		case 0:
			ret=1;
			goto end;
		case -1: // Error;
			goto end;
	}

	if(is_dir_stat(sdirs->current)<=0)
	{
		logp("No prior backup of %s\n", cname);
		ret=0;
		goto end;
	}
	if(!(ctimestamp=prepend_s(sdirs->current, "timestamp")))
	{
		ret=-1;
		goto end;
	}

	ret=check_interval(interval, cname, ctimestamp, time_now);

end:
	free_w(&ctimestamp);
	switch(ret)
	{
		case 0:
			logp("Do a backup of %s now\n", cname);
			break;
		case 1:
			logp("Not yet time for a backup of %s\n", cname);
			break;
	}
	return ret;
}
Exemple #4
0
/*  take an action for the passed note. Enter/edit/check the score following the mode and keyboard state. */
static gint
midiaction (gint notenum)
{
  gboolean new_measure = Denemo.project->movement->cursoroffend;
  DenemoProject *gui = Denemo.project;
  if (gui == NULL)
    return TRUE;
  if (gui->movement == NULL)
    return TRUE;
  DenemoStaff *curstaffstruct = (DenemoStaff *) gui->movement->currentstaff->data;
  enharmonic enote, prevenote;
  gboolean have_previous;
  //g_print("midiaction Adding mask %x, Chord mask %x\n", (Denemo.keyboard_state & ADDING_MASK) , (Denemo.keyboard_state & CHORD_MASK));
  notenum2enharmonic (notenum, &enote.mid_c_offset, &enote.enshift, &enote.octave);
  if (Denemo.project->movement->cursor_appending)
    have_previous = get_current (&prevenote);
  else
    have_previous = get_previous (&prevenote);

  if (!(Denemo.keyboard_state & CHECKING_MASK))
    stage_undo (gui->movement, ACTION_STAGE_END);     //undo is a queue so this is the end :)

  if ((gui->mode & INPUTEDIT) || (Denemo.keyboard_state & CHECKING_MASK))
    {
      static gboolean beep = FALSE;
      gboolean is_tied = FALSE;
      gint measure = gui->movement->currentmeasurenum;
      if (Denemo.project->movement->currentobject)
        {
          DenemoObject *curObj = Denemo.project->movement->currentobject->data;
          if (curObj->type == CHORD)
            {
              do
                {
                  curObj = Denemo.project->movement->currentobject->data;
                  chord *thechord = (chord *) curObj->object;
                  is_tied = (!Denemo.prefs.ignore_ties) && thechord->is_tied;

//#define check_midi_note(a,b,c,d) ((a->mid_c_offset==b)&&(a->enshift==c))?playnote(a,curstaffstruct->midi_channel):gdk_beep();
                  if ((Denemo.keyboard_state & CHECKING_MASK) && thechord->notes)
                    {
                      //later - find note nearest cursor and
                      note *thenote = (note *) thechord->notes->data;
//            check_midi_note(thenote, enote.mid_c_offset + 7 *(enote.octave), enote.enshift, enote.octave);
                      if ((!curObj->isinvisible) && (thenote->mid_c_offset == (enote.mid_c_offset + 7 * (enote.octave))) && (thenote->enshift == enote.enshift))
                        {
                          gint midi = dia_to_midinote (thenote->mid_c_offset) + thenote->enshift;
                          play_note (DEFAULT_BACKEND, 0 /*port */ , curstaffstruct->midi_channel, midi, 300 /*duration */ , 0);
                        }
                      else
                        {
                          gdk_beep ();
                          break;        //do not move on to next note
                        }
                    }
                  else
                    {

                      do_one_note (enote.mid_c_offset, enote.enshift, enote.octave);

                    }
                  if (Denemo.project->movement->cursor_appending)
                    break;
                    curObj = Denemo.project->movement->currentobject->data;
                    thechord = (chord *) curObj->object;
                    is_tied = (!Denemo.prefs.ignore_ties) && thechord->is_tied;
                }
              while ((!(Denemo.keyboard_state & ADDING_MASK)) && next_editable_note () && is_tied);
            }
          else //there is a current object that is not a chord
            {
              if (gui->movement->cursor_appending)
                {
                    do_one_note (enote.mid_c_offset, enote.enshift, enote.octave);
                    next_insert_or_editable_note();
                    //in some circumstance this fails to advance to the next editable note, the following checks for that.
                    if (Denemo.project->movement->currentobject)
                        {
                            curObj = Denemo.project->movement->currentobject->data;
                            if(!curObj->isinvisible)
                               next_editable_note ();
                        }
                }
              else
                gdk_beep ();
            }
          if (gui->mode & INPUTRHYTHM)
            {
              //g_print("measure was %d now %d with appending %d\n", measure, gui->movement->currentmeasurenum, gui->movement->cursor_appending);
              if (!beep && (measure != gui->movement->currentmeasurenum) && !gui->movement->cursor_appending)
                beep = TRUE;
              else if (beep)
                signal_measure_end (), beep = FALSE;
            }
        }
      else
        {                       // no current object
          do_one_note (enote.mid_c_offset, enote.enshift, enote.octave);
          next_insert_or_editable_note();//next_editable_note ();//if we have gone back from an empty measure we need this.
        }
    }
  else
    {                           // not INPUTEDIT
      action_note_into_score (enote.mid_c_offset, enote.enshift, enote.octave);
    }
  if (!(Denemo.keyboard_state & CHECKING_MASK))
    {
      stage_undo (gui->movement, ACTION_STAGE_START);
    }
  draw_score_area();     //just for advancing the cursor.
  if (!(Denemo.keyboard_state & CHECKING_MASK))
    {
      if (Denemo.prefs.immediateplayback)
        {
          gint channel = curstaffstruct->midi_channel;

          if (have_previous && check_interval (enote.mid_c_offset, enote.enshift, prevenote.mid_c_offset, prevenote.enshift))
            channel = Denemo.prefs.pitchspellingchannel;

          play_note (DEFAULT_BACKEND, 0 /*port */ , channel, notenum, 300 /*duration */ , 0);
          if(new_measure)
            signal_measure_end();
        }
    }

  return TRUE;
}
static PyObject *
SearchResults_cumulative_score_row(SearchResults *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[] = {"row", "min_score", "max_score", "interval", NULL};
  int row=-1;
  PyObject *min_score_obj=Py_None, *max_score_obj=Py_None;
  double min_score=0.0, max_score=1.0;
  int num_hits;
  double *scores;
  int include_min=0, include_max=0;
  double score=0.0;
  int i;
  const char *interval = "[]";
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|OOs:cumulative_score_row", kwlist,
                                   &row, &min_score_obj, &max_score_obj, &interval)) {
    return NULL;
  }
  if (!check_row(self->num_results, &row) ||
      !check_min_max_score(min_score_obj, max_score_obj, &min_score, &max_score) ||
      !check_interval(interval, &include_min, &include_max)) {
    return NULL;
  }
  num_hits = chemfp_get_num_hits(self->results+row);
  scores = (self->results+row)->scores;

  if ((min_score > max_score) ||
      (min_score == max_score && (!include_min || !include_max))) {
    return PyFloat_FromDouble(0.0);
  }

  if (include_min) {
    if (include_max) {
      /* [] -- Include both ends */
      if (min_score_obj == Py_None) {
        if (max_score_obj == Py_None) {
          CUMULATIVE_SCORE_ROW_MACRO(1);
        } else {
          /* No lower bound */
          CUMULATIVE_SCORE_ROW_MACRO(scores[i] <= max_score);
        }
      } else {
        if (max_score_obj == Py_None) {
          /* Lower bound but no upper bound */
          CUMULATIVE_SCORE_ROW_MACRO(min_score <= scores[i]);
        } else {
          /* Definite lower and upper bound */
          CUMULATIVE_SCORE_ROW_MACRO(min_score <= scores[i] && scores[i] <= max_score);
        }
      }
    } else {
      /* [) -- Include the minimum but not the maximum */
      if (min_score_obj == Py_None) {
        /* There is no minimum */
        CUMULATIVE_SCORE_ROW_MACRO(scores[i] < max_score);
      } else {
        /* There is a minimum and a maximum test */
        CUMULATIVE_SCORE_ROW_MACRO(min_score <= scores[i] && scores[i] < max_score);
      }
    }
  } else {
    if (include_max) {
      /* (] -- Exclude the minimum, include the maximum */
      if (max_score_obj == Py_None) {
        /* No specified max, so must only be greater than the lower bound */
        CUMULATIVE_SCORE_ROW_MACRO(min_score < scores[i]);
      } else {
        CUMULATIVE_SCORE_ROW_MACRO(min_score < scores[i] && scores[i] <= max_score);
      }
    } else {
      /* () -- Exclude the minimum and exclude the maximum */
      CUMULATIVE_SCORE_ROW_MACRO(min_score < scores[i] && scores[i] < max_score);
    }
  }
  return PyFloat_FromDouble(score);
}
static PyObject *
SearchResults_count_all(SearchResults *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[] = {"min_score", "max_score", "interval", NULL};
  int row=-1;
  PyObject *min_score_obj=Py_None, *max_score_obj=Py_None;
  double min_score=0.0, max_score=1.0;
  int num_hits, num_rows;
  double *scores;
  int include_min=0, include_max=0;
  int count=0;
  int i;
  const char *interval = "[]";
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOs:count_all", kwlist,
                                   &min_score_obj, &max_score_obj, &interval)) {
    return NULL;
  }
  if (!check_min_max_score(min_score_obj, max_score_obj, &min_score, &max_score) ||
      !check_interval(interval, &include_min, &include_max)) {
    return NULL;
  }
  if ((min_score > max_score) ||
      (min_score == max_score && !(include_min && include_max))) {
    return PyInt_FromLong(0);
  }

  num_rows = self->num_results;
  if (include_min) {
    if (include_max) {
      /* [] -- Include both ends */
      if (min_score_obj == Py_None) {
        if (max_score_obj == Py_None) {
          /* Special case; just report the number of elements */
          for (row=0; row<num_rows; row++) {
            count += chemfp_get_num_hits(self->results+row);
          }
        } else {
          /* No lower bound */
          COUNT_ALL_MACRO(scores[i] <= max_score);
        }
      } else {
        if (max_score_obj == Py_None) {
          /* Lower bound but no upper bound */
          COUNT_ALL_MACRO(min_score <= scores[i]);
        } else {
          /* Definite lower and upper bound */
          COUNT_ALL_MACRO(min_score <= scores[i] && scores[i] <= max_score);
        }
      }
    } else {
      /* [) -- Include the minimum but not the maximum */
      if (min_score_obj == Py_None) {
        /* There is no minimum */
        COUNT_ALL_MACRO(scores[i] < max_score);
      } else {
        /* There is a minimum and a maximum test */
        COUNT_ALL_MACRO(min_score <= scores[i] && scores[i] < max_score);
      }
    }
  } else {
    if (include_max) {
      /* (] -- Exclude the minimum, include the maximum */
      if (max_score_obj == Py_None) {
        /* No specified max, so must only be greater than the lower bound */
        COUNT_ALL_MACRO(min_score < scores[i]);
      } else {
        COUNT_ALL_MACRO(min_score < scores[i] && scores[i] <= max_score);
      }
    } else {
      /* () -- Exclude the minimum and exclude the maximum */
      COUNT_ALL_MACRO(min_score < scores[i] && scores[i] < max_score);
    }
  }
  return PyInt_FromLong(count);
}
Exemple #7
0
 void Event::Recurrence::removeMinute(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 59) ;
   p->rio()->mins &= ~(1ull << x) ;
 }
Exemple #8
0
 void Event::Recurrence::addMinute(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 59) ;
   p->rio()->mins |= 1ull << x ;
 }
Exemple #9
0
 void Event::Recurrence::removeHour(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 23) ;
   p->rio()->hour &= ~(1u << x) ;
 }
Exemple #10
0
 void Event::Recurrence::addHour(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 23) ;
   p->rio()->hour |= 1u << x ;
 }
Exemple #11
0
 void Event::Recurrence::removeDayOfWeek(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 7) ;
   p->rio()->wday &= ~(1u << (x==7 ? 0 : x)) ;
 }
Exemple #12
0
 void Event::Recurrence::addDayOfWeek(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 0, 7) ;
   p->rio()->wday |= 1u << (x==7 ? 0 : x) ;
 }
Exemple #13
0
 void Event::Recurrence::removeDayOfMonth(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 1, 31) ;
   p->rio()->mday &= ~(1u << x) ;
 }
Exemple #14
0
 void Event::Recurrence::addDayOfMonth(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 1, 31) ;
   p->rio()->mday |= 1u << x ;
 }
Exemple #15
0
 void Event::Recurrence::removeMonth(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 1, 12) ;
   p->rio()->mons &= ~(1u << (x-1)) ;
 }
Exemple #16
0
 void Event::Recurrence::addMonth(int x)
 {
   check_interval(__PRETTY_FUNCTION__, x, 1, 12) ;
   p->rio()->mons |= 1u << (x-1) ;
 }