예제 #1
0
void networkinterface_wantsSend(NetworkInterface* interface, Socket* socket) {
	MAGIC_ASSERT(interface);

	/* track the new socket for sending if not already tracking */
	switch(interface->qdisc) {
		case NIQ_RR: {
			if(!g_queue_find(interface->rrQueue, socket)) {
				descriptor_ref(socket);
				g_queue_push_tail(interface->rrQueue, socket);
			}
			break;
		}
		case NIQ_FIFO:
		default: {
			if(!priorityqueue_find(interface->fifoQueue, socket)) {
				descriptor_ref(socket);
				priorityqueue_push(interface->fifoQueue, socket);
			}
			break;
		}
	}

	/* trigger a send if we are currently idle */
	if(!(interface->flags & NIF_SENDING)) {
		_networkinterface_scheduleNextSend(interface);
	}
}
예제 #2
0
void
empathy_tp_chat_acknowledge_message (EmpathyTpChat *chat,
				     EmpathyMessage *message) {
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	GArray *message_ids;
	GList *m;
	guint id;

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (priv->ready);

	if (empathy_message_get_sender (message) == priv->user)
		goto out;

	message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);

	id = empathy_message_get_id (message);
	g_array_append_val (message_ids, id);
	acknowledge_messages (chat, message_ids);
	g_array_free (message_ids, TRUE);

