Back to index

gcompris  8.2.2
Defines | Functions | Variables
log.c File Reference
#include <unistd.h>
#include <glib/gstdio.h>
#include <time.h>
#include <string.h>
#include <gcompris.h>
#include "profile.h"

Go to the source code of this file.

Defines

#define KEYLOG_MAX   256
#define USE_UTC   0

Functions

void gc_log_start (GcomprisBoard *gcomprisBoard)
 gc_log_start
void gc_log_set_comment (GcomprisBoard *gcomprisBoard, gchar *expected, gchar *got)
 gc_log_set_comment
void gc_log_set_key (GcomprisBoard *gcomprisBoard, guint keyval)
 gc_log_key
void gc_log_end (GcomprisBoard *gcomprisBoard, gchar *status)
 gc_log_end

Variables

static gchar hostname [256]
static gchar * comment_set
static gchar keylog [KEYLOG_MAX]
static GcomprisBoard * gcomprisBoard_set
static time_t start_time
static time_t start_time_key

Define Documentation

#define KEYLOG_MAX   256

Definition at line 42 of file log.c.

#define USE_UTC   0

Definition at line 57 of file log.c.


Function Documentation

void gc_log_end ( GcomprisBoard *  gcomprisBoard,
gchar *  status 
)

gc_log_end

Parameters:
GcomprisBoard*gcomprisBoard: the board for which the event happen
status,:a string representing the status like PASSED, FAILED.

Definition at line 147 of file log.c.

                                                              {
  FILE *flog;
  gchar *file;

  /* Prepare our log */

  /* The default format for time represenation.  See strftime(3) */
  char *fmt = "%F %T";

  char buf[256];

  /* get the current time from the Unix kernel */
  time_t end_time = time(NULL);
  double duration = difftime(end_time,start_time);

  struct tm *tp;

  GcomprisUser *gcomprisUser = gc_profile_get_current_user();
  const char *username = g_get_user_name();

  if(gcomprisBoard_set != gcomprisBoard)
    return;

  if(gcomprisUser && gcomprisUser->login)
    username = gcomprisUser->login;

  /* and convert it to UTC or local time representation */
  if (USE_UTC)
    tp = gmtime(&start_time);
  else
    tp = localtime(&start_time);

  /* convert the time to a string according to the format specification in fmt */
  strftime(buf, sizeof(buf), fmt, tp);

  /* Print it out */
  if(g_get_home_dir()) {
    file = g_strconcat(g_get_home_dir(), "/.gcompris/gcompris.log", NULL);
  } else {
    /* On WIN98, No home dir */
    file = g_strdup("gcompris.log");
  }

  flog = g_fopen(file,"a");

  /* date,computer,user,board,level,sublevel,status, duration,comment */
  if(flog)
    fprintf(flog, "%s;%s;%s;gcompris;%s;%d;%d;%s;%d;%s;%s\n", buf, hostname, username,
           gcomprisBoard->name,
           gcomprisBoard->level, gcomprisBoard->sublevel,
           status,
           (guint)duration,
           comment_set,
           keylog);
  else
    g_warning("Failed to save the log in file '%s'", file);

  g_warning("%s;%s;%s;gcompris;%s;%d;%d;%s;%d;%s;%s\n", buf, hostname, username,
           gcomprisBoard->name,
           gcomprisBoard->level, gcomprisBoard->sublevel,
           status,
           (guint)duration,
           comment_set,
           keylog);

  if(flog)
    fclose(flog);

  g_free(file);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_log_set_comment ( GcomprisBoard *  gcomprisBoard,
gchar *  expected,
gchar *  got 
)

gc_log_set_comment

Parameters:
GcomprisBoard*gcomprisBoard: the board for which the event happen
expected,:string describing what was expected. This string is copied.
got,:string describing what we got from the user. This string is copied.

Note: Do not include the charater ';' in expected or got

Definition at line 85 of file log.c.

                                                                                    {

  printf("gc_log_set_comment %s %s\n", expected, got);
  if(gcomprisBoard_set != gcomprisBoard) {
    return;
  }

  if(expected==NULL)
    expected="";

  if(got==NULL)
    got="";

  /* If We already had a comment, log the previous one */
  if(comment_set[0] != '\0') {
    gc_log_end(gcomprisBoard, GCOMPRIS_LOG_STATUS_FAILED);
  }

  comment_set = g_strdup_printf("%s;%s", expected, got);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_log_set_key ( GcomprisBoard *  gcomprisBoard,
guint  keyval 
)

gc_log_key

Parameters:
GcomprisBoard*gcomprisBoard: the board for which the event happen
key,:a keyval as defined by gtk

Definition at line 111 of file log.c.

                                                                 {
  char utf8char[6];
  int i;
  /* get the current time from the Unix kernel */
  time_t end_time = time(NULL);
  double duration = difftime(end_time,start_time_key);

  if(!g_unichar_isalnum (gdk_keyval_to_unicode (keyval)))
    return;

  /* Reset the timer */
  start_time_key = end_time;

  /* Should be an easier way to get the UTF-8 code in our string */
  for(i=0; i<6; i++)
    utf8char[i] = '\0';

  sprintf(utf8char, "%c", gdk_keyval_to_unicode(keyval));

  g_unichar_to_utf8 (gdk_keyval_to_unicode(keyval),
                   utf8char);

  if(strlen(keylog)<(KEYLOG_MAX-10)) {
    strcat(keylog, utf8char);
    printf(" 1 gc_log_set_key %s\n", keylog);
    sprintf(keylog+strlen(keylog), "/%d:", (guint)duration);
    printf(" 2 gc_log_set_key %s\n", keylog);
  }

}
void gc_log_start ( GcomprisBoard *  gcomprisBoard)

gc_log_start

log

Parameters:
GcomprisBoard*gcomprisBoard: the board for which the event happen

Definition at line 63 of file log.c.

                                                 {

  gcomprisBoard_set = gcomprisBoard;
  start_time     = time(NULL);
  start_time_key = time(NULL);

#ifndef WIN32
  gethostname(hostname, 256);
#endif

  comment_set = "";
  keylog[0]   = '\0';
}

Here is the caller graph for this function:


Variable Documentation

gchar* comment_set [static]

Definition at line 50 of file log.c.

GcomprisBoard* gcomprisBoard_set [static]

Definition at line 52 of file log.c.

gchar hostname[256] [static]

Definition at line 47 of file log.c.

gchar keylog[KEYLOG_MAX] [static]

Definition at line 51 of file log.c.

time_t start_time [static]

Definition at line 53 of file log.c.

time_t start_time_key [static]

Definition at line 54 of file log.c.