static void
test_activation (void)
{
	CORBA_Environment   env;
	PortableServer_POA  poa;
	GSList             *objids = NULL, *l;
	int                 i;

	fprintf (stderr, "Testing object activation...\n");

	CORBA_exception_init (&env);

	POA_Test__init (&test_servant, &env);

	poa = create_mult_id_poa (&env);

	g_assert (env._major == CORBA_NO_EXCEPTION);

	g_timer_reset (timer);

	for (i = 0; i < 1000; i++) {
		PortableServer_ObjectId *objid;

		objid = PortableServer_POA_activate_object (poa, &test_servant, &env);
		g_assert (env._major == CORBA_NO_EXCEPTION);

		objids = g_slist_append (objids, objid);
	}

	elapsed_time = g_timer_elapsed (timer, NULL);
	bogomark += elapsed_time;
	fprintf (stderr, " activation : %g(ms)\n", elapsed_time);

	g_timer_reset (timer);

	for (l = objids; l; l = l->next) {
		PortableServer_POA_deactivate_object (poa, l->data, &env);
		g_assert (env._major == CORBA_NO_EXCEPTION);
	}

	elapsed_time = g_timer_elapsed (timer, NULL);
	bogomark += elapsed_time;
	fprintf (stderr, " de-activation : %g(ms)\n", elapsed_time);
	
	for (l = objids; l; l = l->next)
		CORBA_free (l->data);
	g_slist_free (objids);

	POA_Test__fini (&test_servant, &env);

	PortableServer_POA_destroy (poa, CORBA_FALSE, CORBA_FALSE, &env);
	g_assert (env._major == CORBA_NO_EXCEPTION);
	CORBA_Object_release ((CORBA_Object) poa, &env);
	g_assert (env._major == CORBA_NO_EXCEPTION);

	CORBA_exception_free (&env);
}
static void
test_copy (void)
{
	int i, j;
#define ELEMS (sizeof (tc) / sizeof (tc[0]))
	CORBA_TypeCode tc[] = {
		TC_CORBA_octet,
		TC_CORBA_sequence_CORBA_octet,
		TC_CORBA_double,
		TC_CORBA_string,
		TC_CORBA_sequence_CORBA_string,
		TC_GIOP_TargetAddress		
	};
	gpointer data [ELEMS];
	const char *test_string = "This is a sample string, for dupping";

	fprintf (stderr, "Testing copy...\n");

	for (i = 0; i < ELEMS; i++) {
		data [i] = ORBit_dynany_new_default (tc [i]);

		g_timer_reset (timer);
		for (j = 0; j < 1000; j++) {
			gpointer foo = ORBit_copy_value (data [i], tc [i]);
			CORBA_free (foo);
		}
		elapsed_time = g_timer_elapsed (timer, NULL);
		bogomark += elapsed_time;
		fprintf (stderr, " copy %20s : %g(ms)\n",
			tc[i]->repo_id == NULL ? "(null)" : tc[i]->repo_id,
			elapsed_time);
	}

	fprintf (stderr, "Testing strdup ...\n");

	g_timer_reset (timer);
	for (i = 0; i < 10000; i++) {
		char *str = g_strdup (test_string);
		g_free (str);
	}
	elapsed_time = g_timer_elapsed (timer, NULL) / 10.0;
	bogomark += elapsed_time;
	fprintf (stderr, " g_strdup :     %g(ns)\n", elapsed_time * 1000.0);
	
	g_timer_reset (timer);
	for (i = 0; i < 10000; i++) {
		char *str = CORBA_string_dup (test_string);
		CORBA_free (str);
	}
	elapsed_time = g_timer_elapsed (timer, NULL) / 10.0;
	bogomark += elapsed_time;
	fprintf (stderr, " CORBA_strdup : %g(ns)\n", elapsed_time * 1000.0);
}
Esempio n. 3
0
static int gtkDialogTaskDoubleClick(int button)
{
  static int last_button = -1;
  static GTimer* timer = NULL;
  if (last_button == -1 || last_button != button)
  {
    last_button = button;
    if (timer)
      g_timer_destroy(timer);
    timer = g_timer_new();
    return 0;
  }
  else
  {
    double seconds;

    if (!timer)  /* just in case */
      return 0;

    seconds = g_timer_elapsed(timer, NULL);
    if (seconds < 0.4)
    {
      /* reset state */
      g_timer_destroy(timer);
      timer = NULL;
      last_button = -1;  
      return 1;
    }
    else
    {
      g_timer_reset(timer);
      return 0;
    }
  }
}
Esempio n. 4
0
void
gimv_image_loader_set_image_info (GimvImageLoader *loader, GimvImageInfo *info)
{
   g_return_if_fail (GIMV_IS_IMAGE_LOADER (loader));
   g_return_if_fail (info);
   g_return_if_fail (loader->priv);

   if (gimv_image_loader_is_loading (loader)) {
      gimv_image_loader_load_stop (loader);
      if (loader->priv->next_info)
         gimv_image_info_unref (loader->priv->next_info);
      loader->priv->next_info = gimv_image_info_ref (info);
      return;
   }

   if (loader->priv->image)
      g_object_unref (G_OBJECT (loader->priv->image));
   loader->priv->image = NULL;

   g_timer_reset (loader->timer);

   if (loader->priv->temp_file)
      g_free ((gchar *)loader->priv->temp_file);
   loader->priv->temp_file = NULL;

   if (loader->info)
      gimv_image_info_unref (loader->info);

   if (info)
      loader->info = gimv_image_info_ref (info);
   else
      loader->info = NULL;
}
Esempio n. 5
0
MpdData * magnatune_db_get_genre_list()
{
    MpdData *list = NULL;
    int i,r;

    char *query = sqlite3_mprintf("SELECT genre from 'genres' group by genre");
    sqlite3_stmt *stmt = NULL;
    const char *tail;
    GTimer *timer = g_timer_new();
    r = sqlite3_prepare_v2(magnatune_sqlhandle, query, -1,  &stmt,  &tail);
    if(r ==SQLITE_OK) {
        while((r = sqlite3_step(stmt)) == SQLITE_ROW)
        {
            list = mpd_new_data_struct_append(list);
            list->type = MPD_DATA_TYPE_TAG;
            list->tag_type = MPD_TAG_ITEM_GENRE;
            list->tag = g_strdup(sqlite3_column_text(stmt,0));
        }
    }

    sqlite3_finalize(stmt);
    sqlite3_free(query);
    g_debug("%f s elapsed getting genres\n", g_timer_elapsed(timer,NULL));
    g_timer_reset(timer);
    list = misc_mpddata_remove_duplicate_songs(list); 
    g_debug("%f s elapsed unique genres list\n", g_timer_elapsed(timer,NULL));
    g_timer_destroy(timer);
    return list;
}
Esempio n. 6
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	DEBUG("First started %u processes", proc_count);

	for (;;) { /* main loop */
		struct timeval tv_sleep;

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		if (g_timer_elapsed(timer, NULL) >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				ERROR("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
		}

		tv_sleep.tv_sec = 1L;
		tv_sleep.tv_usec = 0L;
		select(0, NULL, NULL, NULL, &tv_sleep);
		errno = 0;
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
Esempio n. 7
0
File: game.c Progetto: ralight/ggz
int game_update_server(gpointer user_data)
{
	int mytime;

	mytime = g_timer_elapsed(game_info.timer, NULL);
	g_timer_reset(game_info.timer);
	net_update_server(mytime);
	return TRUE;
}
Esempio n. 8
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	GRID_DEBUG("First started %u processes", proc_count);

	while (flag_running) { /* main loop */

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				GRID_DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				GRID_DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		gdouble elapsed = g_timer_elapsed(timer, NULL);
		if (elapsed >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				GRID_WARN("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
			elapsed = 0.0;
		}

		g_usleep (1000000UL - ((gulong)elapsed));
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
int
main (int argc, char *argv[])
{
	CORBA_Environment ev;

	free (malloc (8));

	g_thread_init (NULL);

	CORBA_exception_init (&ev);

	timer = g_timer_new ();
	g_timer_start (timer);

	g_timer_reset (timer);
	orb = CORBA_ORB_init (&argc, argv, "matecorba-local-orb", &ev);
	g_assert (ev._major == CORBA_NO_EXCEPTION);
	fprintf (stderr, "ORB: init took %g(ms)\n",
		 (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
	bogomark += elapsed_time;

	test_copy ();

	test_activation ();

	g_timer_reset (timer);
	CORBA_ORB_destroy (orb, &ev);
	g_assert (ev._major == CORBA_NO_EXCEPTION);
	fprintf (stderr, "ORB: destroy took %g(ms)\n",
		 (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
	bogomark += elapsed_time;
	g_timer_reset (timer);

	CORBA_Object_release ((CORBA_Object) orb, &ev);
	g_assert (ev._major == CORBA_NO_EXCEPTION);

	g_timer_destroy (timer);

	fprintf (stderr, "Overall bogomark %g\n", 1000.0 / bogomark);

	return 0;
}
Esempio n. 10
0
/**
 * gpk_dbus_create_task:
 **/
static GpkDbusTask *
gpk_dbus_create_task (GpkDbus *dbus, guint32 xid, const gchar *interaction, DBusGMethodInvocation *context)
{
	GpkDbusTask *task;
	PkBitfield interact = 0;
	gint timeout = 0;
	gchar *sender;
	gchar *exec;
	guint timestamp = 0;
	gboolean ret;

	task = gpk_dbus_task_new ();

	/* work out what interaction the task should use */
	gpk_dbus_parse_interaction (dbus, interaction, &interact, &timeout);

	/* set interaction mode */
	g_debug ("interact=%i", (gint) interact);
	gpk_dbus_task_set_interaction (task, interact);

	/* try to get the user time of the window */
	if (xid != 0) {
		ret = gpk_x11_set_xid (dbus->priv->x11, xid);
		if (ret)
			timestamp = gpk_x11_get_user_time (dbus->priv->x11);
	}

	/* set the context for the return values */
	gpk_dbus_task_set_context (task, context);

	/* set the last interaction */
	gpk_dbus_task_set_timestamp (task, timestamp);

	/* set the window for the modal and timestamp */
        if (xid != 0)
        	gpk_dbus_task_set_xid (task, xid);

	/* get the program name and set */
	sender = dbus_g_method_get_sender (context);
	exec = gpk_dbus_get_exec_for_sender (dbus, sender);
	if (exec != NULL)
		gpk_dbus_task_set_exec (task, exec);

	/* unref on delete */
	//g_signal_connect...

	/* reset time */
	g_timer_reset (dbus->priv->timer);
	dbus->priv->refcount++;

	g_free (sender);
	g_free (exec);
	return task;
}
Esempio n. 11
0
static void
on_begin_loading(GitgRunner *loader, GitgWindow *window)
{
	GdkCursor *cursor = gdk_cursor_new(GDK_WATCH);
	gdk_window_set_cursor(GTK_WIDGET(window->priv->tree_view)->window, cursor);
	gdk_cursor_unref(cursor);

	gtk_statusbar_push(window->priv->statusbar, 0, _("Begin loading repository"));
	
	g_timer_reset(window->priv->load_timer);
	g_timer_start(window->priv->load_timer);
}
Esempio n. 12
0
/**
 * gpk_dbus_task_finished_cb:
 **/
static void
gpk_dbus_task_finished_cb (GpkDbusTask *task, GpkDbus *dbus)
{
	/* one context has returned */
	if (dbus->priv->refcount > 0)
		dbus->priv->refcount--;

	/* reset time */
	g_timer_reset (dbus->priv->timer);

	g_object_unref (task);
}
Esempio n. 13
0
static void alarm_stop(void)
{
    timer_on = FALSE;
    g_timer_stop (timer);
    g_timer_reset (timer);
    if(timeout > 0) g_source_remove(timeout);
    timeout = 0;

    if(si_alarm)
        gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(si_alarm)), FALSE);
    if (prefs_active)
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_alarm), FALSE);
}
Esempio n. 14
0
static gboolean endless(gpointer argument) {
    float resnum = 0;
    FILE *file;
    char line[1000];
    int i;
    int count;
    int rand;
    char *pline;

    pline = line;

    file = fopen("list.txt", "r");

    for(; fgets(line, 1000, file) != NULL; ++count)
        ;

    while(resnum != 1) {
        free(current_sample_array);
        int rand = g_random_int_range(0, count);
        rewind(file);
        pline = line;
        for(i = 0; i < rand; ++i)
            fgets(line, 1000, file);

        for(; *pline != '\n'; ++pline)
            ;
        *pline = '\0';
        resnum = analyze(line);
    }

    char artist[strlen(current_song.artist) + 9];
    char title[strlen(current_song.title) + 8];
    char album[strlen(current_song.album) + 8];
    strcpy(artist, "Artist: ");
    strcpy(title, "Title: ");
    strcpy(album, "Album: ");

    gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->label), "");
    gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->artist_label), strcat(artist, current_song.artist));
    gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->title_label), strcat(title, current_song.title));
    gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->album_label), strcat(album, current_song.album));

    g_timer_reset(((struct arguments*)argument)->elapsed);
    ((struct arguments*)argument)->offset = 0;
    gtk_adjustment_configure(((struct arguments*)argument)->adjust, 0, 0, current_song.duration, 1, 1, 1);
    gtk_adjustment_changed(((struct arguments*)argument)->adjust);

    if(--((struct arguments*)argument)->continue_count != 0) {
        play(NULL, argument);
    }
}
Esempio n. 15
0
static gboolean
paint_cb (void *user_data)
{
    Data *data = user_data;
    double elapsed = g_timer_elapsed (data->timer, NULL);
    double dt = elapsed - data->last_elapsed;
    GError *error = NULL;

    /* Draw scene with GLES2 */
    if (!cogl_push_gles2_context (data->ctx,
                                  data->gles2_ctx,
                                  data->fb,
                                  data->fb,
                                  &error))
    {
        g_error ("Failed to push gles2 context: %s\n", error->message);
    }

    gears_draw ();

    cogl_pop_gles2_context (data->ctx);

    cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));

    /* advance rotation for next frame */
    angle += 70.0 * dt;  /* 70 degrees per second */
    if (angle > 3600.0)
        angle -= 3600.0;

    data->frames++;

    if (elapsed > 5.0) {
        GLfloat fps = data->frames / elapsed;
        printf ("%d frames in %3.1f seconds = %6.3f FPS\n",
                data->frames, elapsed, fps);
        g_timer_reset (data->timer);
        data->last_elapsed = 0;
        data->frames = 0;
    }else
      data->last_elapsed = elapsed;

    /* If the driver can deliver swap complete events then we can remove
     * the idle paint callback until we next get a swap complete event
     * otherwise we keep the idle paint callback installed and simply
     * paint as fast as the driver will allow... */
    if (cogl_has_feature (data->ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT))
      return FALSE; /* remove the callback */
    else
      return TRUE;
}
Esempio n. 16
0
static void
test_run (gchar        *title,
	  GtkTreeModel *store,
	  ClearFunc    *clear,
	  InsertFunc   *insert)
{
  gint i, k, d, items;
  GTimer *timer;
  gdouble elapsed;
  int memused;
#ifdef HAVE_MALLINFO
  int uordblks_before = 0;
#endif

  g_print ("%s (average over %d runs, time in milliseconds)\n"
	   "items \ttime      \ttime/item \tused memory\n", title, repeats);

  timer = g_timer_new ();

  for (k = 0; k < max_size; k++)
    {
      items = 1 << k;
      elapsed = 0.0;
      for (d = 0; d < repeats; d++)
	{
	  (*clear)(store);
#ifdef HAVE_MALLINFO
	  /* Peculiar location of this, btw.  -- MW.  */
	  uordblks_before = mallinfo().uordblks;
#endif
	  g_timer_reset (timer);
	  g_timer_start (timer);
	  for (i = 0; i < items; i++)
	    (*insert) (store, items, i);
	  g_timer_stop (timer);
	  elapsed += g_timer_elapsed (timer, NULL);
	}
      
      elapsed = elapsed * 1000 / repeats;
#ifdef HAVE_MALLINFO
      memused = (mallinfo().uordblks - uordblks_before) / 1024;
#else
      memused = 0;
#endif
      g_print ("%d \t%f \t%f  \t%dk\n", 
	       items, elapsed, elapsed/items, memused);
    }  
}
Esempio n. 17
0
void alarm_init (void)
{
    debug_printf (DEBUG_INFO, "* Alarm plugin initialized");

	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

    timer = g_timer_new ();

    /* Timer starts on creation, stop it! */
    timer_on = FALSE;
    g_timer_stop (timer);
    g_timer_reset (timer);

    gtk_init_add((GtkFunction)alarm_init_delayed, NULL);
}
Esempio n. 18
0
/**
 * pk_time_reset:
 **/
