2011-08-27 14:53:38 +02:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
|
|
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
|
|
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "cachemodel_manager.h"
|
|
|
|
#include "faixbox_manager.h"
|
|
|
|
|
|
|
|
#ifdef SERVER
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#define logstream FCGI_stdout
|
|
|
|
#else
|
|
|
|
#define FCGI_stdout stdout
|
|
|
|
#define FCGI_stderr stderr
|
|
|
|
#define logstream stderr
|
2012-03-02 09:44:04 +01:00
|
|
|
#endif /*SERVER*/
|
2011-08-27 14:53:38 +02:00
|
|
|
|
|
|
|
|
2012-03-02 09:44:04 +01:00
|
|
|
cachemodellist_param_t * gene_cachemodellist(void)
|
2011-08-27 14:53:38 +02:00
|
|
|
{
|
|
|
|
cachemodellist_param_t *cachemodellist;
|
|
|
|
|
|
|
|
cachemodellist = (cachemodellist_param_t *)malloc( sizeof(cachemodellist_param_t));
|
|
|
|
|
|
|
|
cachemodellist->first = NULL;
|
|
|
|
cachemodellist->last = NULL;
|
|
|
|
|
|
|
|
return cachemodellist;
|
|
|
|
}
|
|
|
|
|
2011-10-11 09:24:58 +02:00
|
|
|
cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target, bool reqJPP)
|
2011-08-27 14:53:38 +02:00
|
|
|
{
|
|
|
|
cachemodel_param_t *cachemodel;
|
|
|
|
faixbox_param_t *tilepart;
|
2011-10-10 11:50:18 +02:00
|
|
|
faixbox_param_t *precpacket;
|
2011-08-27 14:53:38 +02:00
|
|
|
size_t numOfelem;
|
2011-10-10 11:50:18 +02:00
|
|
|
Byte8_t numOftiles;
|
|
|
|
int i;
|
2011-08-27 14:53:38 +02:00
|
|
|
|
|
|
|
cachemodel = (cachemodel_param_t *)malloc( sizeof(cachemodel_param_t));
|
|
|
|
|
|
|
|
refer_target( target, &cachemodel->target);
|
2011-10-11 09:24:58 +02:00
|
|
|
|
|
|
|
if( reqJPP){
|
|
|
|
if( target->jppstream)
|
|
|
|
cachemodel->jppstream = true;
|
|
|
|
else
|
|
|
|
cachemodel->jppstream = false;
|
2012-03-02 09:44:04 +01:00
|
|
|
} else{ /* reqJPT */
|
2011-10-11 09:24:58 +02:00
|
|
|
if( target->jptstream)
|
|
|
|
cachemodel->jppstream = false;
|
|
|
|
else
|
|
|
|
cachemodel->jppstream = true;
|
|
|
|
}
|
|
|
|
|
2011-08-27 14:53:38 +02:00
|
|
|
cachemodel->mhead_model = false;
|
|
|
|
|
|
|
|
tilepart = target->codeidx->tilepart;
|
2011-10-10 11:50:18 +02:00
|
|
|
numOftiles = get_m( tilepart);
|
|
|
|
numOfelem = get_nmax( tilepart)*numOftiles;
|
2011-08-27 14:53:38 +02:00
|
|
|
cachemodel->tp_model = (bool *)calloc( 1, numOfelem*sizeof(bool));
|
2011-10-10 11:50:18 +02:00
|
|
|
cachemodel->th_model = (bool *)calloc( 1, numOftiles*sizeof(bool));
|
|
|
|
cachemodel->pp_model = (bool **)malloc( target->codeidx->SIZ.Csiz*sizeof(bool *));
|
|
|
|
for( i=0; i<target->codeidx->SIZ.Csiz; i++){
|
|
|
|
precpacket = target->codeidx->precpacket[i];
|
|
|
|
cachemodel->pp_model[i] = (bool *)calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(bool));
|
|
|
|
}
|
2011-08-27 14:53:38 +02:00
|
|
|
cachemodel->next = NULL;
|
|
|
|
|
|
|
|
if( cachemodellist){
|
2012-03-02 09:44:04 +01:00
|
|
|
if( cachemodellist->first) /* there are one or more entries */
|
2011-08-27 14:53:38 +02:00
|
|
|
cachemodellist->last->next = cachemodel;
|
2012-03-02 09:44:04 +01:00
|
|
|
else /* first entry */
|
2011-08-27 14:53:38 +02:00
|
|
|
cachemodellist->first = cachemodel;
|
|
|
|
cachemodellist->last = cachemodel;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef SERVER
|
|
|
|
fprintf( logstream, "local log: cachemodel generated\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return cachemodel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_cachemodel( cachemodel_param_t cachemodel)
|
|
|
|
{
|
2011-10-10 11:50:18 +02:00
|
|
|
target_param_t *target;
|
2012-03-02 09:44:04 +01:00
|
|
|
Byte8_t TPnum; /* num of tile parts in each tile */
|
|
|
|
Byte8_t Pmax; /* max num of packets per tile */
|
|
|
|
Byte8_t i, j, k;
|
|
|
|
int n; /* FIXME: Is this large enough ? */
|
2011-10-10 11:50:18 +02:00
|
|
|
|
|
|
|
target = cachemodel.target;
|
2011-08-27 14:53:38 +02:00
|
|
|
|
2011-11-16 17:54:53 +01:00
|
|
|
fprintf( logstream, "target: %s\n", target->targetname);
|
2011-08-27 14:53:38 +02:00
|
|
|
fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
|
|
|
|
|
|
|
|
fprintf( logstream, "\t tile part model:\n");
|
2011-10-10 11:50:18 +02:00
|
|
|
TPnum = get_nmax( target->codeidx->tilepart);
|
2011-08-27 14:53:38 +02:00
|
|
|
|
2011-10-10 11:50:18 +02:00
|
|
|
for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++){
|
|
|
|
for( j=0; j<target->codeidx->SIZ.XTnum; j++){
|
2011-08-27 14:53:38 +02:00
|
|
|
for( k=0; k<TPnum; k++)
|
|
|
|
fprintf( logstream, "%d", cachemodel.tp_model[n++]);
|
|
|
|
fprintf( logstream, " ");
|
|
|
|
}
|
|
|
|
fprintf( logstream, "\n");
|
|
|
|
}
|
2011-10-10 11:50:18 +02:00
|
|
|
|
|
|
|
fprintf( logstream, "\t tile header and precinct packet model:\n");
|
|
|
|
for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
|
2012-03-02 09:44:04 +01:00
|
|
|
fprintf( logstream, "\t tile.%llud %d\n", i, cachemodel.th_model[i]);
|
2011-10-10 11:50:18 +02:00
|
|
|
for( j=0; j<target->codeidx->SIZ.Csiz; j++){
|
2012-03-02 09:44:04 +01:00
|
|
|
fprintf( logstream, "\t compo.%llud: ", j);
|
2011-10-10 11:50:18 +02:00
|
|
|
Pmax = get_nmax( target->codeidx->precpacket[j]);
|
|
|
|
for( k=0; k<Pmax; k++)
|
|
|
|
fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
|
|
|
|
fprintf( logstream, "\n");
|
|
|
|
}
|
|
|
|
}
|
2011-08-27 14:53:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cachemodel_param_t * search_cachemodel( target_param_t *target, cachemodellist_param_t *cachemodellist)
|
|
|
|
{
|
|
|
|
cachemodel_param_t *foundcachemodel;
|
|
|
|
|
|
|
|
foundcachemodel = cachemodellist->first;
|
|
|
|
|
|
|
|
while( foundcachemodel != NULL){
|
|
|
|
|
|
|
|
if( foundcachemodel->target == target)
|
|
|
|
return foundcachemodel;
|
|
|
|
|
|
|
|
foundcachemodel = foundcachemodel->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_cachemodellist( cachemodellist_param_t **cachemodellist)
|
|
|
|
{
|
|
|
|
cachemodel_param_t *cachemodelPtr, *cachemodelNext;
|
|
|
|
|
|
|
|
cachemodelPtr = (*cachemodellist)->first;
|
|
|
|
while( cachemodelPtr != NULL){
|
|
|
|
cachemodelNext=cachemodelPtr->next;
|
|
|
|
delete_cachemodel( &cachemodelPtr);
|
|
|
|
cachemodelPtr=cachemodelNext;
|
|
|
|
}
|
|
|
|
free(*cachemodellist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_cachemodel( cachemodel_param_t **cachemodel)
|
|
|
|
{
|
2011-10-10 11:50:18 +02:00
|
|
|
int i;
|
|
|
|
|
2011-08-27 14:53:38 +02:00
|
|
|
unrefer_target( (*cachemodel)->target);
|
|
|
|
|
|
|
|
free( (*cachemodel)->tp_model);
|
2011-10-10 11:50:18 +02:00
|
|
|
free( (*cachemodel)->th_model);
|
|
|
|
|
2011-11-06 23:03:12 +01:00
|
|
|
for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
|
|
|
|
free( (*cachemodel)->pp_model[i]);
|
2011-10-10 11:50:18 +02:00
|
|
|
free( (*cachemodel)->pp_model);
|
2011-08-27 14:53:38 +02:00
|
|
|
|
|
|
|
#ifndef SERVER
|
|
|
|
fprintf( logstream, "local log: cachemodel deleted\n");
|
|
|
|
#endif
|
|
|
|
free( *cachemodel);
|
|
|
|
}
|
2011-11-30 15:54:41 +01:00
|
|
|
|
|
|
|
bool is_allsent( cachemodel_param_t cachemodel)
|
|
|
|
{
|
|
|
|
target_param_t *target;
|
2012-03-02 09:44:04 +01:00
|
|
|
Byte8_t TPnum; /* num of tile parts in each tile */
|
|
|
|
Byte8_t Pmax; /* max num of packets per tile */
|
|
|
|
Byte8_t i, j, k;
|
|
|
|
int n; /* FIXME: is this large enough ? */
|
2011-11-30 15:54:41 +01:00
|
|
|
|
|
|
|
target = cachemodel.target;
|
|
|
|
|
|
|
|
if( !cachemodel.mhead_model)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TPnum = get_nmax( target->codeidx->tilepart);
|
|
|
|
|
|
|
|
if( cachemodel.jppstream){
|
|
|
|
for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
|
|
|
|
if( !cachemodel.th_model[i])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( j=0; j<target->codeidx->SIZ.Csiz; j++){
|
|
|
|
Pmax = get_nmax( target->codeidx->precpacket[j]);
|
|
|
|
for( k=0; k<Pmax; k++)
|
|
|
|
if( !cachemodel.pp_model[j][i*Pmax+k])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++)
|
|
|
|
for( j=0; j<target->codeidx->SIZ.XTnum; j++)
|
|
|
|
for( k=0; k<TPnum; k++)
|
|
|
|
if( !cachemodel.tp_model[n++])
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|