4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
33 #include "cachemodel_manager.h"
34 #include "faixbox_manager.h"
37 #include "fcgi_stdio.h"
38 #define logstream FCGI_stdout
40 #define FCGI_stdout stdout
41 #define FCGI_stderr stderr
42 #define logstream stderr
46 cachemodellist_param_t * gene_cachemodellist()
48 cachemodellist_param_t *cachemodellist;
50 cachemodellist = (cachemodellist_param_t *)malloc( sizeof(cachemodellist_param_t));
52 cachemodellist->first = NULL;
53 cachemodellist->last = NULL;
55 return cachemodellist;
58 cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target, bool reqJPP)
60 cachemodel_param_t *cachemodel;
61 faixbox_param_t *tilepart;
62 faixbox_param_t *precpacket;
67 cachemodel = (cachemodel_param_t *)malloc( sizeof(cachemodel_param_t));
69 refer_target( target, &cachemodel->target);
72 if( target->jppstream)
73 cachemodel->jppstream = true;
75 cachemodel->jppstream = false;
77 if( target->jptstream)
78 cachemodel->jppstream = false;
80 cachemodel->jppstream = true;
83 cachemodel->mhead_model = false;
85 tilepart = target->codeidx->tilepart;
86 numOftiles = get_m( tilepart);
87 numOfelem = get_nmax( tilepart)*numOftiles;
88 cachemodel->tp_model = (bool *)calloc( 1, numOfelem*sizeof(bool));
89 cachemodel->th_model = (bool *)calloc( 1, numOftiles*sizeof(bool));
90 cachemodel->pp_model = (bool **)malloc( target->codeidx->SIZ.Csiz*sizeof(bool *));
91 for( i=0; i<target->codeidx->SIZ.Csiz; i++){
92 precpacket = target->codeidx->precpacket[i];
93 cachemodel->pp_model[i] = (bool *)calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(bool));
95 cachemodel->next = NULL;
98 if( cachemodellist->first) // there are one or more entries
99 cachemodellist->last->next = cachemodel;
101 cachemodellist->first = cachemodel;
102 cachemodellist->last = cachemodel;
106 fprintf( logstream, "local log: cachemodel generated\n");
112 void print_cachemodel( cachemodel_param_t cachemodel)
114 target_param_t *target;
115 Byte8_t TPnum; // num of tile parts in each tile
116 Byte8_t Pmax; // max num of packets per tile
119 target = cachemodel.target;
121 fprintf( logstream, "target: %s\n", target->targetname);
122 fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
124 fprintf( logstream, "\t tile part model:\n");
125 TPnum = get_nmax( target->codeidx->tilepart);
127 for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++){
128 for( j=0; j<target->codeidx->SIZ.XTnum; j++){
129 for( k=0; k<TPnum; k++)
130 fprintf( logstream, "%d", cachemodel.tp_model[n++]);
131 fprintf( logstream, " ");
133 fprintf( logstream, "\n");
136 fprintf( logstream, "\t tile header and precinct packet model:\n");
137 for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
138 fprintf( logstream, "\t tile.%d %d\n", i, cachemodel.th_model[i]);
139 for( j=0; j<target->codeidx->SIZ.Csiz; j++){
140 fprintf( logstream, "\t compo.%d: ", j);
141 Pmax = get_nmax( target->codeidx->precpacket[j]);
142 for( k=0; k<Pmax; k++)
143 fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
144 fprintf( logstream, "\n");
149 cachemodel_param_t * search_cachemodel( target_param_t *target, cachemodellist_param_t *cachemodellist)
151 cachemodel_param_t *foundcachemodel;
153 foundcachemodel = cachemodellist->first;
155 while( foundcachemodel != NULL){
157 if( foundcachemodel->target == target)
158 return foundcachemodel;
160 foundcachemodel = foundcachemodel->next;
165 void delete_cachemodellist( cachemodellist_param_t **cachemodellist)
167 cachemodel_param_t *cachemodelPtr, *cachemodelNext;
169 cachemodelPtr = (*cachemodellist)->first;
170 while( cachemodelPtr != NULL){
171 cachemodelNext=cachemodelPtr->next;
172 delete_cachemodel( &cachemodelPtr);
173 cachemodelPtr=cachemodelNext;
175 free(*cachemodellist);
178 void delete_cachemodel( cachemodel_param_t **cachemodel)
182 unrefer_target( (*cachemodel)->target);
184 free( (*cachemodel)->tp_model);
185 free( (*cachemodel)->th_model);
187 for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
188 free( (*cachemodel)->pp_model[i]);
189 free( (*cachemodel)->pp_model);
192 fprintf( logstream, "local log: cachemodel deleted\n");
197 bool is_allsent( cachemodel_param_t cachemodel)
199 target_param_t *target;
200 Byte8_t TPnum; // num of tile parts in each tile
201 Byte8_t Pmax; // max num of packets per tile
204 target = cachemodel.target;
206 if( !cachemodel.mhead_model)
209 TPnum = get_nmax( target->codeidx->tilepart);
211 if( cachemodel.jppstream){
212 for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
213 if( !cachemodel.th_model[i])
216 for( j=0; j<target->codeidx->SIZ.Csiz; j++){
217 Pmax = get_nmax( target->codeidx->precpacket[j]);
218 for( k=0; k<Pmax; k++)
219 if( !cachemodel.pp_model[j][i*Pmax+k])
226 for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++)
227 for( j=0; j<target->codeidx->SIZ.XTnum; j++)
228 for( k=0; k<TPnum; k++)
229 if( !cachemodel.tp_model[n++])