static void x_main_loop(void *data) { struct capture_data cam_data; printf("%s:%d\n", __FUNCTION__, __LINE__); // init capture cam_data.w = 320; cam_data.h = 240; cam_data.vfd = v4l2_capture_init(&cam_data.framebuf, &cam_data.w, &cam_data.h); gobee_theora_resize(cam_data.w, cam_data.h, cam_data.w, sock, (struct sockaddr *) &cli, sizeof(cli)); io_loop = ev_default_loop(EVFLAG_AUTO); xgl_qwartz.data = data; printf("%s:%d\n", __FUNCTION__, __LINE__); write(1, "qwe\n", sizeof("qwe\n")); ev_periodic_init(&xgl_qwartz, __session_periodic_cb, 0., 0.0333, 0); ev_periodic_start(io_loop, &xgl_qwartz); cam_qwartz.data = &cam_data; ev_periodic_init(&cam_qwartz, __capture_periodic_cb, 0., 0.06667, 0); ev_periodic_start(io_loop, &cam_qwartz); ev_loop(io_loop, 0); }
/** * @brief Resume (or start) an RTP session * * @param session_gen The session to resume or start * @param range_gen Pointer tp @ref RTSP_Range to start with * * @todo This function should probably take care of starting eventual * libev events when the scheduler is replaced. * * This function is used by the PLAY method of RTSP to start or resume * a session; since a newly-created session starts as paused, this is * the only method available. * * The use of a pointer to double rather than a double itself is to * make it possible to pass this function straight to foreach * functions from glib. * * @internal This function should only be called from g_slist_foreach. */ static void rtp_session_resume(gpointer session_gen, gpointer range_gen) { RTP_session *session = (RTP_session*)session_gen; RTSP_Range *range = (RTSP_Range*)range_gen; fnc_log(FNC_LOG_VERBOSE, "Resuming session %p\n", session); session->range = range; session->start_seq = 1 + session->seq_no; session->start_rtptime = g_random_int(); session->send_time = 0.0; session->last_packet_send_time = time(NULL); /* Create the new thread pool for the read requests */ session->fill_pool = g_thread_pool_new(rtp_session_fill_cb, session, 1, true, NULL); /* Prefetch frames */ rtp_session_fill(session); ev_periodic_set(&session->transport.rtp_writer, range->playback_time - 0.05, 0, NULL); ev_periodic_start(session->srv->loop, &session->transport.rtp_writer); ev_io_start(session->srv->loop, &session->transport.rtcp_reader); }
int main(void) { int max_queue = 128; struct sock_ev_serv server; struct ev_periodic every_few_seconds; // Create our single-loop for this single-thread application EV_P = ev_default_loop(0); // Create unix socket in non-blocking fashion server_init(&server, "/tmp/libev-ipc-daemon.sock", max_queue); // To be sure that we aren't actually blocking ev_periodic_init(&every_few_seconds, not_blocked, 0, 5, 0); ev_periodic_start(EV_A_ &every_few_seconds); // Get notified whenever the socket is ready to read ev_io_init(&server.io, server_cb, server.fd, EV_READ); ev_io_start(EV_A_ &server.io); // Run our loop, ostensibly forever puts("unix-socket-echo starting...\n"); ev_loop(EV_A_ 0); // This point is only ever reached if the loop is manually exited close(server.fd); return EXIT_SUCCESS; }
int periodic_interval_time_test(void) { char timeStr[128] = {0}; char timeInter[128] = {0}; time_t now; time_t scheduleTime; struct tm *tmNow = NULL; struct tm tmSchedule; int ret = -1; time(&now); printf("Please input a periodic time, now time is: %s", ctime(&now)); printf("periodic-time:\n"); scanf("%s", timeStr); printf("interval-time:\n"); scanf("%s", timeInter); ret = string_to_attime(timeStr, &scheduleTime); if (ret < 0) { return -1; } tmNow = localtime(&now); copy_time_tm(&tmSchedule, tmNow); tmSchedule.tm_hour = scheduleTime/3600; tmSchedule.tm_min = (scheduleTime%3600)/60; tmSchedule.tm_sec = (scheduleTime%3600)%60; printf("Configure time is: %s\n", asctime(&tmSchedule)); scheduleTime = mktime(&tmSchedule); ev_periodic_init(&t1, periodic_callback, scheduleTime, (double)atoi(timeInter), NULL); ev_periodic_start(loop, &t1); return 0; }
void start_watchers(struct ev_loop *loop) { ev_io_start(loop, &bspwm_watcher); ev_timer_again(loop, &wifi_timer); ev_timer_again(loop, &battery_watcher); ev_timer_again(loop, &sound_watcher); ev_io_start(loop, &packages_io_watcher); ev_periodic_start(loop, &clock_watcher); ev_signal_start(loop, &signal_watcher); ev_prepare_start(loop, &prepare_display); }
void start_time_redraw_tick(struct ev_loop* main_loop) { if (time_redraw_tick) { ev_periodic_set(time_redraw_tick, 0., 1.0, 0); ev_periodic_again(main_loop, time_redraw_tick); } else { if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) { return; } ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., 1., 0); ev_periodic_start(main_loop, time_redraw_tick); } }
void start_time_redraw_tick(struct ev_loop* main_loop) { if (time_redraw_tick) { ev_periodic_set(time_redraw_tick, 1.0, 60., 0); ev_periodic_again(main_loop, time_redraw_tick); } else { /* When there is no memory, we just don’t have a timeout. We cannot * exit() here, since that would effectively unlock the screen. */ if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) return; ev_periodic_init(time_redraw_tick,time_redraw_cb, 1.0, 60., 0); ev_periodic_start(main_loop, time_redraw_tick); } }
int main(void) { struct sock_ev_serv server; struct ev_periodic every_few_seconds; // Create a single-loop for this single-thread application // use the default event loop unless you have special needs EV_P = ev_default_loop(0); // Create socket in non-blocking fashion // /tmp/libev-echo.sock is server_init(&server, "/tmp/libev-echo.sock", MAX_QUEUE); /* To be sure that we aren't actually blocking ev_periodic_init(ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedue_cb); */ ev_periodic_init(&every_few_seconds, timeout_cb, 0, 5, 0); ev_periodic_start(EV_A_ &every_few_seconds); /* Initialize and configures an ev_io watcher ev_io_init (ev_io *, callback, int fd, int events) fd: file descriptor to rceeive events for events: EV_READ, EV_WRITE or EV_READ | EV_WRITE to receive the given events. Get notified and call callback function whenever the socket receives the event. */ ev_io_init(&server.io, server_cb, server.fd, EV_READ); ev_io_start(EV_A_ &server.io); // Run our loop *forever* puts("echo-server starting...\n"); // Wait for events to arrive ev_loop(EV_A_ 0); // This point is only ever reached if the loop is manually exited close(server.fd); return 0; }
/* * 功能:设置触发时间在一个小时之后,之后通过代码修改系统时间 */ int periodic_time_now_test(void) { time_t now; time_t trigger_time; time(&now); printf("Time before add: %s\n", ctime(&now)); trigger_time = now + 3600; printf("Time after add 1 hours is: %s\n", ctime(&trigger_time)); printf("Timestamp of trigger_time time:%lu\n", trigger_time); // create a new thread periodic_thread_create(trigger_time); // ev ev_periodic_init(&t2, periodic_callback, trigger_time, 0.0, NULL); ev_periodic_start(loop, &t2); return 0; }
int main(int argc, char **argv) { struct ev_loop *el; struct ev_periodic ep; struct sigaction act; int c; // Initialize stats errno_cnt_init(&socket_errors_cnt); errno_cnt_init(&fcntl_errors_cnt); errno_cnt_init(&setsockopt_errors_cnt); errno_cnt_init(&connect_errors_cnt); errno_cnt_init(&write_errors_cnt); // Options and defaults struct hostent *hent; float period = 1.0f / connRate; optreset = optind = 1; while ((c = getopt(argc, argv, "r:s:n:hv")) != -1) { switch (c) { case 'h': usage(stdout, argv[0]); return 0; case 'r': if ((connRate = strtoul(optarg, NULL, 10)) > 0) { period = 1.0f / MIN(connRate, MAX_TICK_FREQUENCY); } break; case 's': dataSize = strtoul(optarg, NULL, 10); break; case 'n': numConns = strtoul(optarg, NULL, 10); break; case 'v': dbg_level++; break; case '?': fprintf(stderr, "%s: unknown option %c\n", argv[0], optopt); return 1; } } if ((argc - optind) != 2) { usage(stderr, argv[0]); return 1; } if (!(hent = gethostbyname(argv[optind]))) { fprintf(stderr, "%s: could not resolve host name\n", argv[0]); return 1; } bzero(&addr, sizeof(addr)); memcpy(&addr.sin_addr, hent->h_addr, sizeof(addr.sin_addr)); addr.sin_port = htons(strtoul(argv[optind + 1], NULL, 10)); addr.sin_len = sizeof(addr); addr.sin_family = AF_INET; bzero(&act, sizeof(act)); act.sa_handler = sigint_cb; if (sigaction(SIGINT, &act, NULL)) { perror("sigaction"); exit(1); } el = ev_default_loop(EVFLAG_AUTO); if (connRate > 0) { ev_periodic_init(&ep, periodic_watcher_cb, 0, period, NULL); ev_periodic_start(el, &ep); } else { while (numConns-- > 0) { spawn_connection(el); } } atexit(atexit_cb); ev_loop(el, 0); ev_default_destroy(); return 0; }
int main (int argc, char* argv[]) { // Create our single-loop for this single-thread application EV_P; pthread_attr_t attr; int thread_status; struct evn_server* server; char socket_address[256]; EV_A = ev_default_loop(0); // Set default options, then parse new arguments to update the settings dummy_settings_set_presets(&dummy_settings); argp_parse (&argp, argc, argv, 0, 0, &dummy_settings); // TODO separate worker settings from daemon settings // (i.e. redirect) if (true == redirect) { redirect_output(); } if (0) { struct ev_periodic every_few_seconds; // To be sure that we aren't actually blocking ev_periodic_init(&every_few_seconds, test_process_is_not_blocked, 0, 1, 0); ev_periodic_start(EV_A_ &every_few_seconds); } // Set the priority of this whole process higher (requires root) setpriority(PRIO_PROCESS, 0, -13); // -15 // initialize the values of the struct that we will be giving to the new thread thread_control.dummy_settings = &dummy_settings; thread_control.buffer_head = 0; thread_control.buffer_count = 0; thread_control.EV_A = ev_loop_new(EVFLAG_AUTO); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); // Initialize the thread that will manage the DUMMY_WORKER thread_status = pthread_create(&dummy_worker_pthread, &attr, dummy_worker_thread, (void *)(&thread_control)); if (0 != thread_status) { fprintf(stderr, "thread creation failed with errno %d (%s)\n", thread_status, strerror(thread_status)); exit(EXIT_FAILURE); } pthread_attr_destroy(&attr); // Create unix socket in non-blocking fashion snprintf(socket_address, sizeof(socket_address), DUMMYD_SOCK, (int)getuid()); unlink(socket_address); server = evn_server_create(EV_A_ server_on_connection); server->on_connection = server_on_connection; evn_server_listen(server, 0, socket_address); // Run our loop, until we recieve the QUIT, TERM or INT signals, or an 'x' over the socket. puts("[Daemon] Looping.\n"); ev_loop(EV_A_ 0); // Cleanup if `unloop` is ever called clean_shutdown(EV_A_ 0); return 0; }
int main(int argc, char *argv[]) { // read options char *dir = NULL; short badarg = 0; int opt; while ((opt = getopt(argc, argv, "d:")) != -1) { if (opt == 'd') dir = optarg; else badarg = 1; } if (badarg) { print_usage(); return 1; } // change dir dir = flon_path(argv[0], dir); if (chdir(dir) != 0) { fgaj_r("couldn't chdir to %s", dir); return 1; } fgaj_i("-d %s", dir); // load configuration if (flon_configure(".") != 0) { fgaj_r("couldn't read %s/etc/flon.json, cannot start", dir); return 1; } free(dir); // set up logging flon_setup_logging("dispatcher"); // scan once scan_dir(); // load timers flon_load_timers(); // then, ev... struct ev_loop *l = ev_default_loop(0); // watch var/spool/dis/ ev_stat est; ev_stat_init(&est, spool_cb, "var/spool/dis/", 0.); ev_stat_start(l, &est); // check from time to time too ev_periodic epe; ev_periodic_init(&epe, trigger_cb, 0., .35, trigger_reschedule_cb); ev_periodic_start(l, &epe); //ev_timer eti; //ev_timer_init(&eti, do_something_when_loop_ready_cb, 0., 0.); //ev_timer_start(l, &eti); ev_signal esi; ev_signal_init(&esi, sighup_cb, SIGHUP); ev_signal_start(l, &esi); // loop //fgaj_i("about to ev_loop..."); ev_loop(l, 0); fgaj_r("something went wrong"); }
int init_bc_periodic_watcher() { ev_periodic_init(&periodic_watcher, bc_periodic_cb, 0, 0, bc_scheduler); ev_periodic_start(bc_loop, &periodic_watcher); return (0); }
static void periodic_start (void *impl, flux_watcher_t *w) { struct f_periodic *fp = w->impl; assert (w->signature == PERIODIC_SIG); ev_periodic_start (w->r->loop, &fp->evp); }