out:
	m = g_queue_find (priv->pending_messages_queue, message);
	g_assert (m != NULL);
	g_queue_delete_link (priv->pending_messages_queue, m);
	g_object_unref (message);
}
예제 #3
0
static ModemCall *
modem_call_service_get_dialed (ModemCallService *self,
                               char const *object_path,
                               char const *remote)
{
  ModemCallServicePrivate *priv = self->priv;
  ModemCall *ci;

  ci = g_hash_table_lookup (priv->instances, object_path);
  if (ci)
    {
      DEBUG ("call already exists %p", (void *)ci);

      if (g_queue_find (priv->dialing.created, ci))
        g_queue_remove (priv->dialing.created, ci);

      return ci;
    }

  ci = g_object_new (MODEM_TYPE_CALL,
      "object-path", object_path,
      "call-service", self,
      "remote", remote,
      "state", MODEM_CALL_STATE_DIALING,
      "ofono-state", "dialing",
      "terminating", FALSE,
      "originating", TRUE,
      NULL);

  modem_call_service_connect_to_instance (self, ci);

  return ci;
}
예제 #4
0
static gboolean
TryVisibilityAroundBlock(P2trPSLG        *PSLG,
                         P2trVector2     *P,
                         P2trPSLG        *ToSee,
                         P2trPSLG        *KnownBlocks,
                         GQueue          *BlocksForTest,
                         /* Try on the edges of this block */
                         const P2trBoundedLine *BlockBeingTested,
                         const P2trVector2     *SideOfBlock)
{
  const P2trVector2 *S = SideOfBlock;
  P2trVector2 ClosestIntersection;
  P2trBoundedLine PS;
  
  p2tr_bounded_line_init (&PS, P, S);

  if (find_closest_intersection (ToSee, &PS.infinite, P, &ClosestIntersection))
    {
      P2trPSLGIter iter;
      P2trBoundedLine PK;
      const P2trBoundedLine *Segment = NULL;
      p2tr_bounded_line_init (&PK, P, &ClosestIntersection);

      /* Now we must make sure that the bounded line PK is inside
       * the polygon, because otherwise it is not considered as a
       * valid visibility path */

      p2tr_pslg_iter_init (&iter, PSLG);
      while (p2tr_pslg_iter_next (&iter, &Segment))
        {
          if (Segment == BlockBeingTested)
              continue;

          /* If we have two segments with a shared point,
           * the point should not be blocked by any of them
           */
          if (p2tr_vector2_is_same (SideOfBlock, &(Segment->start))
              || p2tr_vector2_is_same (SideOfBlock, &(Segment->end)))
              continue;

          if (p2tr_bounded_line_intersect (Segment, &PK))
            {
              if (g_queue_find (BlocksForTest, Segment))
                {
                  g_queue_push_tail (BlocksForTest, (P2trBoundedLine*)Segment);
                }
              /* obstruction found! */
              return FALSE;
            }
        }

      if (LineIsOutsidePolygon (&PK, PSLG))
        return FALSE;

      /* No obstruction! */
      return TRUE;
    }
  /* No intersection for this attempt, continue */
  return FALSE;
}
예제 #5
0
void gate_list_neighbors (gate_t *g, GQueue *gates, int radius, GQueue *neighbors)
{
    if (radius == 0) {
        if (!g_queue_find (neighbors, g))
            g_queue_push_tail (neighbors, g);
    } else {
        for (int i=0;i<g->ng;i++) {
            gate_t *gg = gate_find_by_uid (gates, g->ng_names[i]);
            if (!gg) {
                dbg (DBG_ERROR, "failed to find gate %d, neighbor of %d, radius = %d",
                        g->ng_names[i], g->uid, radius);
                assert (false);
            }
            if (!g_queue_find (neighbors, gg))
                g_queue_push_tail (neighbors, gg);
            gate_list_neighbors (gg, gates, radius-1, neighbors);
        }
    }
}
예제 #6
0
파일: dis.c 프로젝트: jgraef/PUSH
static void push_instr_code_member(push_t *push, void *userdata) {
  push_val_t *val1, *val2;

  if (CH(push->code, 2)) {
    val1 = push_stack_pop_code(push);
    val2 = push_stack_pop(push->code);

    push_stack_push_new(push, push->boolean, PUSH_TYPE_BOOL, g_queue_find(val1->code, val2) != NULL);
  }
}
예제 #7
0
void
mex_download_queue_cancel (MexDownloadQueue *queue,
                           gpointer          id)
{
  MexDownloadQueuePrivate *priv;
  DQTask *task = id;
  GList *l;

  g_return_if_fail (MEX_IS_DOWNLOAD_QUEUE (queue));
  g_return_if_fail (id);

  priv = queue->priv;

  MEX_NOTE (DOWNLOAD_QUEUE, "cancelling download: %s", task->any.uri);

  l = g_queue_find (priv->queue, task);
  if (l)
    {
      /* Make sure our last-local link stays valid */
      if (priv->last_local == l)
        priv->last_local = l->prev;

      mex_download_queue_free (task);
      g_queue_delete_link (priv->queue, l);

      g_object_notify (G_OBJECT (queue), "queue-length");

      return;
    }

  switch (task->type)
    {
    case MEX_DQ_TYPE_SOUP:
      soup_session_cancel_message (priv->session,
                                   task->soup.message,
                                   SOUP_STATUS_CANCELLED);
      break;

    case MEX_DQ_TYPE_GIO:
      g_cancellable_cancel (task->gio.cancellable);
      break;

    case MEX_DQ_TYPE_CACHED:
      if (task->cached.source_id)
        g_source_remove (task->cached.source_id);
      task->cached.source_id = 0;

      mex_download_queue_free (task);
      break;

    default:
      g_warning ("Unknown download type cancelled! %d", task->type);
      break;
    }
}
예제 #8
0
TEST_F(GQueueTest, find)
{
	int testData1 = 42;
	int testData2 = 1337;
	int testData3 = 27;

	GList *list = NULL;
	list = g_list_append(list, &testData1);
	list = g_list_append(list, &testData2);
	queue->head = list;
	queue->tail = list->next->next;
	queue->length = 2;

	GList *find = g_queue_find(queue, &testData1);
	ASSERT_EQ(list, find) << "first element should be found";
	find = g_queue_find(queue, &testData2);
	ASSERT_EQ(list->next, find) << "second element should be found";
	find = g_queue_find(queue, &testData3);
	ASSERT_TRUE(find == NULL) << "unknown element should not be found";
}
예제 #9
0
void
ev_job_scheduler_update_job (EvJob         *job,
			     EvJobPriority  priority)
{
	GSList         *l;
	EvSchedulerJob *s_job = NULL;
	gboolean        need_resort = FALSE;

	/* Main loop jobs are scheduled inmediately */
	if (ev_job_get_run_mode (job) == EV_JOB_RUN_MAIN_LOOP)
		return;

	ev_debug_message (DEBUG_JOBS, "%s pirority %d", EV_GET_TYPE_NAME (job), priority);
	
	G_LOCK (job_list);

	for (l = job_list; l; l = l->next) {
		s_job = (EvSchedulerJob *)l->data;

		if (s_job->job == job) {
			need_resort = (s_job->priority != priority);
			break;
		}
	}
	
	G_UNLOCK (job_list);

	if (need_resort) {
		GList *list;
	
		g_mutex_lock (&job_queue_mutex);
		
		list = g_queue_find (job_queue[s_job->priority], s_job);
		if (list) {
			ev_debug_message (DEBUG_JOBS, "Moving job %s from pirority %d to %d",
					  EV_GET_TYPE_NAME (job), s_job->priority, priority);
			g_queue_delete_link (job_queue[s_job->priority], list);
			g_queue_push_tail (job_queue[priority], s_job);
			g_cond_broadcast (&job_queue_cond);
		}
		
		g_mutex_unlock (&job_queue_mutex);
	}
}
예제 #10
0
void
empathy_tp_chat_acknowledge_messages (EmpathyTpChat *chat,
				      const GList *messages) {
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	/* Copy messages as the messges list (probably is) our own */
	GList *msgs = g_list_copy ((GList *) messages);
	GList *l;
	guint length;
	GArray *message_ids;

	g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
	g_return_if_fail (priv->ready);

	length = g_list_length ((GList *) messages);

	if (length == 0)
		return;

	message_ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), length);

	for (l = msgs; l != NULL; l = g_list_next (l)) {
		GList *m;

		EmpathyMessage *message = EMPATHY_MESSAGE (l->data);

		m = g_queue_find (priv->pending_messages_queue, message);
		g_assert (m != NULL);
		g_queue_delete_link (priv->pending_messages_queue, m);

		if (empathy_message_get_sender (message) != priv->user) {
			guint id = empathy_message_get_id (message);
			g_array_append_val (message_ids, id);
		}
		g_object_unref (message);
	}

	if (message_ids->len > 0)
		acknowledge_messages (chat, message_ids);

	g_array_free (message_ids, TRUE);
	g_list_free (msgs);
}
/**
 * rb_track_transfer_queue_cancel_batch:
 * @queue: the #RBTrackTransferQueue
 * @batch: the #RBTrackTransferBatch to cancel, or NULL for the current batch
 *
 * Removes a transfer batch from the queue.  If an entry from the
 * batch is currently being transferred, the transfer will be
 * aborted.
 */
