EventdNdNotification * eventd_nd_notification_new(EventdPluginContext *context, EventdEvent *event, EventdNdStyle *style) { EventdNdNotification *self; self = g_new0(EventdNdNotification, 1); self->context = context; self->queue = g_hash_table_lookup(context->queues, eventd_nd_style_get_bubble_queue(style)); if ( self->queue == NULL ) self->queue = g_hash_table_lookup(context->queues, "default"); self->style = style; if ( event != NULL ) { g_queue_push_tail(self->queue->wait_queue, self); self->link = g_queue_peek_tail_link(self->queue->wait_queue); } else { self->queue->more_notification = self; g_queue_push_tail(self->queue->queue, self); self->link = g_queue_peek_tail_link(self->queue->queue); } _eventd_nd_notification_process(self, event); self->surface = self->context->backend->surface_new(self->context->backend->context, self, self->surface_size.width, self->surface_size.height); _eventd_nd_notification_refresh_list(self->context, self->queue); return self; }
static gpointer g_async_queue_pop_intern_unlocked (GAsyncQueue *queue, gboolean wait, gint64 end_time) { gpointer retval; if (!g_queue_peek_tail_link (&queue->queue) && wait) { queue->waiting_threads++; while (!g_queue_peek_tail_link (&queue->queue)) { if (end_time == -1) g_cond_wait (&queue->cond, &queue->mutex); else { if (!g_cond_wait_until (&queue->cond, &queue->mutex, end_time)) break; } } queue->waiting_threads--; } retval = g_queue_pop_tail (&queue->queue); g_assert (retval || !wait || end_time > 0); return retval; }
EventdPluginCommandStatus eventd_nd_notification_dismiss_target(EventdPluginContext *context, EventdNdDismissTarget target, EventdNdQueue *queue) { if ( queue == NULL ) { gboolean r = FALSE; GHashTableIter iter; g_hash_table_iter_init(&iter, context->queues); while ( g_hash_table_iter_next(&iter, NULL, (gpointer *) &queue) ) r = ( eventd_nd_notification_dismiss_target(context, target, queue) == EVENTD_PLUGIN_COMMAND_STATUS_OK ) || r; return r ? EVENTD_PLUGIN_COMMAND_STATUS_OK : EVENTD_PLUGIN_COMMAND_STATUS_CUSTOM_1; } GList *notification = NULL; switch ( target ) { case EVENTD_ND_DISMISS_NONE: break; case EVENTD_ND_DISMISS_ALL: { gboolean r = FALSE; notification = g_queue_peek_head_link(queue->queue); while ( notification != NULL ) { GList *next = g_list_next(notification); eventd_nd_notification_dismiss(notification->data); notification = next; r = TRUE; } return r ? EVENTD_PLUGIN_COMMAND_STATUS_OK : EVENTD_PLUGIN_COMMAND_STATUS_CUSTOM_1; } case EVENTD_ND_DISMISS_OLDEST: { if ( queue->reverse ) notification = g_queue_peek_head_link(queue->queue); else notification = g_queue_peek_tail_link(queue->queue); } break; case EVENTD_ND_DISMISS_NEWEST: { if ( queue->reverse ) notification = g_queue_peek_tail_link(queue->queue); else notification = g_queue_peek_head_link(queue->queue); } break; } if ( notification == NULL ) return EVENTD_PLUGIN_COMMAND_STATUS_CUSTOM_1; eventd_nd_notification_dismiss(notification->data); return EVENTD_PLUGIN_COMMAND_STATUS_OK; }
/** * rtp_jitter_buffer_get_ts_diff: * @jbuf: an #RTPJitterBuffer * * Get the difference between the timestamps of first and last packet in the * jitterbuffer. * * Returns: The difference expressed in the timestamp units of the packets. */ guint32 rtp_jitter_buffer_get_ts_diff (RTPJitterBuffer * jbuf) { guint64 high_ts, low_ts; RTPJitterBufferItem *high_buf, *low_buf; guint32 result; g_return_val_if_fail (jbuf != NULL, 0); high_buf = (RTPJitterBufferItem *) g_queue_peek_head_link (jbuf->packets); low_buf = (RTPJitterBufferItem *) g_queue_peek_tail_link (jbuf->packets); if (!high_buf || !low_buf || high_buf == low_buf) return 0; high_ts = high_buf->rtptime; low_ts = low_buf->rtptime; /* it needs to work if ts wraps */ if (high_ts >= low_ts) { result = (guint32) (high_ts - low_ts); } else { result = (guint32) (high_ts + G_MAXUINT32 + 1 - low_ts); } return result; }
static void empathy_roster_view_row_activated (GtkListBox *box, GtkListBoxRow *row) { EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (box); EmpathyRosterContact *contact; FolksIndividual *individual; GList *l; if (!EMPATHY_IS_ROSTER_CONTACT (row)) return; contact = EMPATHY_ROSTER_CONTACT (row); individual = empathy_roster_contact_get_individual (contact); /* Activate the oldest event associated with this contact, if any */ for (l = g_queue_peek_tail_link (self->priv->events); l != NULL; l = g_list_previous (l)) { Event *event = l->data; if (event->individual == individual) { g_signal_emit (box, signals[SIG_EVENT_ACTIVATED], 0, individual, event->user_data); return; } } g_signal_emit (box, signals[SIG_INDIVIDUAL_ACTIVATED], 0, individual); }
static void mex_proxy_add_content (MexProxy *proxy, MexContent *content) { MexProxyPrivate *priv = proxy->priv; /* Start the timer or re-start its time-out */ if (!priv->timer_timeout) { g_timer_start (priv->timer); priv->timer_timeout = g_idle_add_full (CLUTTER_PRIORITY_REDRAW, (GSourceFunc)mex_proxy_stop_timer_cb, proxy, NULL); } /* Don't spend more than 5ms before hitting the main-loop again * creating/adding objects, and make sure to maintain order. */ if (!g_queue_is_empty (priv->to_add) || g_timer_elapsed (priv->timer, NULL) * 1000 >= 5) { g_queue_push_tail (priv->to_add, g_object_ref_sink (content)); g_hash_table_insert (priv->to_add_hash, content, g_queue_peek_tail_link (priv->to_add)); return; } mex_proxy_add_content_no_defer (proxy, content); }
void sql_reserved_query_move_to_tail(sql_reserved_query *srq, reserved_query_item *rqi) { GList *to_tail = rqi->list_pos; GQueue *gq = NULL; reserved_query_item *rm_rqi = NULL; int ret = 0; if (srq == NULL || to_tail == NULL) return; ret = g_queue_link_index(srq->gq_reserved_long_query, to_tail); gq = (ret != -1) ? (srq->gq_reserved_long_query) : (srq->gq_reserved_short_query); if (g_queue_get_length(gq) == 0) return ; if (to_tail != gq->tail) { g_queue_unlink(gq, to_tail); g_queue_push_tail_link(gq, to_tail); rqi->list_pos = g_queue_peek_tail_link(gq); } #ifdef FILTER_DEBUG g_queue_travel(srq->gq_reserved_long_query); g_queue_travel(srq->gq_reserved_short_query); #endif return ; }
GList* li_http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen) { liHttpHeader *h; GList *l; for (l = g_queue_peek_tail_link(&headers->entries); l; l = g_list_previous(l)) { h = (liHttpHeader*) l->data; if (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen)) return l; } return NULL; }
static gpointer g_async_queue_pop_intern_unlocked (GAsyncQueue *queue, gboolean try_, GTimeVal *end_time) { gpointer retval; if (!g_queue_peek_tail_link (queue->queue)) { if (try_) return NULL; if (!queue->cond) queue->cond = g_cond_new (); if (!end_time) { queue->waiting_threads++; while (!g_queue_peek_tail_link (queue->queue)) g_cond_wait (queue->cond, queue->mutex); queue->waiting_threads--; } else { queue->waiting_threads++; while (!g_queue_peek_tail_link (queue->queue)) if (!g_cond_timed_wait (queue->cond, queue->mutex, end_time)) break; queue->waiting_threads--; if (!g_queue_peek_tail_link (queue->queue)) return NULL; } } retval = g_queue_pop_tail (queue->queue); g_assert (retval); return retval; }
static void explorer_append_history (Explorer* self, HistoryNode *node) { node->explorer = self; g_queue_push_tail(self->history_queue, node); /* Seems like a reasonable length... */ explorer_prune_history(self, 128); /* Our new node is now the current one for back/forward navigation */ self->history_current_link = g_queue_peek_tail_link(self->history_queue); explorer_update_history_sensitivity(self); }
void sql_reserved_query_insert(sql_reserved_query *srq, reserved_query_item *rq) { GQueue *gq = NULL; if (srq == NULL || rq == NULL) return ; gq = (rq->item_status & RQ_OVER_TIME) ? srq->gq_reserved_long_query : srq->gq_reserved_short_query; g_queue_push_tail(gq, rq); rq->list_pos = g_queue_peek_tail_link(gq); }
// input: set of gates // output: similarity matrix // void gates_compute_similarity_matrix (GQueue *gates) { GNode *tree = NULL; int count=0; GList *el = NULL; double *corrmat; double bag_radius = 10.0 * sqrt(128.0); unsigned int N = 10; int maxcount = -1; int ngates = g_queue_get_length (gates); GQueue *bags = g_queue_new (); // correlation matrix corrmat = corrmat_init (ngates, .0); // for each gate... el = g_queue_peek_tail_link (gates); while (el) { gate_t *gate = (gate_t*)el->data; navlcm_feature_list_t *fs = gate_features (gate); printf ("gate uid: %d\n", gate->uid); if (fs) { #if 0 tree_unit_testing (self->bags, &self->tree, fs, N, bag_radius); #else if (!tree) tree = tree_init_from_void (128); // vote for closest gate so far bag_t_vote_for_indices (bags, fs, tree, N, bag_radius, gate->uid, corrmat, ngates); bag_tree_t_insert_feature_list (NULL, tree, fs, N, bag_radius, gate->uid); #endif } if (tree) tree_print_info (tree); el = el->prev; count++; if (maxcount != -1 && count>maxcount) break; } // print out the correlation matrix class_corrmat_write (corrmat, ngates, "corrmat.txt"); }
static void gegl_tile_backend_swap_push_queue (ThreadParams *params) { g_mutex_lock (&mutex); g_queue_push_tail (queue, params); if (params->operation == OP_WRITE) params->entry->link = g_queue_peek_tail_link (queue); /* wake up the writer thread */ g_cond_signal (&queue_cond); g_mutex_unlock (&mutex); }
static guint64 get_buffer_level (RTPJitterBuffer * jbuf) { GstBuffer *high_buf = NULL, *low_buf = NULL; guint64 level; GList *find; /* first first buffer with timestamp */ find = g_queue_peek_head_link (jbuf->packets); while (find) { high_buf = find->data; if (GST_BUFFER_TIMESTAMP (high_buf) != -1) break; high_buf = NULL; find = g_list_next (find); } find = g_queue_peek_tail_link (jbuf->packets); while (find) { low_buf = find->data; if (GST_BUFFER_TIMESTAMP (low_buf) != -1) break; low_buf = NULL; find = g_list_previous (find); } if (!high_buf || !low_buf || high_buf == low_buf) { level = 0; } else { guint64 high_ts, low_ts; high_ts = GST_BUFFER_TIMESTAMP (high_buf); low_ts = GST_BUFFER_TIMESTAMP (low_buf); if (high_ts > low_ts) level = high_ts - low_ts; else level = 0; GST_LOG_OBJECT (jbuf, "low %" GST_TIME_FORMAT " high %" GST_TIME_FORMAT " level %" G_GUINT64_FORMAT, GST_TIME_ARGS (low_ts), GST_TIME_ARGS (high_ts), level); } return level; }
int main(int argc, char** argv) { GQueue* q = g_queue_new(); g_queue_push_tail(q, "Alice"); g_queue_push_tail(q, "Bob"); g_queue_push_tail(q, "Fred"); printf("Queue is Alice, Bob, and Fred; removing Bob\n"); int fred_pos = g_queue_index(q, "Fred"); g_queue_remove(q, "Bob"); printf("Fred moved from %d to %d\n", fred_pos, g_queue_index(q, "Fred")); printf("Bill is cutting in line\n"); GList* fred_ptr = g_queue_peek_tail_link(q); g_queue_insert_before(q, fred_ptr, "Bill"); printf("Middle person is now %s\n", g_queue_peek_nth(q, 1)); printf("%s is still at the end\n", g_queue_peek_tail(q)); g_queue_free(q); return 0; }
TEST_F(GQueueTest, peekLink) { int testData1 = 42; int testData2 = 1337; g_queue_push_tail(queue, &testData1); g_queue_push_tail(queue, &testData2); GList *link = g_queue_peek_head_link(queue); ASSERT_EQ(queue->head, link) << "peeking at the head of the queue should produce expected element"; link = g_queue_peek_tail_link(queue); ASSERT_EQ(queue->tail, link) << "peeking at the tail of the queue should produce expected element"; link = g_queue_peek_nth_link(queue, 0); ASSERT_EQ(queue->head, link) << "peeking at the first element of the queue should produce expected element"; link = g_queue_peek_nth_link(queue, 1); ASSERT_EQ(queue->tail, link) << "peeking at the second element of the queue should produce expected element"; }
static guint64 get_buffer_level (RTPJitterBuffer * jbuf) { RTPJitterBufferItem *high_buf = NULL, *low_buf = NULL; guint64 level; /* first first buffer with timestamp */ high_buf = (RTPJitterBufferItem *) g_queue_peek_tail_link (jbuf->packets); while (high_buf) { if (high_buf->dts != -1) break; high_buf = (RTPJitterBufferItem *) g_list_previous (high_buf); } low_buf = (RTPJitterBufferItem *) g_queue_peek_head_link (jbuf->packets); while (low_buf) { if (low_buf->dts != -1) break; low_buf = (RTPJitterBufferItem *) g_list_next (low_buf); } if (!high_buf || !low_buf || high_buf == low_buf) { level = 0; } else { guint64 high_ts, low_ts; high_ts = high_buf->dts; low_ts = low_buf->dts; if (high_ts > low_ts) level = high_ts - low_ts; else level = 0; GST_LOG_OBJECT (jbuf, "low %" GST_TIME_FORMAT " high %" GST_TIME_FORMAT " level %" G_GUINT64_FORMAT, GST_TIME_ARGS (low_ts), GST_TIME_ARGS (high_ts), level); } return level; }
// assumes that gates are stored in backward order (i.e head of the queue is latest gate) // void gates_renumber (GQueue *gates) { int count=0; dbg (DBG_CLASS, "renumbering %d gates.", g_queue_get_length (gates)); // renumber gates for (GList *iter=g_queue_peek_tail_link(gates);iter;iter=g_list_previous(iter)) { gate_t *g = (gate_t*)iter->data; if (g->uid != count) { for (GList *iter=g_queue_peek_head_link(gates);iter;iter=g_list_next(iter)) { gate_t *g2 = (gate_t*)iter->data; gate_replace_in_neighbors (g2, g->uid, count); } g->uid = count; } count++; } // sanity check gates_sanity_check (gates); }
/** ******************************************************************************* * @brief Save a serial (token) in the queue and map. * * @attention locks the serial lock * * @param serial_info IN serial info * @param serial IN message serial (token) to save * @param lserror OUT set on error * * @retval true on success * @retval false on failure ******************************************************************************* */ bool _LSTransportSerialSave(_LSTransportSerial *serial_info, _LSTransportMessage *message, LSError *lserror) { LSMessageToken serial = _LSTransportMessageGetToken(message); _LSTransportSerialListItem *item = _LSTransportSerialListItemNew(serial, message); SERIAL_INFO_LOCK(&serial_info->lock); g_queue_push_tail(serial_info->queue, item); GList *list = g_queue_peek_tail_link(serial_info->queue); LS_ASSERT(list != NULL); _LSTransportSerialMapEntry *map_entry = _LSTransportSerialMapEntryNew(serial, list); LS_ASSERT(NULL == g_hash_table_lookup(serial_info->map, &map_entry->serial)); g_hash_table_insert(serial_info->map, &map_entry->serial, map_entry); SERIAL_INFO_UNLOCK(&serial_info->lock); return true; }
/* convert track to lcm structure */ navlcm_track_t *track_to_lcm (track2_t *t) { if (g_queue_is_empty (t->data)) return NULL; navlcm_track_t *tr = (navlcm_track_t*)malloc(sizeof(navlcm_track_t)); tr->ft.num = g_queue_get_length (t->data); tr->ft.el = (navlcm_feature_t*)malloc(tr->ft.num*sizeof(navlcm_feature_t)); int i=0; for (GList *iter=g_queue_peek_tail_link(t->data);iter;iter=iter->prev) { navlcm_feature_t *f = navlcm_feature_t_copy ((navlcm_feature_t*)iter->data); tr->ft.el[i] = *f; if (i==0) tr->time_start = f->utime; if (i==tr->ft.num-1) tr->time_end = f->utime; free (f); i++; } tr->ttl = 1; tr->uid = 0; return tr; }
static void gegl_tile_backend_swap_push_queue (ThreadParams *params) { g_mutex_lock (&mutex); /* block if the queue has gotten too big */ while (queue_size > gegl_config ()->queue_size) g_cond_wait (&max_cond, &mutex); g_queue_push_tail (queue, params); if (params->operation == OP_WRITE) { params->entry->link = g_queue_peek_tail_link (queue); queue_size += params->length + sizeof (GList) + sizeof (ThreadParams); } /* wake up the writer thread */ g_cond_signal (&queue_cond); g_mutex_unlock (&mutex); }
static void li_connection_reset_keep_alive(liConnection *con) { liVRequest *vr = con->mainvr; if (NULL == con->con_sock.raw_in || NULL == con->con_sock.raw_out || con->in.source != con->con_sock.raw_in) { li_connection_reset(con); return; } /* only start keep alive watcher if there isn't more input data already */ if (con->con_sock.raw_in->out->length == 0) { li_event_stop(&con->keep_alive_data.watcher); { con->keep_alive_data.max_idle = CORE_OPTION(LI_CORE_OPTION_MAX_KEEP_ALIVE_IDLE).number; if (con->keep_alive_data.max_idle == 0) { con->state = LI_CON_STATE_CLOSE; con_iostream_shutdown(con); li_connection_reset(con); return; } con->keep_alive_data.timeout = li_cur_ts(con->wrk) + con->keep_alive_data.max_idle; if (con->keep_alive_data.max_idle == con->srv->keep_alive_queue_timeout) { /* queue is sorted by con->keep_alive_data.timeout */ gboolean need_start = (0 == con->wrk->keep_alive_queue.length); con->keep_alive_data.timeout = li_cur_ts(con->wrk) + con->srv->keep_alive_queue_timeout; g_queue_push_tail(&con->wrk->keep_alive_queue, con); con->keep_alive_data.link = g_queue_peek_tail_link(&con->wrk->keep_alive_queue); if (need_start) li_worker_check_keepalive(con->wrk); } else { li_event_timer_once(&con->keep_alive_data.watcher, con->keep_alive_data.max_idle); } } } else { li_stream_again_later(&con->in); } con->state = LI_CON_STATE_KEEP_ALIVE; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; con->out_has_all_data = FALSE; con->info.keep_alive = TRUE; li_connection_update_io_wait(con); li_vrequest_reset(con->mainvr, TRUE); li_http_request_parser_reset(&con->req_parser_ctx); li_stream_disconnect(&con->out); li_stream_disconnect_dest(&con->in); con->out.out->is_closed = FALSE; memset(&con->in_chunked_decode_state, 0, sizeof(con->in_chunked_decode_state)); /* restore chunkqueue limits */ li_chunkqueue_use_limit(con->con_sock.raw_in->out, LI_CONNECTION_DEFAULT_CHUNKQUEUE_LIMIT); li_chunkqueue_use_limit(con->con_sock.raw_out->out, LI_CONNECTION_DEFAULT_CHUNKQUEUE_LIMIT); /* reset stats */ con->info.stats.bytes_in = G_GUINT64_CONSTANT(0); con->info.stats.bytes_in_5s = G_GUINT64_CONSTANT(0); con->info.stats.bytes_in_5s_diff = G_GUINT64_CONSTANT(0); con->info.stats.bytes_out = G_GUINT64_CONSTANT(0); con->info.stats.bytes_out_5s = G_GUINT64_CONSTANT(0); con->info.stats.bytes_out_5s_diff = G_GUINT64_CONSTANT(0); con->info.stats.last_avg = 0; }
void nautilus_create_thumbnail (NautilusFile *file) { time_t file_mtime = 0; NautilusThumbnailInfo *info; NautilusThumbnailInfo *existing_info; GList *existing, *node; nautilus_file_set_is_thumbnailing (file, TRUE); info = g_new0 (NautilusThumbnailInfo, 1); info->image_uri = nautilus_file_get_uri (file); info->mime_type = nautilus_file_get_mime_type (file); /* Hopefully the NautilusFile will already have the image file mtime, so we can just use that. Otherwise we have to get it ourselves. */ if (file->details->got_file_info && file->details->file_info_is_up_to_date && file->details->mtime != 0) { file_mtime = file->details->mtime; } else { get_file_mtime (info->image_uri, &file_mtime); } info->original_file_mtime = file_mtime; #ifdef DEBUG_THUMBNAILS g_message ("(Main Thread) Locking mutex\n"); #endif pthread_mutex_lock (&thumbnails_mutex); /********************************* * MUTEX LOCKED *********************************/ if (thumbnails_to_make_hash == NULL) { thumbnails_to_make_hash = g_hash_table_new (g_str_hash, g_str_equal); } /* Check if it is already in the list of thumbnails to make. */ existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri); if (existing == NULL) { /* Add the thumbnail to the list. */ #ifdef DEBUG_THUMBNAILS g_message ("(Main Thread) Adding thumbnail: %s\n", info->image_uri); #endif g_queue_push_tail ((GQueue *)&thumbnails_to_make, info); node = g_queue_peek_tail_link ((GQueue *)&thumbnails_to_make); g_hash_table_insert (thumbnails_to_make_hash, info->image_uri, node); /* If the thumbnail thread isn't running, and we haven't scheduled an idle function to start it up, do that now. We don't want to start it until all the other work is done, so the GUI will be updated as quickly as possible.*/ if (thumbnail_thread_is_running == FALSE && thumbnail_thread_starter_id == 0) { thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL); } } else { #ifdef DEBUG_THUMBNAILS g_message ("(Main Thread) Updating non-current mtime: %s\n", info->image_uri); #endif /* The file in the queue might need a new original mtime */ existing_info = existing->data; existing_info->original_file_mtime = info->original_file_mtime; free_thumbnail_info (info); } /********************************* * MUTEX UNLOCKED *********************************/ #ifdef DEBUG_THUMBNAILS g_message ("(Main Thread) Unlocking mutex\n"); #endif pthread_mutex_unlock (&thumbnails_mutex); }
static void on_go_menu_show (GtkWidget *menu, Explorer *self) { const int max_linear_items = 4; const int max_scaled_items = 10; int i, num_scaled_items; GList *current; gdouble t_total, t; GTimeVal *scaled_reference; HistoryNode* node; explorer_cleanup_go_items(self); /* If our queue is empty, add a new record immediately. This * will prevent us from getting an empty 'go' menu right after * startup- instead it will have a thumbnail of our defaults * or whatever image the user happened to load. This can't * go in our initialization above since that happens before * we've actually rendered anything. Putting it here is more * reliable than using a timer. */ if (self->history_queue->length < 1) explorer_append_history(self, history_node_new(HISTOGRAM_IMAGER(self->map))); /* The first few items are straight from the most recent list */ current = g_queue_peek_tail_link(self->history_queue); for (i=0; i<max_linear_items; i++) { if (!current) return; explorer_add_go_item(self, current); current = current->prev; } /* The rest of the list is spread evenly over time, from the end * of the above section back to the oldest history we have. */ if (!current) return; node = current->data; scaled_reference = &node->timestamp; t_total = timeval_subtract(scaled_reference, &((HistoryNode*)g_queue_peek_head(self->history_queue))->timestamp); num_scaled_items = MIN(self->history_queue->length - max_linear_items, max_scaled_items); if (num_scaled_items <= 0) return; for (i=0; i<num_scaled_items; i++) { /* For each item on the scaled_items list, find the * node at the proper position in time. */ while (1) { if (!current) return; node = current->data; t = timeval_subtract(scaled_reference, &node->timestamp); if (t > (i*t_total/num_scaled_items)) break; current = current->prev; } explorer_add_go_item(self, current); } }
void gates_save_layout (GQueue *gates, const char *mode, const char *format, const char *filename) { Agraph_t *graph; GVC_t* context; if (!gates || g_queue_is_empty (gates)) return; // create context (automatically calls aginit()) context = gvContext(); // open a graph graph = agopen((char*)"map", AGRAPHSTRICT); // strict, directed graph // add all gates to the graph // for (GList *iter=g_queue_peek_tail_link (gates);iter;iter=g_list_previous (iter)) { gate_t *gate = (gate_t*)iter->data; char name[5]; sprintf (name, "%d", gate->uid); printf ("creating node with name %s\n", name); agnode (graph, name); } // create edges int count=0; for (GList *iter=g_queue_peek_tail_link (gates);iter;iter=g_list_previous (iter)) { gate_t *gate = (gate_t*)iter->data; // find corresponding node char name[5]; sprintf (name, "%d", gate->uid); Agnode_t *n1 = agfindnode (graph, name); if (!n1) { dbg (DBG_ERROR, "failed to retrieve node from name %s", name); continue; } printf ("adding %d edges to node %d\n", gate->ng, gate->uid); for (int j=0;j<gate->ng;j++) { sprintf (name, "%d", gate->ng_names[j]); Agnode_t *n2 = agfindnode (graph, name); if (!n2) { dbg (DBG_ERROR, "failed to retrieve node from name %s", name); continue; } agedge (graph, n1, n2); count++; } } printf ("created %d edges.\n", count); // layout the graph // choices are: manual, fdp, dot, neato, twopi, circo dbg (DBG_CLASS, "rendering graph with graphviz. mode = %s", mode); if (strcmp (mode, "fdp")) { gvLayout (context, graph, (char*)"fdp"); } if (strcmp (mode, "dot")) { gvLayout (context, graph, (char*)"dot"); } if (strcmp (mode, "neato")) { gvLayout (context, graph, (char*)"neato"); } if (strcmp (mode, "twopi")) { gvLayout (context, graph, (char*)"twopi"); } if (strcmp (mode, "circo")) { gvLayout (context, graph, (char*)"circo"); } // render graph to file dbg (DBG_CLASS, "saving graph to file %s", filename); gvRenderFilename(context, graph, (char*)format, (char*)filename); dbg (DBG_CLASS, "done."); // free graph gvFreeLayout(context, graph); agclose (graph); gvFreeContext(context); }
/* This should run pretty quick, its called a lot */ iconv_t camel_iconv_open (const gchar *oto, const gchar *ofrom) { const gchar *to, *from; gchar *tofrom; struct _iconv_cache *ic; struct _iconv_cache_node *in; gint errnosav; iconv_t ip; if (oto == NULL || ofrom == NULL) { errno = EINVAL; return (iconv_t) -1; } to = camel_iconv_charset_name (oto); from = camel_iconv_charset_name (ofrom); tofrom = g_alloca (strlen (to) + strlen (from) + 2); sprintf (tofrom, "%s%%%s", to, from); G_LOCK (iconv); ic = g_hash_table_lookup (iconv_cache, tofrom); if (ic) { g_queue_remove (&iconv_cache_list, ic); } else { GList *link; link = g_queue_peek_tail_link (&iconv_cache_list); while (link != NULL && iconv_cache_list.length > E_ICONV_CACHE_SIZE) { GList *prev = g_list_previous (link); ic = (struct _iconv_cache *) link->data; in = g_queue_peek_head (&ic->open); if (in != NULL && !in->busy) { cd (printf ("Flushing iconv converter '%s'\n", ic->conv)); g_queue_delete_link (&iconv_cache_list, link); g_hash_table_remove (iconv_cache, ic->conv); flush_entry (ic); } link = prev; } ic = g_malloc (sizeof (*ic)); g_queue_init (&ic->open); ic->conv = g_strdup (tofrom); g_hash_table_insert (iconv_cache, ic->conv, ic); cd (printf ("Creating iconv converter '%s'\n", ic->conv)); } g_queue_push_head (&iconv_cache_list, ic); /* If we have a free iconv, use it */ in = g_queue_peek_tail (&ic->open); if (in != NULL && !in->busy) { cd (printf ("using existing iconv converter '%s'\n", ic->conv)); ip = in->ip; if (ip != (iconv_t) - 1) { /* work around some broken iconv implementations * that die if the length arguments are NULL */ gsize buggy_iconv_len = 0; gchar *buggy_iconv_buf = NULL; /* resets the converter */ iconv (ip, &buggy_iconv_buf, &buggy_iconv_len, &buggy_iconv_buf, &buggy_iconv_len); in->busy = TRUE; g_queue_remove (&ic->open, in); g_queue_push_head (&ic->open, in); } } else { cd (printf ("creating new iconv converter '%s'\n", ic->conv)); ip = iconv_open (to, from); in = g_malloc (sizeof (*in)); in->ip = ip; in->parent = ic; g_queue_push_head (&ic->open, in); if (ip != (iconv_t) - 1) { g_hash_table_insert (iconv_cache_open, ip, in); in->busy = TRUE; } else { errnosav = errno; g_warning ("Could not open converter for '%s' to '%s' charset", from, to); in->busy = FALSE; errno = errnosav; } } G_UNLOCK (iconv); return ip; }