gboolean
pk_time_reset (PkTime *pktime)
{
	g_return_val_if_fail (PK_IS_TIME (pktime), FALSE);

	pktime->priv->time_offset = 0;
	pktime->priv->last_percentage = 0;
	pktime->priv->average_min = PK_TIME_AVERAGE_DEFAULT_MIN;
	pktime->priv->average_max = PK_TIME_AVERAGE_DEFAULT_MAX;
	pktime->priv->value_min = PK_TIME_VALUE_DEFAULT_MIN;
	pktime->priv->value_max = PK_TIME_VALUE_DEFAULT_MAX;
	g_timer_reset (pktime->priv->timer);
	pk_time_free_data (pktime);

	return TRUE;
}
Esempio n. 19
0
void test6()
{
    sc_uint32 i, j;
    sc_addr addr;
    sc_stream *stream = 0;
    sc_addr *results = 0;
    sc_uint32 results_count = 0;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    //g_snprintf(test, 1024, "../CMakeLists.txt");
    g_timer_reset(timer);
    g_timer_start(timer);

    for (i = 0; i < link_append_count; i++)
    {
        //addr = sc_storage_link_new();
        printf("Find addrs for content %d\t", i);

        stream = sc_stream_memory_new((char*)&i, sizeof(i), SC_STREAM_READ, SC_FALSE);

        if (sc_storage_find_links_with_content(stream, &results, &results_count) == SC_RESULT_OK)
        {
            printf("founded: \n");
            for (j = 0; j < results_count; j++)
                printf("seg=%d, offset=%d\n", results[j].seg, results[j].offset);
            g_free(results);
            results = 0;
        }else
            printf("error\n");

        sc_stream_free(stream);
    }

    g_timer_stop(timer);

    printf("Created links: %d\n", link_append_count);
    printf("Links per second: %f\n", link_append_count / g_timer_elapsed(timer, 0));

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
Esempio n. 20
0
void test2()
{
    sc_uint passed = 0;
    sc_uint idx = 0;
    sc_uint32 packed;
    sc_uint32 test_count = 10000000;
    sc_addr addr, addr2;

    printf("Test sc-addr packing\n");
    passed = 0;

    timer = g_timer_new();

    g_timer_reset(timer);
    g_timer_start(timer);

    for (idx = 0; idx < test_count; idx++)
    {
        // make random addr
        addr.seg = g_random_int() % SC_ADDR_SEG_MAX;
        addr.offset = g_random_int() % SC_ADDR_OFFSET_MAX;

        // pack
        packed = SC_ADDR_LOCAL_TO_INT(addr);

        // unpack
        addr2.seg = SC_ADDR_LOCAL_SEG_FROM_INT(packed);
        addr2.offset = SC_ADDR_LOCAL_OFFSET_FROM_INT(packed);

        if (SC_ADDR_IS_NOT_EQUAL(addr, addr2))
        {
            printf("Error!\n");
            printf("Source seg=%d, offset=%d\n", addr.seg, addr.offset);
            printf("Packed=%d\n", packed);
            printf("Unpacked seg=%d, offset=%d", addr2.seg, addr2.offset);
        }else
            passed++;
    }

    g_timer_stop(timer);

    printf("Passed %d of %d tests\n", passed, idx);
    printf("Pack/Unpack operations per second: %f", test_count / g_timer_elapsed(timer, 0));

    g_timer_destroy(timer);
}
Esempio n. 21
0
void 
processAndPrintTimeStamp(cairo_t *cr, gdouble plotWidth, gdouble plotHeight, PlotSample *ps) {
  if(NULL == cr) return;
 
  static char textPosition = 0;
  gchar pointText[10];
  cairo_text_extents_t textAnalysisResult;

  if(NULL == ps->tmrBetSamples) {
    /* this is the very first important event so start the timer */
    ps->tmrBetSamples = g_timer_new();
  } else {
    /* obtain and format the time since last event ocured */
    ps->elapsedSinceLastSample = g_timer_elapsed(ps->tmrBetSamples, NULL);
    g_timer_reset(ps->tmrBetSamples);

    /* print the formated time periods between pulses */
    if(ps->elapsedSinceLastSample >= PLOT_TIMESTAMP_MIN_VAL) g_sprintf(pointText, "%.3fs", ps->elapsedSinceLastSample);
    else g_sprintf(pointText, "%dms", (unsigned int)(ps->elapsedSinceLastSample * 1000));

    /* calculate the printed text dimensions and the target coordinates.
       Don't wory to much for these magical numbers since they were empirical determined for visual styling. */  
    cairo_text_extents(cr, pointText, &textAnalysisResult);
    if(ps->plotCoords.x + textAnalysisResult.width <= plotWidth) {
      if(textPosition == 0) {
        cairo_move_to(cr, ps->plotCoords.x + IMPORTANT_PLOT_PIXEL_DIM / 1.8, ps->plotCoords.y - IMPORTANT_PLOT_PIXEL_DIM / 3.0);
      } else {
        cairo_move_to(cr, ps->plotCoords.x + IMPORTANT_PLOT_PIXEL_DIM / 1.4, ps->plotCoords.y + IMPORTANT_PLOT_PIXEL_DIM * 2.3);
      }
    } else {
      if(textPosition == 0) {
        cairo_move_to(cr, ps->plotCoords.x - IMPORTANT_PLOT_PIXEL_DIM / 1.8 - textAnalysisResult.width, ps->plotCoords.y - IMPORTANT_PLOT_PIXEL_DIM / 3.0);
      } else {
        cairo_move_to(cr, ps->plotCoords.x - IMPORTANT_PLOT_PIXEL_DIM / 1.4 - textAnalysisResult.width, ps->plotCoords.y - IMPORTANT_PLOT_PIXEL_DIM * 2.3);
      }
    }

    /* switch text position for next time stamp printing */  
    textPosition = (textPosition + 1) % 2;   

    /* stamp the result on the plot */
    cairo_set_source_rgb(cr, ps->plotColor.r, ps->plotColor.g, ps->plotColor.b);
    cairo_set_font_size(cr, 9.0);
    cairo_show_text(cr, pointText);
  }
}
Esempio n. 22
0
/**
 * gpm_backlight_notify_system_idle_changed:
 **/
static gboolean
gpm_backlight_notify_system_idle_changed (GpmBacklight *backlight, gboolean is_idle)
{
	gdouble elapsed;

	/* no point continuing */
	if (backlight->priv->system_is_idle == is_idle) {
		egg_debug ("state not changed");
		return FALSE;
	}

	/* get elapsed time and reset timer */
	elapsed = g_timer_elapsed (backlight->priv->idle_timer, NULL);
	g_timer_reset (backlight->priv->idle_timer);

	if (is_idle == FALSE) {
		egg_debug ("we have just been idle for %lfs", elapsed);

		/* The user immediatly undimmed the screen!
		 * We should double the timeout to avoid this happening again */
		if (elapsed < 10) {
			/* double the event time */
			backlight->priv->idle_dim_timeout *= 2.0;
			egg_debug ("increasing idle dim time to %is", backlight->priv->idle_dim_timeout);
			gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
		}

		/* We reset the dimming after 2 minutes of idle,
		 * as the user will have changed tasks */
		if (elapsed > 2*60) {
			/* reset back to our default dimming */
			backlight->priv->idle_dim_timeout =
				gconf_client_get_int (backlight->priv->conf,
					   GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL);
			egg_debug ("resetting idle dim time to %is", backlight->priv->idle_dim_timeout);
			gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
		}
	} else {
		egg_debug ("we were active for %lfs", elapsed);
	}

	egg_debug ("changing powersave idle status to %i", is_idle);
	backlight->priv->system_is_idle = is_idle;
	return TRUE;
}
Esempio n. 23
0
File: iimage.c Progetto: DINKIN/nip2
static gboolean
iimage_graphic_save( Classmodel *classmodel, 
	GtkWidget *parent, const char *filename )
{
	iImage *iimage = IIMAGE( classmodel );
	ImageValue *value = &iimage->value;
	char buf[FILENAME_MAX];

	/* Can't happen nested-ly, so a static is OK. 
	 */
	static GTimer *timer = NULL;

	/* We don't want $VAR etc. in the filename we pass down to the file
	 * ops.
	 */
	im_strncpy( buf, filename, FILENAME_MAX );
	path_expand( buf );

	/* Append the mode string. This needs an expanded filename.
	 */
	filesel_add_mode( buf );

	if( !timer )
		timer = g_timer_new();
	g_timer_reset( timer );

	if( value->ii )
		if( !imageinfo_write( value->ii, buf ) )
			return( FALSE );

	mainw_recent_add( &mainw_recent_image, filename );

	if( main_option_time_save ) {
		double elapsed;

		elapsed = g_timer_elapsed( timer, NULL );
		error_top( _( "Save timer." ) );
		error_sub( _( "Image save took %g seconds." ), elapsed );

		return( FALSE );
	}

	return( TRUE );
}
Esempio n. 24
0
void game_init()
{
  int i;

  if (!gtimer)
    gtimer = g_timer_new();
  g_timer_reset(gtimer);

  game_time = g_timer_elapsed(gtimer, NULL);
  game_tick  = 1.0 / 60;

  wave_cnt = 0;
  wave_time = game_time + 5; /* give 5 secs before start of waves */
  vortex_time = game_time + 3; /* give 3 secs before 1st vortex */


  control_speed = 0;
  control_spin  = 0;
  control_fire  = 0;

  score = 0;

  player.state = 1;
  player.timer = game_time;
  player.pos_x = 0;
  player.pos_y = 0;
  player.vel_x = 0;
  player.vel_y = 0;
  player.dir   = 0;
  player.radius= 5;


  for (i=0; i<sizeof(enemy)/sizeof(Entity); i++)
    enemy[i].state = 0;

  for (i=0; i<sizeof(vortex)/sizeof(Entity); i++)
    vortex[i].state = 0;

  for (i=0; i<sizeof(p_bullet)/sizeof(Entity); i++)
    p_bullet[i].state = 0;

  for (i=0; i<sizeof(e_bullet)/sizeof(Entity); i++)
    e_bullet[i].state = 0;
}
Esempio n. 25
0
/**
 * pk_backend_job_set_role:
 **/
void
pk_backend_job_set_role (PkBackendJob *job, PkRoleEnum role)
{
	/* Should only be called once... */
	if (job->priv->role != PK_ROLE_ENUM_UNKNOWN &&
	    job->priv->role != role) {
		g_warning ("cannot set role to %s, already %s",
			   pk_role_enum_to_string (role),
			   pk_role_enum_to_string (job->priv->role));
	}

	g_timer_reset (job->priv->timer);
	job->priv->role = role;
	job->priv->status = PK_STATUS_ENUM_WAIT;
	pk_backend_job_call_vfunc (job,
				   PK_BACKEND_SIGNAL_STATUS_CHANGED,
				   GUINT_TO_POINTER (job->priv->status),
				   NULL);
}
Esempio n. 26
0
static gboolean
paint_cb (void *user_data)
{
    Data *data = user_data;
    double elapsed = g_timer_elapsed (data->timer, NULL);
    double dt = elapsed - data->last_elapsed;
    CoglError *error = NULL;

    /* Draw scene with GLES2 */
    if (!cogl_push_gles2_context (data->ctx,
                                  data->gles2_ctx,
                                  data->fb,
                                  data->fb,
                                  &error))
    {
        g_error ("Failed to push gles2 context: %s\n", error->message);
    }

    gears_draw ();

    cogl_pop_gles2_context (data->ctx);

    cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));

    /* advance rotation for next frame */
    angle += 70.0 * dt;  /* 70 degrees per second */
    if (angle > 3600.0)
        angle -= 3600.0;

    data->frames++;

    if (elapsed > 5.0) {
        GLfloat fps = data->frames / elapsed;
        printf ("%d frames in %3.1f seconds = %6.3f FPS\n",
                data->frames, elapsed, fps);
        g_timer_reset (data->timer);
        data->last_elapsed = 0;
        data->frames = 0;
    }else
      data->last_elapsed = elapsed;

    return FALSE; /* remove the callback */
}
Esempio n. 27
0
void test7()
{
    sc_uint32 i, j;
    sc_addr addr, addr1, addr2;
    sc_addr new_addr;
    sc_event *event1, *event2, *event3, *event4;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    g_timer_reset(timer);
    g_timer_start(timer);

    addr = sc_storage_node_new(0);
    addr1 = sc_storage_node_new(0);
    printf("Register events\n");
    event1 = sc_event_new(addr, SC_EVENT_ADD_OUTPUT_ARC, 0, &event_callback, 0);
    event2 = sc_event_new(addr1, SC_EVENT_ADD_INPUT_ARC, 1, &event_callback, 0);
    event3 = sc_event_new(addr, SC_EVENT_REMOVE_OUTPUT_ARC, 2, &event_callback, 0);
    event4 = sc_event_new(addr1, SC_EVENT_REMOVE_INPUT_ARC, 3, &event_callback, 0);

    addr2 = sc_storage_arc_new(0, addr, addr1);
    sc_storage_element_free(addr2);

    printf("Unregister events\n");
    sc_event_destroy(event1);
    sc_event_destroy(event2);
    sc_event_destroy(event3);
    sc_event_destroy(event4);

    addr2 = sc_storage_arc_new(0, addr, addr1);
    sc_storage_element_free(addr2);

    g_timer_stop(timer);

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
Esempio n. 28
0
gboolean session_ping(gpointer data){
Session *s;

	debug("Ping...");
	g_assert(data!=NULL);
	s=(Session *)data;
	if (s->waiting_for_pong){
		gg_ping(s->ggs); /* send ping, even if server doesn't respond
				    this one will be not counted for the ping delay*/
		return TRUE;
	}

	if (!s->ping_timer) s->ping_timer=g_timer_new();
	else g_timer_reset(s->ping_timer);
	g_timer_start(s->ping_timer);
	gg_ping(s->ggs);
	s->waiting_for_pong=TRUE;
	if (s->timeout_func) g_source_remove(s->timeout_func);
	s->timeout_func=g_timeout_add(pong_timeout*1000,session_timeout,s);
	return TRUE;
}
Esempio n. 29
0
MpdData * magnatune_db_get_artist_list(char *wanted_genre)
{
    MpdData *list = NULL;
    int r;
    /** check if there is data */
    char *query = sqlite3_mprintf("SELECT albumname from 'genres' WHERE genre=%Q", wanted_genre);
    sqlite3_stmt *stmt = NULL;
    const char *tail;
    GTimer *timer = g_timer_new();
    r = sqlite3_prepare_v2(magnatune_sqlhandle, query, -1,  &stmt,  &tail);
    if(r ==SQLITE_OK) {
        while((r = sqlite3_step(stmt)) == SQLITE_ROW)
        {
            sqlite3_stmt *stmt2 = NULL;
            const char *tail2;
            char *query2 = sqlite3_mprintf("SELECT artist from 'albums' WHERE albumname=%Q", sqlite3_column_text(stmt,0));
            int r2 = sqlite3_prepare_v2(magnatune_sqlhandle, query2, -1,  &stmt2,  &tail2);
            if(r2 ==SQLITE_OK) {
                while((r2 = sqlite3_step(stmt2)) == SQLITE_ROW)
                {
                    list = mpd_new_data_struct_append(list);
                    list->type = MPD_DATA_TYPE_TAG;
                    list->tag_type = MPD_TAG_ITEM_ARTIST;
                    list->tag = g_strdup(sqlite3_column_text(stmt2,0));
                }
            }
            sqlite3_finalize(stmt2);
            sqlite3_free(query2);
        }
    }
    sqlite3_finalize(stmt);
    sqlite3_free(query);
    g_debug("%f s elapsed getting genres\n", g_timer_elapsed(timer,NULL));
    g_timer_reset(timer);
    list = misc_mpddata_remove_duplicate_songs(list);

    g_debug("%f s elapsed unique artist list\n", g_timer_elapsed(timer,NULL));
    g_timer_destroy(timer);
    return list;
}
Esempio n. 30
0
BP_EXPORT void
bp_scene_draw (scene_t * scene)
{
	unsigned int i;
	GTimer *timer;

	timer = g_timer_new ();
	g_timer_reset (timer);
	g_timer_start (timer);

#if 0
	ADD (background, scene->settings.atmosphere.background,
	     scene->settings.atmosphere.ambient_light);
#else
	ASSIGN (background, scene->settings.atmosphere.background);
#endif

	for (i = 0; i < scene->settings.num_threads; i++) {
 		int rc = pthread_create (&threads [i], &thread_attr, draw_scanlines, &thread_args [i]);
		if (rc) {
			printf("ERROR; thread %d return code from pthread_create() is %d\n",
			       i + 1,rc);
			exit(-1);
		}
	}

	for (i = 0; i < scene->settings.num_threads; i++) {
		int rc = pthread_join(threads[i], NULL);
		if (rc) {
			printf("ERROR; return code from pthread_join() is %d\n", rc);
			exit(-1);
		}
	}
	
	g_timer_stop (timer);
	gulong microseconds; /* not really usefully but needed by the timing code */
	printf ("Drawing took %f.\n", g_timer_elapsed (timer, &microseconds));
}