/** * got command from server, and push them to task queue * @param m: the message got ************************************************************/ static void server_push_command(message_t *message) { if( message == NULL ){ LM_ERR( " server push message is null \n" ); return; } connection_t *connection; task_thread_t *thread; task_queue_item_t *item; connection = (connection_t*)message->connection; /*push to the task queue*/ thread = (task_thread_t *)(connection->thread); item = task_queue_item_new(thread->ttm, SERVER_ITEM_NUMBER); if (item == NULL){ LM_ERR("task_queue_item_new return null\n"); return ; } item->task_data.msg = *message; task_queue_push(thread->new_task_queue, item); if (write(thread->notify_send_fd, "", 1) != 1) { LM_DBG("Writing to thread notify pipe\n"); } return ; }
void thread_pool_execute_task(thread_pool_t p, routine_t f, arg_t arg) { task_t t=NULL; assert(p!=NULL && p->tasks!=NULL); /* create the task and add it to the queue */ t=task_create(f,arg); p->tasks=task_queue_push(p->tasks,t); }
bool task_push_netplay_lan_scan_rooms(retro_task_callback_t cb) { retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task)); if (!task) return false; task->type = TASK_TYPE_BLOCKING; task->handler = task_netplay_lan_scan_handler; task->callback = cb; task->title = strdup(msg_hash_to_str(MSG_NETPLAY_LAN_SCANNING)); task_queue_push(task); return true; }
bool input_autoconfigure_disconnect(unsigned i, const char *ident) { char msg[255]; retro_task_t *task = task_init(); autoconfig_disconnect_t *state = (autoconfig_disconnect_t*)calloc(1, sizeof(*state)); if (!state || !task) goto error; msg[0] = '\0'; state->idx = i; snprintf(msg, sizeof(msg), "%s #%u (%s).", msg_hash_to_str(MSG_DEVICE_DISCONNECTED_FROM_PORT), i, ident); state->msg = strdup(msg); input_config_clear_device_name(state->idx); input_config_clear_device_display_name(state->idx); input_config_clear_device_config_name(state->idx); input_config_clear_device_config_path(state->idx); task->state = state; task->handler = input_autoconfigure_disconnect_handler; task_queue_push(task); return true; error: if (state) { if (!string_is_empty(state->msg)) free(state->msg); free(state); } if (task) free(task); return false; }
void task_push_get_powerstate(void) { retro_task_t *task = task_init(); powerstate_t *state = NULL; if (!task) return; state = (powerstate_t*)calloc(1, sizeof(*state)); if (!state) { free(task); return; } task->type = TASK_TYPE_NONE; task->state = state; task->handler = task_powerstate_handler; task->callback = task_powerstate_cb; task->mute = true; task_queue_push(task); }
bool task_push_dbscan( const char *playlist_directory, const char *content_database, const char *fullpath, bool directory, bool show_hidden_files, retro_task_callback_t cb) { retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t)); db_handle_t *db = (db_handle_t*)calloc(1, sizeof(db_handle_t)); if (!t || !db) goto error; t->handler = task_database_handler; t->state = db; t->callback = cb; t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN)); db->show_hidden_files = show_hidden_files; db->is_directory = directory; db->playlist_directory = NULL; db->fullpath = strdup(fullpath); db->playlist_directory = strdup(playlist_directory); db->content_database_path = strdup(content_database); task_queue_push(t); return true; error: if (t) free(t); if (db) free(db); return false; }
bool input_autoconfigure_connect( const char *name, const char *display_name, const char *driver, unsigned idx, unsigned vid, unsigned pid) { unsigned i; retro_task_t *task = task_init(); autoconfig_params_t *state = (autoconfig_params_t*)calloc(1, sizeof(*state)); settings_t *settings = config_get_ptr(); const char *dir_autoconf = settings ? settings->paths.directory_autoconfig : NULL; bool autodetect_enable = settings ? settings->bools.input_autodetect_enable : false; if (!task || !state || !autodetect_enable) goto error; if (!string_is_empty(name)) state->name = strdup(name); if (!string_is_empty(dir_autoconf)) state->autoconfig_directory = strdup(dir_autoconf); state->idx = idx; state->vid = vid; state->pid = pid; state->max_users = *( input_driver_get_uint(INPUT_ACTION_MAX_USERS)); input_autoconfigure_override_handler(state); if (!string_is_empty(state->name)) input_config_set_device_name(state->idx, state->name); input_config_set_pid(state->idx, state->pid); input_config_set_vid(state->idx, state->vid); for (i = 0; i < RARCH_BIND_LIST_END; i++) { input_autoconf_binds[state->idx][i].joykey = NO_BTN; input_autoconf_binds[state->idx][i].joyaxis = AXIS_NONE; if ( !string_is_empty(input_autoconf_binds[state->idx][i].joykey_label)) free(input_autoconf_binds[state->idx][i].joykey_label); if ( !string_is_empty(input_autoconf_binds[state->idx][i].joyaxis_label)) free(input_autoconf_binds[state->idx][i].joyaxis_label); input_autoconf_binds[state->idx][i].joykey_label = NULL; input_autoconf_binds[state->idx][i].joyaxis_label = NULL; } input_autoconfigured[state->idx] = false; task->state = state; task->handler = input_autoconfigure_connect_handler; task_queue_push(task); return true; error: if (state) { input_autoconfigure_params_free(state); free(state); } if (task) free(task); return false; }
bool task_push_audio_mixer_load(const char *fullpath, retro_task_callback_t cb, void *user_data) { nbio_handle_t *nbio = NULL; struct audio_mixer_handle *image = NULL; retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t)); if (!t) goto error; nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio)); if (!nbio) goto error; strlcpy(nbio->path, fullpath, sizeof(nbio->path)); image = (struct audio_mixer_handle*)calloc(1, sizeof(*image)); if (!image) goto error; image->is_finished = false; strlcpy(image->path, fullpath, sizeof(image->path)); nbio->type = NBIO_TYPE_NONE; image->type = AUDIO_MIXER_TYPE_NONE; if (strstr(fullpath, file_path_str(FILE_PATH_WAV_EXTENSION))) { image->type = AUDIO_MIXER_TYPE_WAV; nbio->type = NBIO_TYPE_WAV; t->callback = task_audio_mixer_handle_upload_wav; } else if (strstr(fullpath, file_path_str(FILE_PATH_OGG_EXTENSION))) { image->type = AUDIO_MIXER_TYPE_OGG; nbio->type = NBIO_TYPE_OGG; t->callback = task_audio_mixer_handle_upload_ogg; } else if ( strstr(fullpath, file_path_str(FILE_PATH_MOD_EXTENSION)) || strstr(fullpath, file_path_str(FILE_PATH_S3M_EXTENSION)) || strstr(fullpath, file_path_str(FILE_PATH_XM_EXTENSION))) { image->type = AUDIO_MIXER_TYPE_MOD; nbio->type = NBIO_TYPE_MOD; t->callback = task_audio_mixer_handle_upload_mod; } nbio->data = (struct audio_mixer_handle*)image; nbio->is_finished = false; nbio->cb = &cb_nbio_audio_mixer_load; nbio->status = NBIO_STATUS_INIT; t->state = nbio; t->handler = task_file_load_handler; t->cleanup = task_audio_mixer_load_free; t->user_data = user_data; task_queue_push(t); return true; error: if (nbio) { if (nbio->data) free(nbio->data); nbio_free(nbio->handle); free(nbio); } if (t) free(t); RARCH_ERR("[audio mixer load] Failed to open '%s': %s.\n", fullpath, strerror(errno)); return false; }
static void* task_push_http_transfer_generic( struct http_connection_t *conn, const char *url, bool mute, const char *type, retro_task_callback_t cb, void *user_data) { task_finder_data_t find_data; char tmp[255]; retro_task_t *t = NULL; http_handle_t *http = NULL; if (string_is_empty(url)) return NULL; tmp[0] = '\0'; find_data.func = task_http_finder; find_data.userdata = (void*)url; /* Concurrent download of the same file is not allowed */ if (task_queue_find(&find_data)) { RARCH_LOG("[http] '%s'' is already being downloaded.\n", url); return NULL; } if (!conn) return NULL; http = (http_handle_t*)calloc(1, sizeof(*http)); if (!http) goto error; http->connection.handle = conn; http->connection.cb = &cb_http_conn_default; if (type) strlcpy(http->connection.elem1, type, sizeof(http->connection.elem1)); strlcpy(http->connection.url, url, sizeof(http->connection.url)); http->status = HTTP_STATUS_CONNECTION_TRANSFER; t = (retro_task_t*)calloc(1, sizeof(*t)); if (!t) goto error; t->handler = task_http_transfer_handler; t->state = http; t->mute = mute; t->callback = cb; t->user_data = user_data; t->progress = -1; snprintf(tmp, sizeof(tmp), "%s '%s'", msg_hash_to_str(MSG_DOWNLOADING), path_basename(url)); t->title = strdup(tmp); task_queue_push(t); return t; error: if (conn) net_http_connection_free(conn); if (http) free(http); return NULL; }
/* Take frame bottom-up. */ static bool screenshot_dump( const char *name_base, const void *frame, unsigned width, unsigned height, int pitch, bool bgr24, void *userbuf, bool savestate, bool is_idle, bool is_paused) { char screenshot_path[PATH_MAX_LENGTH]; uint8_t *buf = NULL; #ifdef _XBOX1 d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(true); #endif settings_t *settings = config_get_ptr(); retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task)); screenshot_task_state_t *state = (screenshot_task_state_t*) calloc(1, sizeof(*state)); const char *screenshot_dir = settings->paths.directory_screenshot; screenshot_path[0] = '\0'; if (string_is_empty(screenshot_dir) || settings->bools.screenshots_in_content_dir) { fill_pathname_basedir(screenshot_path, name_base, sizeof(screenshot_path)); screenshot_dir = screenshot_path; } state->is_idle = is_idle; state->is_paused = is_paused; state->bgr24 = bgr24; state->height = height; state->width = width; state->pitch = pitch; state->frame = frame; state->userbuf = userbuf; state->silence = savestate; state->history_list_enable = settings->bools.history_list_enable; state->pixel_format_type = video_driver_get_pixel_format(); if (savestate) snprintf(state->filename, sizeof(state->filename), "%s.png", name_base); else { if (settings->bools.auto_screenshot_filename) fill_str_dated_filename(state->shotname, path_basename(name_base), IMG_EXT, sizeof(state->shotname)); else snprintf(state->shotname, sizeof(state->shotname), "%s.png", path_basename(name_base)); fill_pathname_join(state->filename, screenshot_dir, state->shotname, sizeof(state->filename)); } #ifdef _XBOX1 d3d->dev->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &state->surf); #elif defined(HAVE_RPNG) buf = (uint8_t*)malloc(width * height * 3); if (!buf) { if (task) free(task); free(state); return false; } state->out_buffer = buf; #endif task->type = TASK_TYPE_BLOCKING; task->state = state; task->handler = task_screenshot_handler; if (!savestate) task->title = strdup(msg_hash_to_str(MSG_TAKING_SCREENSHOT)); task_queue_push(task); return true; }
/* Take frame bottom-up. */ static bool screenshot_dump( const char *name_base, const void *frame, unsigned width, unsigned height, int pitch, bool bgr24, void *userbuf, bool savestate, bool is_idle, bool is_paused, bool fullpath, bool use_thread) { char screenshot_path[PATH_MAX_LENGTH]; uint8_t *buf = NULL; settings_t *settings = config_get_ptr(); retro_task_t *task; screenshot_task_state_t *state; const char *screenshot_dir = settings->paths.directory_screenshot; struct retro_system_info system_info; screenshot_path[0] = '\0'; if (!core_get_system_info(&system_info)) return false; task = task_init(); state = (screenshot_task_state_t*)calloc(1, sizeof(*state)); state->shotname[0] = '\0'; /* If fullpath is true, name_base already contains a static path + filename to save the screenshot to. */ if (fullpath) strlcpy(state->filename, name_base, sizeof(state->filename)); else { if (string_is_empty(screenshot_dir) || settings->bools.screenshots_in_content_dir) { fill_pathname_basedir(screenshot_path, name_base, sizeof(screenshot_path)); screenshot_dir = screenshot_path; } } state->is_idle = is_idle; state->is_paused = is_paused; state->bgr24 = bgr24; state->height = height; state->width = width; state->pitch = pitch; state->frame = frame; state->userbuf = userbuf; state->silence = savestate; state->history_list_enable = settings->bools.history_list_enable; state->pixel_format_type = video_driver_get_pixel_format(); if (!fullpath) { if (savestate) snprintf(state->filename, sizeof(state->filename), "%s.png", name_base); else { if (settings->bools.auto_screenshot_filename) { const char *screenshot_name = NULL; if (path_is_empty(RARCH_PATH_CONTENT)) { if (string_is_empty(system_info.library_name)) screenshot_name = "RetroArch"; else screenshot_name = system_info.library_name; } else screenshot_name = path_basename(name_base); fill_str_dated_filename(state->shotname, screenshot_name, IMG_EXT, sizeof(state->shotname)); } else snprintf(state->shotname, sizeof(state->shotname), "%s.png", path_basename(name_base)); fill_pathname_join(state->filename, screenshot_dir, state->shotname, sizeof(state->filename)); } } #if defined(HAVE_RPNG) buf = (uint8_t*)malloc(width * height * 3); if (!buf) { if (task) free(task); free(state); return false; } state->out_buffer = buf; #endif task->type = TASK_TYPE_BLOCKING; task->state = state; task->handler = task_screenshot_handler; if (use_thread) { if (!savestate) task->title = strdup(msg_hash_to_str(MSG_TAKING_SCREENSHOT)); if (!task_queue_push(task)) { /* There is already a blocking task going on */ if (task->title) task_free_title(task); free(task); if (state->out_buffer) free(state->out_buffer); free(state); return false; } } else { if (task) free(task); return screenshot_dump_direct(state); } return true; }