void
rb_track_transfer_queue_cancel_batch (RBTrackTransferQueue *queue,
				      RBTrackTransferBatch *batch)
{
	gboolean found = FALSE;
	if (batch == NULL || batch == queue->priv->current) {
		batch = queue->priv->current;
		queue->priv->current = NULL;
		found = TRUE;
	} else {
		if (g_queue_find (queue->priv->batch_queue, batch)) {
			g_queue_remove (queue->priv->batch_queue, batch);
			found = TRUE;
		}
	}

	if (found) {
		_rb_track_transfer_batch_cancel (batch);
		g_object_unref (batch);

		start_next_batch (queue);
	}
}
예제 #12
0
static void
ev_scheduler_thread_job_cancelled (EvSchedulerJob *job,
				   GCancellable   *cancellable)
{
	GList   *list;
	
	ev_debug_message (DEBUG_JOBS, "%s", EV_GET_TYPE_NAME (job->job));

	g_mutex_lock (&job_queue_mutex);

	/* If the job is not still running,
	 * remove it from the job queue and job list.
	 * If the job is currently running, it will be
	 * destroyed as soon as it finishes. 
	 */
	list = g_queue_find (job_queue[job->priority], job);
	if (list) {
		g_queue_delete_link (job_queue[job->priority], list);
		g_mutex_unlock (&job_queue_mutex);
		ev_scheduler_job_destroy (job);
	} else {
		g_mutex_unlock (&job_queue_mutex);
	}
}
예제 #13
0
파일: memory.c 프로젝트: MkPereira/gcompris
static gint tux_play(){
  int rx, ry;

  if (Paused){
    g_warning("Paused");
    return TRUE;
  }

  if ( ! to_tux )
    return TRUE;

  if(secondCard)
    {
      display_card(firstCard, ON_BACK);
      firstCard = NULL;
      display_card(secondCard, ON_BACK);
      secondCard = NULL;
    }

  if (winning_pairs){
    if (!firstCard){
      firstCard = ((WINNING *) winning_pairs->data)->first ;
      display_card(firstCard, ON_FRONT);
      if (currentUiMode == UIMODE_SOUND)
	return FALSE;
      else
	return TRUE;
    } else {
      secondCard = ((WINNING *) winning_pairs->data)->second;
      display_card(secondCard, ON_FRONT);
      if (currentUiMode == UIMODE_SOUND)
	return FALSE;
      else {
	gc_sound_play_ogg ("sounds/flip.wav", NULL);
	win_id = g_timeout_add (1000,
				(GSourceFunc) hide_card, NULL);
	return TRUE;
      }
    }
  }

  // Randomly set the pair
  rx = g_random_int_range( 0, numberOfColumn);
  ry = g_random_int_range(0, numberOfLine);

  gboolean  stay_unknown = (remainingCards > (g_queue_get_length (tux_memory)
					      + (firstCard ? 1 : 0)));

  g_warning("remainingCards %d tux_memory %d -> stay_unknown %d",
	    remainingCards,
	    g_queue_get_length (tux_memory),
	    stay_unknown );

  while((memoryArray[rx][ry]->hidden) || (memoryArray[rx][ry] == firstCard)
	|| (stay_unknown && g_queue_find(tux_memory,memoryArray[rx][ry])))
    {
      g_warning("Loop to find %d %d %s", rx, ry, memoryArray[rx][ry]->data);
      rx++;
      // Wrap
      if(rx>=numberOfColumn)
	{
	  rx=0;
	  ry++;
	  if(ry>=numberOfLine)
	    ry=0;
	}
    }

  if (!firstCard){
    firstCard = memoryArray[rx][ry];
    add_card_in_tux_memory(firstCard);
    display_card(firstCard, ON_FRONT);
    if (currentUiMode == UIMODE_SOUND)
      return FALSE;
    else
      return TRUE;
  } else {
    secondCard = memoryArray[rx][ry];
    add_card_in_tux_memory(secondCard);
    display_card(secondCard, ON_FRONT);
    if (currentUiMode == UIMODE_SOUND)
      return FALSE;
    else {
      if (compare_card(firstCard, secondCard)==0){
	gc_sound_play_ogg ("sounds/flip.wav", NULL);
	win_id = g_timeout_add (1000,
				(GSourceFunc) hide_card, NULL);
	return TRUE;
      } else{
	to_tux = FALSE;
	return FALSE;
      }
    }
  }
  return FALSE;
}
예제 #14
0
static void
modem_call_request_dial_reply (DBusGProxy *proxy,
                               DBusGProxyCall *call,
                               void *_request)
{
  DEBUG ("enter");

  ModemRequest *request = _request;
  ModemCallService *self = MODEM_CALL_SERVICE (modem_request_object (request));
  ModemCallServicePrivate *priv = self->priv;
  ModemCallRequestDialReply *callback = modem_request_callback (request);
  gpointer user_data = modem_request_user_data (request);
  char *destination = modem_request_get_data (request, "call-destination");
  GError *error = NULL;
  ModemCall *ci = NULL;
  char *object_path = NULL;

  if (dbus_g_proxy_end_call (proxy, call, &error,
          DBUS_TYPE_G_OBJECT_PATH, &object_path,
          G_TYPE_INVALID))
    {
      ci = modem_call_service_get_dialed (self, object_path, destination);
    }
  else
    {
      object_path = NULL;
      modem_error_fix (&error);
    }

  if (ci)
    {
      DEBUG ("%s: instance %s (%p)", MODEM_OFACE_CALL_MANAGER ".Dial",
          object_path, (void *)ci);

      modem_message (MODEM_LOG_CALL,
          "call create request to \"%s\" successful",
          destination);
    }
  else
    {
      char ebuffer[32];

      modem_message (MODEM_LOG_CALL,
          "call create request to \"%s\" failed: %s.%s: %s",
          destination,
          modem_error_domain_prefix (error->domain),
          modem_error_name (error, ebuffer, sizeof ebuffer),
          error->message);

      DEBUG ("%s: " GERROR_MSG_FMT, MODEM_OFACE_CALL_MANAGER ".Dial",
          GERROR_MSG_CODE (error));
    }

  if (modem_request_get_data (request, "call-canceled"))
    {
      if (ci)
        modem_call_request_release (ci, NULL, NULL);
    }
  else
    {
      g_assert (ci || error);
      callback (self, request, ci, error, user_data);
    }

  if (g_queue_find (priv->dialing.queue, request))
    g_queue_remove (priv->dialing.queue, request);

  while (g_queue_is_empty (priv->dialing.queue) &&
      !g_queue_is_empty (priv->dialing.created))
    {
      char *remote;

      ci = g_queue_pop_head (priv->dialing.created);

      g_object_get (ci, "remote", &remote, NULL);

      g_signal_emit (self, signals[SIGNAL_CREATED], 0, ci, remote);

      g_free (remote);
    }

  g_free (object_path);
  g_clear_error (&error);
}
예제 #15
0
파일: fm-thumbnail.c 프로젝트: engla/libfm
void fm_thumbnail_request_cancel(FmThumbnailRequest* req)
{
    ThumbnailTask* task;
    GList* l, *l2;

    G_LOCK(queue);
    /* if it's in generator queue (most likely) */

    if(cur_generating && cur_generating->requests)
    {
        /* this is the currently processed item */
        if( l2=g_list_find(cur_generating->requests, req) )
        {
            cur_generating->requests = g_list_delete_link(cur_generating->requests, l2);
            if(!cur_generating->requests)
            {
                cur_generating->flags |= CANCEL;
                g_cancellable_cancel(generator_cancellable);
            }
            G_UNLOCK(queue);
            return;
        }
    }

    for(l=generator_queue.head; l; l=l->next)
    {
        task = (ThumbnailTask*)l->data;
        if(l2 = g_list_find(task->requests, req)) /* found the request */
        {
            task->requests = g_list_delete_link(task->requests, l2);
            if(!task->requests) /* no one is requesting this thumbnail */
            {
                if(l == generator_queue.head) /* this is the currently processed item */
                {
                    task->flags |= CANCEL;
                    if(generator_cancellable)
                        g_cancellable_cancel(generator_cancellable);
                    g_queue_delete_link(&generator_queue, l);
                }
                else
                {
                    g_queue_delete_link(&generator_queue, l);
                    thumbnail_task_free(task);
                }
            }
            G_UNLOCK(queue);
            return;
        }
    }

    /* not found, try loader queue */

    if(cur_loading && cur_loading->requests)
    {
        /* this is the currently processed item */
        if( l2=g_list_find(cur_loading->requests, req) )
        {
            cur_loading->requests = g_list_delete_link(cur_loading->requests, l2);
            if(!cur_loading->requests)
                cur_loading->flags |= CANCEL;
            G_UNLOCK(queue);
            return;
        }
    }

    for(l=loader_queue.head; l; l=l->next)
    {
        task = (ThumbnailTask*)l->data;
        if(l2 = g_list_find(task->requests, req)) /* found the request */
        {
            task->requests = g_list_delete_link(task->requests, l2);
            if(!task->requests) /* no one is requesting this thumbnail */
            {
                g_queue_delete_link(&loader_queue, l);
                thumbnail_task_free(task);
            }
            G_UNLOCK(queue);
            return;
        }
    }

    /* not found in both loader or generator queue */
    /* is it in ready queue? */
    l = g_queue_find(&ready_queue, req);
    if(l)
    {
        g_queue_delete_link(&ready_queue, l);
        fm_thumbnail_request_free(req);
        /* if there is no item left in ready queue, cancel idle handler */
        if(g_queue_is_empty(&ready_queue) && ready_idle_handler)
        {
            g_source_remove(ready_idle_handler);
            ready_idle_handler = 0;
        }
    }
    G_UNLOCK(queue);
}