Пример #1
0
static int data_source_filepoll(void * vinstance, wsdata_t* source_data,
                                ws_doutput_t * dout, int type_index) {

     proc_instance_t * proc = (proc_instance_t*)vinstance;
     
     if (!proc->fp) {
          time_t tnext = local_get_time();
          if (tnext > proc->next_time) {
               dprint("time %d %d %d", (int)tnext, (int)proc->next_time, (int)proc->poll_duration);
               proc->fp = gzopen(proc->poll_filename, "r");
               proc->next_time = tnext + proc->poll_duration;
          }
     }

     if (proc->fp) {
          if (poll_file(proc, source_data)) {
               wsdt_tuple_t * tuple = (wsdt_tuple_t*)source_data->data;
               if (tuple->len) {
                    ws_set_outdata(source_data, proc->outtype_tuple, dout);
               }
          }
     }

     return 1;
}
Пример #2
0
// The following is a function to take in command arguments and initalize
// this processor's instance, and is called only once for each instance of this
// processor.
// also register as a source here..
// return 1 if ok
// return 0 if fail
int proc_init(wskid_t * kid, int argc, char ** argv, void ** vinstance, 
              ws_sourcev_t * sv, void * type_table) {

     //allocate proc instance of this processor
     proc_instance_t * proc =
          (proc_instance_t*)calloc(1,sizeof(proc_instance_t));
     *vinstance = proc;

     // initialize flags and variables
     proc->delim = strdup(","); // default delimiter
     proc->in = stdin; // default input source
     proc->type_table = type_table; // for inline label lookup
     proc->do_poll = 0; // false
     proc->poll_duration = 60; // default duration for polling a file

     //read in command options
     if (!proc_cmd_options(argc, argv, proc, type_table)) {
          return 0;
     }

     // TODO: If no input stream is given, we should gracefully exit ...
     
     // register sources, set output types
     if (proc->do_poll) { // file will be polled for events
          proc->outtype_tuple =
               ws_register_source_byname(type_table, "TUPLE_TYPE",
                                         data_source_filepoll, sv);
          proc->next_time = local_get_time() + proc->poll_duration;
     }
     else { // not polling file
          if (proc->straight_data) { // getting events from stdin
               int fd = fileno(proc->in); // int descriptor of stdin stream
               proc->fp = gzdopen(fd, "r"); // associates stdin with gzFile object
          }
          else { // reading from list of file names
               if (!local_scour_stdin(proc)) {
                    error_print("no input file to start with");
                    return 0;
               }
          } // TODO: Include ability to read directly from a single csv file

          if ( proc->preload ) {
               proc->outtype_tuple =
                    ws_register_source_byname(type_table, "TUPLE_TYPE", data_source_preload, sv);
          } else {
               proc->outtype_tuple = 
                    ws_register_source_byname(type_table, "TUPLE_TYPE", data_source, sv);
          }
     }

     if (!proc->outtype_tuple) {
          fprintf(stderr, "registration failed\n");
          return 0;
     }

     return 1; 
}
Пример #3
0
tap_ev
test_tap_ev_queue_shift_wait(tap_ev_queue queue, ev_tstamp seconds)
{
    tap_ev event;
    SXE_TIME deadline;
    SXE_TIME current;
    SXE_TIME wait_time;

    wait_time = SXE_TIME_FROM_DOUBLE_SECONDS(seconds);
    event     = tap_ev_queue_shift(queue);

    /* If the tap event queue was not empty, return the event.
     */
    if (event != NULL) {
        return event;
    }

    deadline = local_get_time() + wait_time;

    for (;;) {
        test_ev_loop_wait(SXE_TIME_TO_DOUBLE_SECONDS(wait_time));
        event = tap_ev_queue_shift(queue);

        if (event != NULL) {
            return event;
        }

        current = local_get_time();

        if (current >= deadline) {
            return NULL;
        }

        wait_time = deadline - current;
    }
}
Пример #4
0
static gboolean clock_callback(gpointer data)
{
  struct tm tm;
  char date[256];
  char tz[64];
  const char *next;

  time_t t = local_get_time();
  localtime_r(&t, &tm);

  *tz = 0;
  ticker_get_timezone(tz, sizeof tz);

  next = timeto(next_alarm, t);

#if 0
  snprintf(date, sizeof date,
           "%04d-%02d-%02d %02d:%02d:%02d %s %s",
           tm.tm_year + 1900,
           tm.tm_mon + 1,
           tm.tm_mday,
           tm.tm_hour,
           tm.tm_min,
           tm.tm_sec,
           tz, next);
#else
  snprintf(date, sizeof date,
           "%02d-%02d-%02d %02d:%02d:%02d %s %s",
           tm.tm_year % 100,
           tm.tm_mon + 1,
           tm.tm_mday,
           tm.tm_hour,
           tm.tm_min,
           tm.tm_sec,
           tz, next);

#endif
  if( clock_label != 0 )
  {
    gtk_label_set_text(GTK_LABEL(clock_label), date);
  }
  return TRUE;
}
Пример #5
0
static gboolean queue_rescan_callback(void *data)
{
  //log_append("@ %s()\n", __FUNCTION__);

  cookie_t *vec = 0;
  alarm_event_t *eve = 0;

  queue_clear();

  if( (vec = alarmd_event_query(0,0, 0,0, 0)) )
  {
    for( int i = 0; vec[i] > 0; ++i )
    {
      if( (eve = alarmd_event_get(vec[i])) )
      {
        char tdate[256];
        char adate[256];
        char tz[256];
        char trigger[256];

        struct tm tm;
        time_t t = local_get_time();

        *adate = *tz = 0;

        ticker_get_timezone(tz, sizeof tz);
        ticker_get_remote(eve->trigger, tz, &tm);
        snprintf(tdate, sizeof tdate,
                 //"%04d-%02d-%02d %02d:%02d:%02d %s (%s)",
                 //tm.tm_year + 1900,
                 "%02d-%02d-%02d %02d:%02d:%02d %s (%s)",
                 tm.tm_year % 100,
                 tm.tm_mon + 1,
                 tm.tm_mday,
                 tm.tm_hour,
                 tm.tm_min,
                 tm.tm_sec,
                 tz,
                 timeto(eve->trigger, t));

        if( *eve->alarm_tz != 0 )
        {
          ticker_get_remote(eve->trigger, eve->alarm_tz, &tm);
          snprintf(adate, sizeof adate,
                   "\n"
                   //"%04d-%02d-%02d %02d:%02d:%02d %s",
                   //tm.tm_year + 1900,
                   "%02d-%02d-%02d %02d:%02d:%02d %s",
                   tm.tm_year % 100,
                   tm.tm_mon + 1,
                   tm.tm_mday,
                   tm.tm_hour,
                   tm.tm_min,
                   tm.tm_sec,
                   eve->alarm_tz);
        }

        snprintf(trigger, sizeof trigger, "%c %s%s",
                 (eve->flags & ALARM_EVENT_DISABLED) ? 'D' : 'E',
                 tdate, adate);

        queue_append(eve->cookie,
                     trigger,
                     eve->recur_count,
                     eve->title,
                     eve->message);
        alarm_event_delete(eve);
      }

    }
    free(vec);
  }

  rescan_id = 0;
  return FALSE;
}