Exemplo n.º 1
0
void queue_prev(gboolean notif) {
    int n, p;
    int len = g_queue_get_length(&g_queue);

    g_debug("Switching to previous track.");

    if (g_shuffle) {
        /* Possible cases: g_repeat, g_current_track == -1, g_shuffle_first == -1 */
        if (g_current_track == -1) {
            if (g_shuffle_first == -1) {
                /* Pick a random track */
                n = g_random_int_range(0, len);

                /* Set the next one to be the first shuffle track... */
                p = g_queue_index(&g_shuffle_queue, GINT_TO_POINTER(n));
                if (p == -1) g_error("Can't find last track in shuffle queue");
                p = (p+1) % len;
                g_shuffle_first = GPOINTER_TO_INT(g_queue_peek_nth(&g_shuffle_queue, p));
            }
            else {
                /* Find the track that comes just before the first shuffle track */
                p = g_queue_index(&g_shuffle_queue, GINT_TO_POINTER(g_shuffle_first));
                if (p == -1) g_error("Can't find first track in shuffle queue");
                p = (p-1) % len;
                n = GPOINTER_TO_INT(g_queue_peek_nth(&g_shuffle_queue, p));
            }
        }
        else {
            if (g_shuffle_first == -1) {
                g_warning("g_shuffle_first == -1 in goto_prev()");
                g_shuffle_first = g_current_track;
            }

            /* Is this the first track in non-repeat mode? */
            if ((g_current_track == g_shuffle_first) && !g_repeat) {
                n = -1;
            }
            else {
                /* Find the index of the current track in the shuffle queue */
                p = g_queue_index(&g_shuffle_queue, GINT_TO_POINTER(g_current_track));
                if (p == -1)
                    g_error("Can't find current track in shufflequeue");

                /* Find the previous track in the shuffle queue */
                p = (p+len-1) % len;
                n = GPOINTER_TO_INT(g_queue_peek_nth(&g_shuffle_queue, p));
            }
        }
    }
    else {
        n = g_current_track - 1;
        if (g_repeat)
            n %= len;
    }

    queue_goto(FALSE, n, FALSE);
    if (notif) queue_notify();
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
TEST_F(GQueueTest, index)
{
	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 = g_list_last(list);
	queue->length = 2;

	gint index = g_queue_index(queue, &testData1);
	ASSERT_EQ(0, index) << "index of first element should be zero";
	index = g_queue_index(queue, &testData2);
	ASSERT_EQ(1, index) << "index of second element should be one";
	index = g_queue_index(queue, &testData3);
	ASSERT_EQ(-1, index) << "index of unknown element should be minus one";
}
Exemplo n.º 4
0
MyShape*	my_layer_pop_shape (MyLayer *self, MyShape *shape) {

	gint pos;
	MyLayerPrivate* priv = MY_LAYER_GET_PRIVATE (self);
	
	pos = g_queue_index (priv->shapes, shape);
	if (pos != -1) { // find
		return (MyShape *) g_queue_pop_nth (priv->shapes, pos);
	}
	return NULL;
}
Exemplo n.º 5
0
Arquivo: queue.c Projeto: pes0/spop
/***************************
 *** Move into the queue ***
 ***************************/
void queue_next(gboolean notif) {
    int n, p;
    int len = g_queue_get_length(&g_queue);

    g_debug("Switching to next track (current track: %d).", g_current_track);

    if (g_repeat && len == 1) {
        /* Easy case: replay the same track */
        queue_seek(0);
        if (notif) queue_notify();
        return;
    }

    if (g_shuffle) {
        /* Possible cases: g_repeat, g_current_track == -1, g_shuffle_first == -1 */
        if (g_current_track == -1) {
            if (g_shuffle_first == -1) {
                /* Pick a random track */
                n = g_random_int_range(0, len);
                g_shuffle_first = n;
            }
            else {
                n = g_shuffle_first;
            }
        }
        else {
            if (g_shuffle_first == -1) {
                g_warning("g_shuffle_first == -1 in goto_next()");
                g_shuffle_first = g_current_track;
            }

            /* Find the index of the current track in the shuffle queue */
            p = g_queue_index(&g_shuffle_queue, GINT_TO_POINTER(g_current_track));
            if (p == -1) g_error("Can't find current track in shuffle queue");

            /* Find the next track in the shuffle queue */
            p = (p+1) % len;
            n = GPOINTER_TO_INT(g_queue_peek_nth(&g_shuffle_queue, p));

            if ((n == g_shuffle_first) && !g_repeat)
                n = -1;
        }
    }
    else {
        n = g_current_track + 1;
        if (g_repeat)
            n %= len;
    }

    queue_goto(FALSE, n, FALSE);
    if (notif) queue_notify();
}
Exemplo n.º 6
0
void
joy_gfx3d_screen_lower_window(JoyScreen *self, JoyBubble *window)
{
	struct Private *priv = GET_PRIVATE(self);
	if (G_UNLIKELY(!priv->windows)) {
		return;
	}
	gint n = g_queue_index(priv->windows, window);
	if (G_UNLIKELY(-1 == n)) {
		return;
	}
	GList *node = g_queue_pop_nth_link(priv->windows, n);
	if (G_UNLIKELY(!node)) {
		return;
	}
	g_queue_push_tail_link(priv->windows, node);
}
Exemplo n.º 7
0
static void
send_receive_menu_service_added_cb (EMailAccountStore *account_store,
                                    CamelService *service,
                                    SendReceiveData *data)
{
	GQueue *services;

	if (!send_receive_can_use_service (account_store, service, NULL))
		return;

	services = g_queue_new ();

	g_queue_push_head (services, service);
	g_hash_table_foreach (data->menu_items, send_receive_gather_services, services);
	g_queue_sort (services, sort_services_cb, account_store);

	send_receive_add_to_menu (data, service, g_queue_index (services, service));

	g_queue_free (services);
}
Exemplo n.º 8
0
static GstFlowReturn
gst_freeze_play (GstPad * pad, GstBuffer * buff)
{
  GstFreeze *freeze;
  guint64 cur_offset;
  GstFlowReturn ret = GST_FLOW_OK;

  freeze = GST_FREEZE (gst_pad_get_parent (pad));

  if (freeze->on_flush) {
    g_object_unref (freeze);
    return GST_FLOW_WRONG_STATE;
  }

  cur_offset = freeze->offset;
  /* If it is working in push mode this function will be called by "_chain"
     and buff will never be NULL. In pull mode this function will be called
     by _loop and buff will be NULL */
  if (!buff) {
    ret =
        gst_pad_pull_range (GST_PAD (freeze->sinkpad), freeze->offset, 4096,
        &buff);
    if (ret != GST_FLOW_OK) {
      gst_object_unref (freeze);
      return ret;
    }

    freeze->offset += GST_BUFFER_SIZE (buff);

  }

  if (g_queue_get_length (freeze->buffers) < freeze->max_buffers ||
      freeze->max_buffers == 0) {
    g_queue_push_tail (freeze->buffers, buff);
    GST_DEBUG_OBJECT (freeze, "accepted buffer %u",
        g_queue_get_length (freeze->buffers) - 1);
  } else {
    gst_buffer_unref (buff);
  }


  if (freeze->current != NULL) {
    GST_DEBUG_OBJECT (freeze, "switching to next buffer");
    freeze->current = g_queue_peek_nth (freeze->buffers,
        g_queue_index (freeze->buffers, (gpointer) freeze->current) + 1);
  }

  if (freeze->current == NULL) {
    if (freeze->max_buffers > 1)
      GST_DEBUG_OBJECT (freeze, "restarting the loop");
    freeze->current = g_queue_peek_head (freeze->buffers);
  }

  GST_BUFFER_TIMESTAMP (freeze->current) = freeze->timestamp_offset +
      freeze->running_time;
  freeze->running_time += GST_BUFFER_DURATION (freeze->current);

  gst_buffer_ref (freeze->current);
  ret = gst_pad_push (freeze->srcpad, freeze->current);

  gst_object_unref (freeze);

  return ret;
}
Exemplo n.º 9
0
int random_rcl_assignment(Job *jobarray, int njobs, int nmachines,
                          solution *new_sol, GRand *rand_) {
    int i;
    double max;
    double min;
    double lb, ub;
    double temp_dbl;
    partlist *temp = (partlist *) NULL;
    Job *temp_job = (Job *) NULL;
    //GList *it = (GList *) NULL;
    GQueue *to_do_list = (GQueue *) NULL;
    temp = new_sol->part;
    to_do_list = g_queue_new();

    for (i = 0; i < njobs; ++i) {
        g_queue_push_tail(to_do_list, jobarray + i);
    }

    while (!g_queue_is_empty(to_do_list)) {
        temp_job = (Job *)to_do_list->head->data;
        max = ((double)temp[0].completiontime + (double)temp_job->processingime);
        min = max;
        GArray *rcl = g_array_new(FALSE, FALSE, sizeof(pair_job_machine));

        /** Compute min and max */
        for (i = 1; i < nmachines; ++i) {
            //for (it = to_do_list->head; it; it = it->next)
            //{
            //temp_job = (Job*)it->data;
            temp_dbl = (temp[i].completiontime + temp_job->processingime);

            if (max < temp_dbl) {
                max = temp_dbl;
            }

            if (min > temp_dbl) {
                min = temp_dbl;
            }

            //}
        }

        /** Compute RCL */
        pair_job_machine temp_job_machine;
        lb = min;
        ub = min + 0.25 * (max - lb);

        for (i = 0; i < nmachines; ++i) {
            //for (it = to_do_list->head; it; it = g_list_next(it))
            //{
            //temp_job = ((Job*)it->data);
            double g = ((double)temp[i].completiontime + (double)temp_job->processingime);

            if (lb <= g && g <= ub) {
                temp_job_machine.job = temp_job->job;
                temp_job_machine.machine = i;
                g_array_append_val(rcl, temp_job_machine);
            }

            //}
        }

        /** Choose uniformaly an assignment of a job to a machine */
        int a = g_rand_int_range(rand_, 0, rcl->len);
        int job = g_array_index(rcl, pair_job_machine, a).job;
        int machine = g_array_index(rcl, pair_job_machine, a).machine;
        partlist_insert(temp + machine, new_sol->vlist, jobarray + job);
        g_queue_pop_nth(to_do_list, g_queue_index(to_do_list, jobarray + job));
        g_array_free(rcl, TRUE);
    }

    g_queue_free(to_do_list);
    return 0;
}