process_post_event_status process_post_priority_event(process* p, process_event_t ev, process_data_t data, process_event_priority pri) { if (pri >= NB_PROCESS_EVENT_PRIORITIES) { return PROCESS_POST_EVENT_INVALID_PRIORITY; } return post_event(p, &queues[pri], ev, data); }
static audio_result_t load_url(void* _mp3_info, const char* url) { mp3_t* mp3_info = (mp3_t*) _mp3_info; mc_free(mp3_info->file_or_url); mp3_info->file_or_url = mc_strdup(url); post_event(mp3_info->player_control, INTERNAL_CMD_LOAD_URL, -1); psem_wait(mp3_info->length_set); return AUDIO_OK; }
static audio_result_t load_file(void* _minfo, const char* file) { ogg_t* minfo = (ogg_t*) _minfo; mc_free(minfo->file_or_url); minfo->file_or_url = mc_strdup(file); post_event(minfo->player_control, INTERNAL_CMD_LOAD_FILE, -1); psem_wait(minfo->length_set); return AUDIO_OK; }
boost::statechart::result QuittingGame::react(const StartQuittingGame& u) { TraceLogger(FSM) << "(HumanClientFSM) QuittingGame"; m_server_process = &u.m_server; m_after_server_shutdown_action = u.m_after_server_shutdown_action; post_event(ShutdownServer()); return discard_event(); }
Approaching::Approaching(my_context ctx) : my_base(ctx) { UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : NoUISubState; PRINTENGINE->SendStatus(ApproachingState, Entering, uiSubState); if (context<PrinterStateMachine>()._motionCompleted) post_event(EvMotionCompleted()); }
static void channel_server_connected(Channel * c1) { trace(LOG_ALWAYS, "channel server connected"); assert(c1->state == ChannelStateConnected); /* Connect to destination on next dispatch since we are limited in * what we can do in a callback, e.g. cannot close channel. */ post_event(connect_dest, c1); }
void facade::init(std::vector<std::string> args) { base::app::app::init(args); /////////////////////////////////////////////////// base::event::event* new_event=NULL; /////////////////////////////////////////////////// connect_event_handler("event.base.app.shutdown", boost::bind(&base::app::app::handle_shutdown, this, _1)); /////////////////////////////////////////////////// std::string config_file("config/bj.client.dev.ini"); try { boost::property_tree::ini_parser::read_ini(config_file, *get_configuration("default")); } catch(const std::exception& e) { std::cerr<<"[facade::init] Exception: "<<e.what()<<"."<<std::endl; std::cout<<"usage: "<<args[0]<<" [host_ip] [host_port]"<<std::endl; /////////////////////////////////////////// new_event=base::event::Factory::get("event.base.app.shutdown"); new_event->set_debug_info(_DEBUG_INFO_()); post_event(new_event); /////////////////////////////////////////// return; } //std::cout<<base::formatting::to_string(_options)<<std::endl; merge_configuration_options("default"); //std::cout<<base::ptree::str(*get_configuration("default"))<<std::endl; /////////////////////////////////////////////////// // connect_event_handler("event.base.deadlinetimer.timeout", boost::bind(&facade::handle_timeout, this, _1)); /////////////////////////////////////////////////// _xml=new xml(this); _cli=new cli(this); _cli->init(); _server_settings=new server_settings(); /////////////////////////////////////////////////// _session=new session(this); _session->init(); std::string host_ip=get_configuration("default")->get<std::string>("server.ip"); int port=get_configuration("default")->get<int>("common.tcp_port"); boost::asio::ip::tcp::endpoint* endpoint= new boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(host_ip), port); _session->connect(endpoint); /////////////////////////////////////////////////// _player=new player(this); _player->set_name(get_configuration("default")->get<std::string>("player.name")); _player->set_nick(get_configuration("default")->get<std::string>("player.nick")); _player->set_pass(get_configuration("default")->get<std::string>("player.pass")); _player->set_skin_id(get_configuration("default")->get<int>("player.skin_id")); /////////////////////////////////////////////////// _player_controller=new player_controller(this); _player_controller->set_player(_player); _player_controller->init(); /////////////////////////////////////////////////// get_thread_group()->add_thread(new boost::thread(boost::bind(&cli::poll_std_cin, _cli))); }
static void signal_handler(int sig) { if (is_dispatch_thread()) { discovery_stop(); signal(sig, SIG_DFL); raise(sig); } else { post_event(shutdown_event, NULL); } }
// respond to connection or disconnection of ftdi device. // may be called from an interrupt void ftdi_change(uhc_device_t* dev, u8 plug) { print_dbg("\r\n changed FTDI connection status"); if(plug) { e.eventType = kEventFtdiConnect; } else { e.eventType = kEventFtdiDisconnect; } // posting an event so the main loop can respond post_event(&e); }
//////////////////////////////////////////////////////////// // PlayingTurn //////////////////////////////////////////////////////////// PlayingTurn::PlayingTurn(my_context ctx) : Base(ctx) { TraceLogger(FSM) << "(HumanClientFSM) PlayingTurn"; Client().Register(Client().GetClientUI().GetMapWnd()); Client().GetClientUI().GetMapWnd()->InitTurn(); Client().GetClientUI().GetMapWnd()->RegisterWindows(); // only useful at game start but InitTurn() takes a long time, don't want to display windows before content is ready. could go in WaitingForGameStart dtor but what if it is given e.g. an error reaction? // TODO: reselect last fleet if stored in save game ui data? Client().GetClientUI().GetMessageWnd()->HandleGameStatusUpdate( boost::io::str(FlexibleFormat(UserString("TURN_BEGIN")) % CurrentTurn()) + "\n"); Client().GetClientUI().GetMessageWnd()->HandlePlayerStatusUpdate(Message::PLAYING_TURN, Client().PlayerID()); Client().GetClientUI().GetPlayerListWnd()->Refresh(); Client().GetClientUI().GetPlayerListWnd()->HandlePlayerStatusUpdate(Message::PLAYING_TURN, Client().PlayerID()); if (Client().GetApp()->GetClientType() != Networking::CLIENT_TYPE_HUMAN_OBSERVER) Client().GetClientUI().GetMapWnd()->EnableOrderIssuing(true); if (Client().GetApp()->GetClientType() == Networking::CLIENT_TYPE_HUMAN_OBSERVER) { // observers can't do anything but wait for the next update, and need to // be back in WaitingForTurnData, so posting TurnEnded here has the effect // of keeping observers in the WaitingForTurnData state so they can receive // updates from the server. post_event(TurnEnded()); } else if (Client().GetApp()->GetClientType() == Networking::CLIENT_TYPE_HUMAN_PLAYER) { if (Client().GetClientUI().GetMapWnd()->AutoEndTurnEnabled()) { // if in-game-GUI auto turn advance enabled, set auto turn counter to 1 Client().InitAutoTurns(1); } // if no auto turns left, and supposed to quit then autosave // which will lead to a quit when the save completes if (Client().AutoTurnsLeft() <= 0 && GetOptionsDB().Get<bool>("auto-quit")) Client().Autosave(); // if there are still auto turns left, advance the turn automatically, // and decrease the auto turn counter if (Client().AutoTurnsLeft() > 0) { post_event(AdvanceTurn()); Client().DecAutoTurns(); } } }
static void np_trigger_message(InputBuf * ibuf) { ChannelNP * c = ibuf2np(ibuf); assert(is_dispatch_thread()); assert(c->ibuf.message_count > 0); if (c->ibuf.handling_msg == HandleMsgIdle) { post_event(handle_channel_msg, c); c->ibuf.handling_msg = HandleMsgTriggered; } }
Initializing::Initializing(my_context ctx) : my_base(ctx) { PRINTENGINE->SendStatus(InitializingState, Entering); // see if the printer should be put into demo mode if (PRINTENGINE->DemoModeRequested()) post_event(EvEnterDemoMode()); // check to see if the door is open on startup if (PRINTENGINE->DoorIsOpen()) { post_event(EvDoorOpened()); } else { PRINTENGINE->Initialize(); post_event(EvInitialized()); } }
static audio_result_t seek(void* _minfo, long position_in_ms) { ogg_t* minfo = (ogg_t*) _minfo; if (minfo->can_seek) { post_event(minfo->player_control, INTERNAL_CMD_SEEK, position_in_ms); return AUDIO_OK; } else { return AUDIO_NOT_SUPPORTED; } }
int virtual_stream_get_data(VirtualStream * stream, char * buf, size_t buf_size, size_t * data_size, int * eos) { size_t len; assert(stream->magic == STREAM_MAGIC); len = (stream->buf_inp + stream->buf_len - stream->buf_out) % stream->buf_len; if (len > buf_size) { len = buf_size; *eos = 0; } else { *eos = stream->eos_inp; } *data_size = len; if (*eos) stream->eos_out = 1; if (stream->buf_out + len <= stream->buf_len) { memcpy(buf, stream->buf + stream->buf_out, len); } else { size_t x = stream->buf_len - stream->buf_out; size_t y = len - x; memcpy(buf, stream->buf + stream->buf_out, x); memcpy(buf + x, stream->buf, y); } if (stream->access & VS_ENABLE_REMOTE_WRITE) { LINK * l; for (l = stream->clients.next; l != &stream->clients; l = l->next) { StreamClient * client = stream2client(l); if (!list_is_empty(&client->write_requests)) { WriteRequest * r = client2write_request(client->write_requests.next); size_t done = 0; int error = 0; if (virtual_stream_add_data(client->stream, r->data + r->offs, r->size - r->offs, &done, r->eos) < 0) error = errno; r->offs += done; if (error || r->offs >= r->size) { delete_write_request(r, error); } while (error && !list_is_empty(&client->write_requests)) { r = client2write_request(client->write_requests.next); delete_write_request(r, ERR_COMMAND_CANCELLED); } } } } if ((stream->access & VS_ENABLE_REMOTE_READ) == 0 && len > 0) { stream->buf_out = (stream->buf_out + len) % stream->buf_len; assert(!*eos || stream->buf_out == stream->buf_inp); if (!stream->space_available_posted) { post_event(notify_space_available, stream); stream->space_available_posted = 1; } } return 0; }
static void execOutput(acalcoutRecord *pcalc) { long status; /* Determine output data */ if (aCalcoutRecordDebug >= 10) printf("acalcoutRecord(%s):execOutput:entry\n", pcalc->name); /* Check to see what to do if INVALID */ if (pcalc->nsev < INVALID_ALARM) { /* Output the value */ if (aCalcoutRecordDebug >= 10) printf("acalcoutRecord(%s):execOutput:calling writeValue\n", pcalc->name); status = writeValue(pcalc); /* post event if output event != 0 */ if (pcalc->oevt > 0) post_event((int)pcalc->oevt); } else { switch (pcalc->ivoa) { case menuIvoaContinue_normally: /* write the new value */ status = writeValue(pcalc); /* post event if output event != 0 */ if (pcalc->oevt > 0) post_event((int)pcalc->oevt); break; case menuIvoaDon_t_drive_outputs: break; case menuIvoaSet_output_to_IVOV: pcalc->oval=pcalc->ivov; status = writeValue(pcalc); /* post event if output event != 0 */ if (pcalc->oevt > 0) post_event((int)pcalc->oevt); break; default: status=-1; recGblRecordError(S_db_badField,(void *)pcalc, "acalcout:process Illegal IVOA field"); } } }
static BOOL CtrlHandler(DWORD ctrl) { switch(ctrl) { case CTRL_C_EVENT: case CTRL_CLOSE_EVENT: case CTRL_BREAK_EVENT: case CTRL_SHUTDOWN_EVENT: post_event(shutdown_event, NULL); return TRUE; } return FALSE; }
int panel_close_callback(int event, struct widget *from, s32 param, int owner, const u8 *data) { struct widget *p; p = from->callback_owner; if (p && event==PG_WE_ACTIVATE) { /* Send a close event from the panel widget */ post_event(PG_WE_CLOSE, p, 0,0,NULL); } return 1; /* Absorb event */ }
static void check_safe_events(Context * ctx) { assert(ctx->stopped || ctx->exited); assert(ctx->pending_safe_event); assert(safe_event_list != NULL); assert(safe_event_pid_count > 0); ctx->pending_safe_event = 0; safe_event_pid_count--; if (safe_event_pid_count == 0) { post_event(run_safe_events, (void *)++safe_event_generation); } }
boost::statechart::result PlayingTurn::react(const TurnUpdate& msg) { TraceLogger(FSM) << "(HumanClientFSM) PlayingTurn.TurnUpdate"; Client().GetClientUI().GetMessageWnd()->HandleLogMessage(UserString("ERROR_EARLY_TURN_UPDATE") + "\n"); // need to re-post the game start message to be re-handled after // transitioning into WaitingForTurnData post_event(msg); return transit<WaitingForTurnData>(); }
boost::statechart::result MPLobby::react(const GameStart& msg) { TraceLogger(FSM) << "(HumanClientFSM) MPLobby.GameStart"; // need to re-post the game start message to be re-handled after // transitioning into WaitingForGameStart post_event(msg); Client().GetClientUI().GetMapWnd()->Sanitize(); Client().Remove(Client().GetClientUI().GetMultiPlayerLobbyWnd()); return transit<WaitingForGameStart>(); }
static void task_delete_hook(WIND_TCB * tcb) { if (tcb != main_thread && taskIdCurrent != main_thread) { EventInfo info; VX_COUNTING_SEMAPHORE(signal_mem); info.signal = semCInitialize(signal_mem, SEM_Q_FIFO, 0); info.pid = (UINT32)tcb; post_event(task_delete_event, &info); semTake(info.signal, WAIT_FOREVER); semTerminate(info.signal); } }
static int cisco_dissector(orchids_t *ctx, mod_entry_t *mod, event_t *e, void *data) { DebugLog(DF_MOD, DS_DEBUG, "cisco_dissector()\n"); /* dissect event top attribute here, and add them to it */ /* then, post resulting event */ post_event(ctx, mod, e); return (0); }
boost::statechart::result PlayingGame::react(const LobbyUpdate& msg) { TraceLogger(FSM) << "(HumanClientFSM) PlayingGame.LobbyUpdate"; // need to re-post the lobby update message to be re-handled after // transitioning into MPLobby post_event(msg); Client().ResetClientData(true); Client().GetClientUI().ShowMultiPlayerLobbyWnd(); return transit<MPLobby>(); }
boost::statechart::result QuittingGame::react(const WaitForDisconnect& u) { TraceLogger(FSM) << "(HumanClientFSM) QuittingGame.WaitForDisconnect"; if (!Client().Networking().IsConnected()) { post_event(TerminateServer()); return discard_event(); } // Wait until the timeout for a disconnect event if (QUITTING_TIMEOUT > (Clock::now() - m_start_time)) { std::this_thread::sleep_for(QUITTING_POLLING_INTERVAL); post_event(WaitForDisconnect()); return discard_event(); } // Otherwise kill the connection Client().Networking().DisconnectFromServer(); post_event(TerminateServer()); return discard_event(); }
int context_attach(pid_t pid, ContextAttachCallBack * done, void * data, int mode) { AttachDoneArgs * args = (AttachDoneArgs *)loc_alloc(sizeof(AttachDoneArgs)); assert(done != NULL); assert((mode & CONTEXT_ATTACH_SELF) == 0); args->pid = pid; args->done = done; args->data = data; post_event(event_attach_done, args); return 0; }
InitializingLayer::InitializingLayer(my_context ctx) : my_base(ctx) { // check to see if the door is still open after calibrating if (PRINTENGINE->DoorIsOpen()) post_event(EvDoorOpened()); else { // perform initialization needed for next layer // (even if the door is opened and closed again while here, // this won't be called more than once per layer, because we're going to // immediately transition to the next state) PRINTENGINE->NextLayer(); post_event(EvInitialized()); } UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : NoUISubState; // don't send status till after estimated print time has been set PRINTENGINE->SendStatus(InitializingLayerState, Entering, uiSubState); }
void ChannelScannerCLI::InformUser(const QString &error) { if (VERBOSE_LEVEL_NONE) { cerr<<"ERROR: "<<error.toAscii().constData()<<endl; } else { VERBOSE(VB_IMPORTANT, LOC_ERR + error); } post_event(scanMonitor, ScannerEvent::ScanComplete, 0); }
static void * event_thread_func(void * arg) { taskPrioritySet(0, VX_TASK_PRIORITY_MIN); for (;;) { struct event_info * info = loc_alloc(sizeof(struct event_info)); semTake(events_signal, WAIT_FOREVER); SPIN_LOCK_ISR_TAKE(&events_lock); if (events_buf_overflow && events_inp == events_out) { SPIN_LOCK_ISR_GIVE(&events_lock); loc_free(info); break; } assert(events_inp != events_out); *info = events[events_out]; events_out = (events_out + 1) % MAX_EVENTS; SPIN_LOCK_ISR_GIVE(&events_lock); post_event(event_handler, info); } post_event(event_error, NULL); return NULL; }
PreExposureDelay::PreExposureDelay(my_context ctx) : my_base(ctx) { UISubState uiSubState = PRINTENGINE->PauseRequested() ? AboutToPause : NoUISubState; PRINTENGINE->SendStatus(PreExposureDelayState, Entering, uiSubState); // check to see if the door is still open after calibrating, // in case we skipped the tray deflection steps if (PRINTENGINE->DoorIsOpen()) post_event(EvDoorOpened()); else { double delay = PRINTENGINE->GetPreExposureDelayTimeSec(); if (delay < 0.001) { // no delay needed post_event(EvDelayEnded()); } else PRINTENGINE->StartDelayTimer(delay); } }
boost::statechart::result QuittingGame::react(const Disconnection& d) { TraceLogger(FSM) << "(HumanClientFSM) PlayingGame.Disconnection"; if (m_server_process) { // Treat disconnection as acknowledgement of shutdown and free the // process to allow orderly shutdown. m_server_process->Free(); } else { ErrorLogger(FSM) << "m_server_process is nullptr"; } post_event(TerminateServer()); return discard_event(); }