void RP5C01::initialize() { #ifndef HAS_RP5C15 // load ram image memset(ram, 0, sizeof(ram)); FILEIO* fio = new FILEIO(); if(fio->Fopen(emu->bios_path(_T("RP5C01.BIN")), FILEIO_READ_BINARY)) { fio->Fread(ram, sizeof(ram), 1); fio->Fclose(); } delete fio; #endif // initialize rtc memset(regs, 0, sizeof(regs)); regs[0x0a] = 1; regs[0x0d] = 8; regs[0x0f] = 0xc; alarm = pulse_1hz = pulse_16hz = false; count_16hz = 0; emu->get_host_time(&cur_time); read_from_cur_time(); // register events register_event(this, EVENT_1SEC, 1000000, true, ®ister_id); register_event(this, EVENT_16HZ, 1000000 / 32, true, NULL); }
void AudioManager::setup() { register_event(INITIALISE); register_event(EXIT); register_event(AUDIO_MANAGER_CHANGE_UPDATE_RATE); register_event(m_update_rate); // List Any Other Events that Need to be Listened to }
void stars_init(void) { int x; register_event("draw ortho", draw_stars); register_event("timer delta", update_stars); for(x=0; x<NUM_STARS; x++) { stars[x].v[0] = rand_int(640); stars[x].v[1] = rand_int(480); stars[x].v[2] = rand_float(); stars[x].v[3] = rand_float(); } }
void path_init(void) { int x; for(x=0; x<MAX_PLAYERS; x++) { lines[x].num_pts = 0; lines[x].pts_used = 0; lines[x].pts = 0; } register_event("reset AP", create_path); register_event("draw transparent", draw_paths); }
void UPD765A::set_drq(bool val) { #ifdef _FDC_DEBUG_LOG // emu->out_debug_log("FDC: DRQ=%d\n", val ? 1 : 0); #endif // cancel next drq and data lost events if(drq_id != -1) { cancel_event(this, drq_id); } if(lost_id != -1) { cancel_event(this, lost_id); } drq_id = lost_id = -1; // register data lost event if data exists if(val) { #ifdef UPD765A_DMA_MODE // EPSON QC-10 CP/M Plus dma_data_lost = true; #else if((command & 0x1f) != 0x0d) { #ifdef SDL // for customized event manager + 2HD disk register_event(this, EVENT_LOST, 30000, false, &lost_id); #else register_event(this, EVENT_LOST, disk[hdu & DRIVE_MASK]->get_usec_per_bytes(1), false, &lost_id); #endif // SDL } else { // FIXME: write id register_event(this, EVENT_LOST, 30000, false, &lost_id); } #endif } if(no_dma_mode) { write_signals(&outputs_irq, (val && !irq_masked) ? 0xffffffff : 0); } else { write_signals(&outputs_drq, (val && !drq_masked) ? 0xffffffff : 0); #ifdef UPD765A_DMA_MODE // EPSON QC-10 CP/M Plus if(val && dma_data_lost) { #ifdef _FDC_DEBUG_LOG emu->out_debug_log("FDC: DATA LOST (DMA)\n"); #endif result = ST1_OR; write_signals(&outputs_drq, 0); shift_to_result7(); } #endif } }
input_source::input_source(device_manager* manager, device_plugin plugin, void* plug_data) : manager(manager), plugin(plugin), plug_data(plug_data), uniq(plugin.uniq), phys(plugin.phys) { for (auto ev : manager->get_events()) register_event(ev); std::vector<option_info> prof_opts; manager->mapprofile->list_options(prof_opts); for (auto opt : prof_opts) options[opt.name] = opt; epfd = epoll_create(1); if (epfd < 1) perror("epoll create"); int internal[2]; pipe(internal); watch_file(internal[0], this); priv_pipe = internal[1]; internalpipe = internal[0]; if (plugin.init) plugin.init(plug_data, this); ff_ids[0] = -1; }
static int init_signal(void) { sigset_t mask; int ret; sigemptyset(&mask); sigaddset(&mask, SIGTERM); sigprocmask(SIG_BLOCK, &mask, NULL); sigfd = signalfd(-1, &mask, SFD_NONBLOCK); if (sigfd < 0) { sd_err("failed to create a signal fd: %m"); return -1; } ret = register_event(sigfd, signal_handler, NULL); if (ret) { sd_err("failed to register signal handler (%d)", ret); return -1; } sd_debug("register signal_handler for %d", sigfd); return 0; }
void SUB::initialize() { key_buffer = new FIFO(16); // key scan (15ms) register_event(this, EVENT_KEYSCAN, 15000, true, NULL); }
void data_services_init(void) { if (data_service_state != DATA_SERVICE_STATE_NOT_STARTED) return; if ((data_service_event_handle = register_event(&data_services)) == INVALID_HANDLE) return; data_service_state = DATA_SERVICE_STATE_INIT; };
int xio_create_listen_ports(const char *bindaddr, int port, int (*callback)(int fd, void *), bool rdma) { char url[256]; struct xio_server *server; struct server_data *server_data; int xio_fd; server_data = xzalloc(sizeof(*server_data)); server_data->ctx = xio_get_main_ctx(); snprintf(url, 256, rdma ? "rdma://%s:%d" : "tcp://%s:%d", bindaddr ? bindaddr : "0.0.0.0", port); sd_info("accelio binding url: %s", url); /* bind a listener server to a portal/url */ server = xio_bind(server_data->ctx, &portal_server_ops, url, NULL, 0, server_data); if (server == NULL) { sd_err("xio_bind() failed"); return -1; } xio_fd = xio_context_get_poll_fd(server_data->ctx); register_event(xio_fd, xio_server_handler, server_data); return 0; }
void player_death(t_server *serv, t_player *player) { remove_player_from_case(serv, player, player->pos); buff_append(player->wrbuff, "mort\n", 5); register_event(serv, KILL_PLAYER, 0, (void *)player); graphic_instr_all(serv, &player->num, PDI); }
static int local_init(const char *option) { sigset_t mask; int ret; static struct timer t = { .callback = check_pids, .data = &t, }; if (option) shmfile = option; shm_queue_init(); sigemptyset(&mask); sigaddset(&mask, SIGUSR1); sigprocmask(SIG_BLOCK, &mask, NULL); sigfd = signalfd(-1, &mask, SFD_NONBLOCK); if (sigfd < 0) { eprintf("failed to create a signal fd: %m\n"); return -1; } add_timer(&t, 1); ret = register_event(sigfd, local_handler, NULL); if (ret) { eprintf("failed to register local event handler (%d)\n", ret); return -1; } return 0; }
void planks_init(void) { int x; struct marfitude_pos pos; marfitude_get_pos(&pos); num_planks = NUM_TICKS / 4; planks = malloc(sizeof(*planks) * num_planks); for(x=0; x<num_planks; x++) { int tic = ((int)pos.tic) & ~3; setup_plank(x, tic - NEGATIVE_TICKS + x * 4); } cur_plank = 0; register_event("draw opaque", draw_planks); register_event("tic", add_plank); }
int process_top_request(omp_collector_message *req) { switch(req->r) { case OMP_REQ_START: __ompc_req_start(req); break; case OMP_REQ_REGISTER: register_event(req); break; case OMP_REQ_UNREGISTER: unregister_event(req); break; case OMP_REQ_STATE: return_state(req); break; case OMP_REQ_CURRENT_PRID: return_current_prid(req); break; case OMP_REQ_PARENT_PRID: return_parent_prid(req); break; case OMP_REQ_STOP: __ompc_req_stop(req); break; case OMP_REQ_PAUSE: __ompc_req_pause(req); break; case OMP_REQ_RESUME: __ompc_req_resume(req); break; #ifdef USE_COLLECTOR_TASK case OMP_REQ_TASK_ID: return_task_info(req); break; case OMP_REQ_TASK_PID: return_parent_task_info(req); break; #endif default: *(req->ec) = OMP_ERRCODE_UNKNOWN; *(req->rsz) = 0; break; } return 1; }
void SOUND::write_data8(uint32 addr, uint32 data) { if(register_id != -1) { return; // ignore new commands before return ack } if(!param_cnt) { // new command switch(data) { case 0x00: param_cnt = 1; break; // note off case 0x01: param_cnt = 10; break; // noises & square case 0x02: param_cnt = 4; break; // tone case 0x1f: param_cnt = MAX_PARAM; break; // pcm } param_ptr = 0; cmd_addr = get_cpu_pc(0); // for patch #ifdef SOUND_DEBUG emu->out_debug(_T("PC=%4x\tSOUND\t"), cmd_addr); #endif } #ifdef SOUND_DEBUG emu->out_debug("%2x ", data); #endif if(param_cnt) { params[param_ptr++] = data; if(params[0] == 0x1f) { // pcm command if(param_ptr == 6) { memset(pcm_table, 0, sizeof(pcm_table)); pcm_len = pcm.ptr = 0; } else if(param_ptr >= 7) { // 0xfe,0x00 : end of pcm, intf1 must not be done except star speeder if(params[param_ptr - 2] == 0xfe && data == 0x00 && cmd_addr != 0xa765) { param_cnt = 1; } else { process_pcm(params[param_ptr - 2]); } } } if(--param_cnt) { if(register_id != -1) { cancel_event(register_id); } register_event(this, 0, ACK_WAIT, false, ®ister_id); } } if(!param_cnt) { // process command process_cmd(); #ifdef SOUND_DEBUG emu->out_debug("\n"); #endif } }
void SOUND::event_callback(int event_id, int err) { if(pcm.count && param_ptr == 5 && params[0] == 0x1f && params[1] == 0x04 && params[2] == 0x64) { // wait previous pcm register_event(this, 0, ACK_WAIT, false, ®ister_id); return; } d_cpu->write_signal(SIG_UPD7801_INTF1, 1, 1); register_id = -1; }
/* * Processes an incoming "handle a new connection" item. This is called when * input arrives on the libevent wakeup pipe. */ static void thread_libevent_process(evutil_socket_t fd, short which, void *arg) { LIBEVENT_THREAD *me = arg; CQ_ITEM *item; conn* pending; cb_assert(me->type == GENERAL); drain_notification_channel(fd); if (memcached_shutdown) { event_base_loopbreak(me->base); return ; } while ((item = cq_pop(me->new_conn_queue)) != NULL) { conn *c = conn_new(item->sfd, item->parent_port, item->init_state, item->event_flags, item->read_buffer_size, me->base); if (c == NULL) { if (settings.verbose > 0) { settings.extensions.logger->log(EXTENSION_LOG_INFO, NULL, "Can't listen for events on fd %d\n", item->sfd); } closesocket(item->sfd); } else { cb_assert(c->thread == NULL); c->thread = me; } cqi_free(item); } LOCK_THREAD(me); pending = me->pending_io; me->pending_io = NULL; while (pending != NULL) { conn *c = pending; cb_assert(me == c->thread); pending = pending->next; c->next = NULL; if (c->sfd != INVALID_SOCKET && !c->registered_in_libevent) { /* The socket may have been shut down while we're looping */ /* in delayed shutdown */ register_event(c, 0); } /* * We don't want the thread to keep on serving all of the data * from the context of the notification pipe, so just let it * run one time to set up the correct mask in libevent */ c->nevents = 1; run_event_loop(c); } UNLOCK_THREAD(me); }
void rows_init(void) { create_texture(&row_texes[0], width, height, create_row0); create_texture(&row_texes[1], width, height, create_row1); create_texture(&row_texes[2], width, height, create_row2); create_texture(&row_texes[3], width, height, create_row3); create_texture(&row_texes[4], width, height, create_row4); create_texture(&row_texes[5], width, height, create_row5); create_texture(&row_texes[6], width, height, create_row6); register_event("draw opaque", draw_rows); }
void AudioManager::change_update_rate(unsigned long event_code) { if ( event_code != m_update_rate ) { if ( event_code >= UPDATE && event_code <= UPDATE_SLOW ) { unregister_event(m_update_rate); m_update_rate = (unsigned long)event_code; register_event(m_update_rate); } } }
static int accord_init(const char *option) { int ret; if (!option) { eprintf("specify one of the accord servers.\n"); eprintf("e.g. sheep /store -c accord:127.0.0.1\n"); return -1; } pthread_mutex_lock(&start_lock); ahandle = acrd_init(option, 9090, acrd_join_fn, acrd_leave_fn, NULL); if (!ahandle) { eprintf("failed to connect to accrd server %s\n", option); return -1; } efd = eventfd(0, EFD_NONBLOCK); if (efd < 0) { eprintf("failed to create an event fd: %m\n"); return -1; } acrd_wq = init_work_queue("accord", true); if (!acrd_wq) { eprintf("failed to create accord workqueue: %m\n"); return -1; } pthread_cond_wait(&start_cond, &start_lock); pthread_mutex_unlock(&start_lock); if (need_cleanup) for_each_acrd_file(ahandle, BASE_FILE, __acrd_del, NULL); else { queue_start_pos = -1; queue_end_pos = -1; for_each_acrd_file(ahandle, QUEUE_FILE, find_queue_end, &queue_end_pos); } acrd_add_watch(ahandle, QUEUE_FILE, ACRD_EVENT_PREFIX | ACRD_EVENT_ALL, acrd_watch_fn, NULL); ret = register_event(efd, acrd_handler, NULL); if (ret) { eprintf("failed to register accord event handler (%d)\n", ret); return -1; } return 0; }
void static_view_init(void) { bluenotes_init(); explode_init(); greynotes_init(); lines_init(); rows_init(); scoreboard_init(); targets_init(); register_event("set view", set_main_view); view_focus = 0.0; }
void UPD765A::shift_to_result7() { #ifdef UPD765A_WAIT_RESULT7 if(result7_id != -1) { cancel_event(this, result7_id); result7_id = -1; } if(phase != PHASE_TIMER) { register_event(this, EVENT_RESULT7, 100, false, &result7_id); } else #endif shift_to_result7_event(); }
void SASI::write_io8(uint32 addr, uint32 data) { switch(addr) { case 0x1f0: // data if(phase == PHASE_COMMAND) { cmd[cmd_ptr++] = data; if(cmd_ptr == 6) { check_cmd(); } } else if(phase == PHASE_C2) { if(++status_ptr == 10) { set_status(0); } } else if(phase == PHASE_WRITE) { buffer[buffer_ptr++] = data; if(buffer_ptr == 256) { flush(unit); if(--blocks) { sector++; buffer_ptr = 0; if(!seek(unit)) { set_status(0x0f); set_drq(false); } } else { set_status(0); set_drq(false); } } } datareg = data; break; case 0x1f1: // reset reset(); break; case 0x1f2: // select phase = PHASE_SELECT; register_event(this, EVENT_COMMAND, 10, false, NULL); break; case 0x1f3: // mask maskreg = data; break; } }
void I2C1_Init(void) { // I2C1_SDA_TRIS = I2C1_SCL_TRIS = 0; // SDA and SCL as outputs I2C1BRG = I2C1BRGVAL; _I2C1EN = 1; // enable I2C1 _MI2C1IP = INT_PRI_I2C1; // set interrupt priority _MI2C1IF = 0; // clear the I2C1 master interrupt _MI2C1IE = 1; // enable the interrupt I2C1_service_handle = register_event(&serviceI2C1); I2C1_Busy = false; }
void KEYBOARD::write_io8(uint32_t addr, uint32_t data) { switch(addr) { case 0x61: // bit7: H->L = reset flipflop ??? if(data == 0xa1) { // reset keyboard ??? key_buf->clear(); key_read = true; register_event(this, 0, 2000000, false, NULL); } key_ctrl = data; break; } }
void TcpListener::listen() { while (::listen(sd, 0) >= 0) { struct sockaddr_in addr_recv; socklen_t addr_size = sizeof(addr); int sock_recv = accept(sd, (struct sockaddr *) &addr_recv, &addr_size); /* create a new node */ Node *node = new Node(sock_recv, addr_recv, event_queue); Event event(*this, node, Event::TCP_INC_CONNECTION); register_event(event); } }
void machine_t::load_events(const iodata::array *events_data, bool trusted_source, bool use_cookies) { for(unsigned i=0; i < events_data->size(); ++i) { const iodata::record *ee = events_data->get(i)->rec() ; unsigned cookie = use_cookies ? ee->get("cookie")->value() : next_cookie++ ; event_t *e = new event_t ; e->cookie = cookie_t(cookie) ; e->ticker = ticker_t(ee->get("ticker")->value()) ; e->t.load(ee->get("t")->rec()) ; e->tz = ee->get("tz")->str() ; e->attr.load(ee->get("attr")->arr()) ; e->flags = ee->get("flags")->decode(event_t::codec) ; iodata::load(e->recrs, ee->get("recrs")->arr()) ; iodata::load_int_array(e->snooze, ee->get("snooze")->arr()) ; if (e->recrs.size() > 0) e->trigger_if_missed = true; const iodata::array *a = ee->get("b_attr")->arr() ; unsigned nb = a->size() ; e->b_attr.resize(nb) ; for(unsigned i=0; i<nb; ++i) e->b_attr[i].load(a->get(i)->rec()->get("attr")->arr()) ; e->last_triggered = ticker_t(ee->get("dialog_time")->value()) ; e->tsz_max = ee->get("tsz_max")->value() ; e->tsz_counter = ee->get("tsz_counter")->value() ; if(trusted_source) { iodata::load(e->actions, ee->get("actions")->arr()) ; if (e->actions.size()>0) e->client_creds = new credentials_t(ee->get("client_creds")->rec()) ; const iodata::array *cred_modifier = ee->get("cred_modifier")->arr() ; if (cred_modifier->size()>0) e->cred_modifier = new cred_modifier_t(cred_modifier) ; } if(e->flags & EventFlags::Empty_Recurring) e->invalidate_t() ; register_event(e) ; } }
cookie_t machine_t::add_event(const Maemo::Timed::event_io_t *eio, bool process_queue, const credentials_t *creds, const QDBusMessage *p_message) { // The credentials for the event are either already known (creds) // or have to be established by the QDBusMessage structure (from dbus daemon) // Using pointers instead of usual C++ references, just because a NULL-reference // usually confuses people (though working just fine) #if 0 if (event_t *e = new event_t) { // #include "simple-event.c++" #include "clock-ui-event.c++" #else if (event_t *e = event_t::from_dbus_iface(eio)) { if (e->actions.size() > 0) e->client_creds = creds ? new credentials_t(*creds) : new credentials_t(*p_message) ; #endif register_event(e) ; if (process_queue) invoke_process_transition_queue() ; log_info("new event: cookie=%d, object=%p", e->cookie.value(), e) ; return e->cookie ; } return cookie_t(0) ; } void machine_t::register_event(event_t *e) { if (not e->cookie.is_valid()) e->cookie = cookie_t(next_cookie++) ; events[e->cookie] = e ; state_start->go_to(e) ; } void machine_t::unregister_event(event_t *e) { log_assert(is_event_registered(e)) ; if (e->request_watcher) e->request_watcher->detach(e) ; log_assert(not e->request_watcher) ; events.erase(e->cookie) ; }
Datum dbms_alert_register(PG_FUNCTION_ARGS) { text *name = PG_GETARG_TEXT_P(0); int cycle = 0; float8 endtime; float8 timeout = 2; WATCH_PRE(timeout, endtime, cycle); if (ora_lock_shmem(SHMEMMSGSZ, MAX_PIPES, MAX_EVENTS, MAX_LOCKS, false)) { register_event(name); LWLockRelease(shmem_lock); PG_RETURN_VOID(); } WATCH_POST(timeout, endtime, cycle); LOCK_ERROR(); PG_RETURN_VOID(); }
void RP5C01::write_to_cur_time() { cur_time.second = time[0] + (time[1] & 7) * 10; cur_time.minute = time[2] + (time[3] & 7) * 10; if(MODE_12H) { cur_time.hour = time[4] + (time[5] & 1) * 10 + (time[5] & 2 ? 12 : 0); } else { cur_time.hour = time[4] + (time[5] & 3) * 10; } // cur_time.day_of_week = time[6]; cur_time.day = time[7] + (time[8] & 3) * 10; cur_time.month = time[9] + (time[10] & 1) * 10; cur_time.year = time[11] + time[12] * 10; cur_time.update_year(); cur_time.update_day_of_week(); // restart events cancel_event(register_id); register_event(this, EVENT_1SEC, 1000000, true, ®ister_id); }