int single_file_processor(char *filename, struct stat *st) { struct file_header hdr; int fd; mode_t mode = st->st_mode; hdr.namelen = strlen(filename) + 1; hdr.mode = mode; hdr.atime = st->st_atim.tv_sec; hdr.atime_nsec = st->st_atim.tv_nsec; hdr.mtime = st->st_mtim.tv_sec; hdr.mtime_nsec = st->st_mtim.tv_nsec; if (S_ISREG(mode)) { int ret; fd = open(filename, O_RDONLY); if (fd < 0) gui_fatal("open %s", filename); hdr.filelen = st->st_size; write_headers(&hdr, filename); ret = copy_file(1, fd, hdr.filelen, &crc32_sum); if (ret != COPY_FILE_OK) { if (ret != COPY_FILE_WRITE_ERROR) gui_fatal("Copying file %s: %s", filename, copy_file_status_to_str(ret)); else { set_block(0); wait_for_result(); exit(1); } } close(fd); } if (S_ISDIR(mode)) { hdr.filelen = 0; write_headers(&hdr, filename); } if (S_ISLNK(mode) && !ignore_symlinks) { char name[st->st_size + 1]; if (readlink(filename, name, sizeof(name)) != st->st_size) gui_fatal("readlink %s", filename); hdr.filelen = st->st_size + 1; write_headers(&hdr, filename); if (!write_all_with_crc(1, name, st->st_size + 1)) { set_block(0); wait_for_result(); exit(1); } } // check for possible error from qfile-unpacker wait_for_result(); return 0; }
static PGresult* get_pg_result(PlxFn *plx_fn, PlxConn *plx_conn) { PGresult *pg_result = NULL; PGresult *tmp_pg_result = NULL; while((tmp_pg_result = wait_for_result(plx_fn, plx_conn))) { ExecStatusType status = PQresultStatus(tmp_pg_result); if (status == PGRES_TUPLES_OK) { if (pg_result) { PQclear(pg_result); PQclear(tmp_pg_result); plx_error(plx_fn, "second pg_result???"); } else pg_result = tmp_pg_result; } else { if (pg_result) PQclear(pg_result); delete_plx_conn(plx_conn); pg_result_error(tmp_pg_result); } } return pg_result; }
void write_headers(struct file_header *hdr, char *filename) { if (!write_all_with_crc(1, hdr, sizeof(*hdr)) || !write_all_with_crc(1, filename, hdr->namelen)) { set_block(0); wait_for_result(); exit(1); } }
void mir_toolkit::mir_connection_release(MirConnection * connection) { if (&error_connection == connection) return; auto wait_handle = connection->disconnect(); wait_handle->wait_for_result(); delete connection; }
static GHashTable * get_properties_cb (MS2Server *server, const gchar *id, const gchar **properties, gpointer data, GError **error) { GHashTable *properties_table = NULL; GrlMedia *media; GriloMs2Data *grdata; grdata = g_slice_new0 (GriloMs2Data); grdata->server = g_object_ref (server); grdata->source = (GrlSource *) data; grdata->options = grl_operation_options_new (NULL); grdata->keys = get_grilo_keys (properties, &grdata->other_keys); grl_operation_options_set_resolution_flags (grdata->options, GRL_RESOLVE_FULL | GRL_RESOLVE_IDLE_RELAY); media = unserialize_media (grdata->source, id); if (grdata->keys) { grl_source_resolve (grdata->source, media, grdata->keys, grdata->options, resolve_cb, grdata); } else { resolve_cb (grdata->source, 0, media, grdata, NULL); } wait_for_result (grdata); if (grdata->error) { if (error) { *error = grdata->error; } } else { properties_table = grdata->properties; } g_object_unref (media); g_list_free (grdata->keys); g_list_free (grdata->other_keys); g_free (grdata->parent_id); g_object_unref (grdata->server); g_object_unref (grdata->options); g_slice_free (GriloMs2Data, grdata); return properties_table; }
void notify_end_and_wait_for_result() { struct file_header end_hdr; /* nofity end of transfer */ memset(&end_hdr, 0, sizeof(end_hdr)); end_hdr.namelen = 0; end_hdr.filelen = 0; write_all_with_crc(1, &end_hdr, sizeof(end_hdr)); set_block(0); wait_for_result(); }
void notify_progress(int size, int flag) { static long long total = 0; static long long prev_total = 0; total += size; if (total > prev_total + PROGRESS_NOTIFY_DELTA || (flag != PROGRESS_FLAG_NORMAL)) { // check for possible error from qfile-unpacker; if error occured, // exit() will be called, so don't bother with current state // (notify_progress can be called as callback from copy_file()) if (flag == PROGRESS_FLAG_NORMAL) wait_for_result(); do_notify_progress(total, flag); prev_total = total; } }
static GList * search_objects_cb (MS2Server *server, const gchar *id, const gchar *query, guint offset, guint max_count, const gchar **properties, gpointer data, GError **error) { GList *objects; GriloMs2Data *grdata; gint count; /* Browse is only allowed in root container */ if (g_strcmp0 (id, MS2_ROOT) != 0) { if (error) { /* FIXME: a better error should be reported */ *error = g_error_new (0, 0, "search is only allowed in root container"); } return NULL; } grdata = g_slice_new0 (GriloMs2Data); grdata->server = g_object_ref (server); grdata->source = (GrlSource *) data; grdata->options = grl_operation_options_new (NULL); grdata->keys = get_grilo_keys (properties, &grdata->other_keys); grdata->parent_id = g_strdup (id); grdata->list_type = LIST_ALL; grl_operation_options_set_resolution_flags (grdata->options, GRL_RESOLVE_FULL | GRL_RESOLVE_IDLE_RELAY); /* Adjust limits */ if (offset >= limit) { browse_cb (grdata->source, 0, NULL, 0, grdata, NULL); } else { count = max_count == 0? (limit - offset): CLAMP (max_count, 1, limit - offset); grl_operation_options_set_count (grdata->options, count); grl_operation_options_set_skip (grdata->options, offset); grl_source_search (grdata->source, query, grdata->keys, grdata->options, browse_cb, grdata); } wait_for_result (grdata); if (grdata->error) { if (error) { *error = grdata->error; } g_list_foreach (grdata->children, (GFunc) g_hash_table_unref, NULL); g_list_free (grdata->children); objects = NULL; } else { objects = grdata->children; } g_list_free (grdata->keys); g_list_free (grdata->other_keys); g_free (grdata->parent_id); g_object_unref (grdata->server); g_object_unref (grdata->options); g_slice_free (GriloMs2Data, grdata); return objects; }
static GList * list_children_cb (MS2Server *server, const gchar *id, ListType list_type, guint offset, guint max_count, const gchar **properties, gpointer data, GError **error) { GList *children; GrlMedia *media; GriloMs2Data *grdata; gint count; grdata = g_slice_new0 (GriloMs2Data); grdata->server = g_object_ref (server); grdata->source = (GrlSource *) data; grdata->options = grl_operation_options_new (NULL); grdata->keys = get_grilo_keys (properties, &grdata->other_keys); grdata->parent_id = g_strdup (id); grdata->offset = offset; grdata->list_type = list_type; grl_operation_options_set_resolution_flags (grdata->options, GRL_RESOLVE_FULL | GRL_RESOLVE_IDLE_RELAY); media = unserialize_media (grdata->source, id); /* Adjust limits */ if (offset >= limit) { browse_cb (grdata->source, 0, NULL, 0, grdata, NULL); } else { /* TIP: as Grilo is not able to split containers and items, in this case we will ask for all elements and then remove unneeded children in callback */ switch (list_type) { case LIST_ALL: count = max_count == 0? (limit - offset): CLAMP (max_count, 1, limit - offset); grl_operation_options_set_count (grdata->options, count); grl_operation_options_set_skip (grdata->options, offset); grdata->operation_id = grl_source_browse (grdata->source, media, grdata->keys, grdata->options, browse_cb, grdata); break; case LIST_CONTAINERS: case LIST_ITEMS: count = max_count == 0? limit: max_count; grl_operation_options_set_count (grdata->options, count); grl_operation_options_set_skip (grdata->options, 0); grdata->operation_id = grl_source_browse (grdata->source, media, grdata->keys, grdata->options, browse_cb, grdata); break; default: /* Protection. It should never be reached, unless ListType is extended */ browse_cb (grdata->source, 0, NULL, 0, grdata, NULL); } } wait_for_result (grdata); if (grdata->error) { if (error) { *error = grdata->error; } g_list_foreach (grdata->children, (GFunc) g_hash_table_unref, NULL); g_list_free (grdata->children); children = NULL; } else { children = grdata->children; } g_object_unref (media); g_list_free (grdata->keys); g_list_free (grdata->other_keys); g_free (grdata->parent_id); g_object_unref (grdata->server); g_object_unref (grdata->options); g_slice_free (GriloMs2Data, grdata); return children; }