示例#1
0
GcomprisProfile *gc_db_get_profile_from_id(gint profile_id)
{
  SUPPORT_OR_RETURN(FALSE);

#ifdef USE_SQLITE
  GcomprisProfile *profile = NULL;

  char *zErrMsg;
  char **result;
  int rc;
  int nrow;
  int ncolumn;
  gchar *request;

  int i;
  GList *ids;
  /* get section_id */
  request = g_strdup_printf(GET_PROFILE(profile_id));


  rc = sqlite3_get_table(gcompris_db,
			 request,
			 &result,
			 &nrow,
			 &ncolumn,
			 &zErrMsg
			 );

  if( rc!=SQLITE_OK ){
    g_error("SQL error: %s\n", zErrMsg);
  }

  if (nrow != 0){
    profile = g_malloc0(sizeof(GcomprisProfile));

    profile->profile_id = profile_id;


    profile->name = g_strdup(result[3]);
    profile->directory = g_strdup(result[4]);
    profile->description = g_strdup(result[5]);
    sqlite3_free_table(result);
    g_free(request);

    request = g_strdup_printf(GET_GROUPS_IN_PROFILE(profile->profile_id));

    rc = sqlite3_get_table(gcompris_db,
			   request,
			   &result,
			   &nrow,
			   &ncolumn,
			   &zErrMsg
			   );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow == 0){
      g_message("No users' groups for profile %s", profile->name);
      profile->group_ids = NULL;
    } else {
      ids = NULL;

      i = ncolumn;
      while (i < (nrow +1)*ncolumn) {
	int *group_id = g_malloc(sizeof(int));

	*group_id = atoi(result[i++]);
	ids = g_list_append(ids, group_id);
      }
      profile->group_ids = ids;
    }
    sqlite3_free_table(result);

    request = g_strdup_printf(GET_ACTIVITIES_OUT_OF_PROFILE(profile->profile_id));
    rc = sqlite3_get_table(gcompris_db,
			   request,
			   &result,
			   &nrow,
			   &ncolumn,
			   &zErrMsg
			   );

    if( rc!=SQLITE_OK ){
      g_error("SQL error: %s\n", zErrMsg);
    }

    g_free(request);

    if (nrow == 0){
      g_message("No activities for profile %s", profile->name);
      profile->activities = NULL;
    } else {
      ids = NULL;

      i = ncolumn;
      while (i < (nrow +1)*ncolumn) {
	int *board_id = g_malloc(sizeof(int));

	*board_id = atoi(result[i++]);
	ids = g_list_append(ids, board_id);
      }
      profile->activities = ids;
    }
    sqlite3_free_table(result);
  }

  return profile;
#endif
}
示例#2
0
/****************************************************************************//**
 * Video capture thread main entry point.
 * @param arg Optional thread parameter, this is unused.
 * @return Always null
 ****************************************************************************/
static void *videocapThread( void *arg )
{
    PongInstance_t* pongInstance = (PongInstance_t *) arg;

    int vIndex = -1;
    int result;

    while ( keepWorking )
    {
        // 1. Get an empty vframe buffer,
        //    only if we sucessfully sent the previous one
        if ( vIndex == -1 )
        {
            result = mq_read( pongInstance->mqVideoEmpty, &vIndex, sizeof(int), 100000 );
            if ( result!=OK )
            {
                if ( result == ERROR )
                    loge("mq_read failed - %s", strerror(errno) );

                continue;

            } /*if*/

            log("Got empty video frame index %d         ", vIndex );
            //usleep(1000000);

        }/*if*/
        #ifdef PROFILING_ON
            START_PROFILE();
        #endif
        // 2. fill vframe buffer with data from camera
        // copy data to 'pongInstance.videoFrames[vIndex]'
        getFrame((unsigned char *) &pongInstance->videoFrames[vIndex], &pongInstance->cameraInfo);

        #ifdef PROFILING_ON
            STOP_PROFILE();
            GET_PROFILE("getFrame");
        #endif

        // 3. Send vframe to the color filters threads
        result = mq_write( pongInstance->mqVideoFull, &vIndex, sizeof(int), 100000 );
        if ( result!=OK )
        {
            if ( result == ERROR )
                loge("mq_write failed - %s", strerror(errno) );

            continue;

        } /*if*/

        log("Sent full video frame index %d       ", vIndex );
        //usleep(1000000);


        vIndex = -1; //allow another receive to happen in the next iteration

    }/*while*/


    log( FG13 "  *** VideoCap exited...");
    return NULL;
}