Changeset 631 for trunk/zoo-project/zoo-kernel/service_internal_otb.c
- Timestamp:
- Apr 13, 2015, 8:17:18 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal_otb.c
r619 r631 98 98 99 99 /** 100 * Write a file from value and length101 *102 * @param fname the file name103 * @param val the value104 * @param length the value length105 */106 int writeFile(char* fname,char* val,int length){107 FILE* of=fopen(fname,"wb");108 if(of==NULL){109 return -1;110 }111 size_t ret=fwrite(val,sizeof(char),length,of);112 if(ret<length){113 fprintf(stderr,"Write error occured!\n");114 fclose(of);115 return -1;116 }117 fclose(of);118 return 1;119 }120 121 /**122 100 * Load and run an OTB Application corresponding to the service by using inputs parameters. 123 101 * Define the m_Conf … … 137 115 map* tmp=NULL; 138 116 int res=-1; 139 140 117 std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); 141 118 if (list.size() == 0){ … … 146 123 free(tmps); 147 124 res=-1; 125 return res; 148 126 } 149 127 else{ 128 dumpMapsValuesToFiles(main_conf,real_inputs); 150 129 for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){ 151 130 if(s->name==*it){ … … 212 191 setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp); 213 192 dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType); 214 }else{ 215 map* tmpPath=getMapFromMaps(m,"main","tmpPath"); 216 map* tmpSid=getMapFromMaps(m,"lenv","sid"); 217 map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),"mimeType"); 218 char file_ext[32]; 219 getFileExtension(tmpVal != NULL ? tmpVal->value : NULL, file_ext, 32); 220 if(type == ParameterType_InputImageList){ 221 char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char)); 222 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,0,file_ext); 223 int length=0; 224 map* tmpSize=getMap(test,"size"); 225 if(tmpSize!=NULL){ 226 length=atoi(tmpSize->value); 227 } 228 writeFile(val,test->value,length); 229 values.push_back(val); 230 free(val); 231 map* tmpLength=getMapFromMaps(inputs,paramKey.c_str(),"length"); 232 if(tmpLength!=NULL){ 233 int len=atoi(tmpLength->value); 234 maps* tmpI=getMaps(inputs,paramKey.c_str()); 235 for(int k=1;k<len;k++){ 236 val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+13)*sizeof(char)); 237 sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,s->name,tmpSid->value,k,file_ext); 238 length=0; 239 map* tmpV=getMapArray(tmpI->content,"value",k); 240 tmpSize=getMapArray(tmpI->content,"size",k); 241 if(tmpSize!=NULL){ 242 length=atoi(tmpSize->value); 243 } 244 writeFile(val,tmpV->value,length); 245 values.push_back(val); 246 free(val); 247 } 248 } 249 dynamic_cast<InputImageListParameter *> (param.GetPointer())->SetListFromFileName(values); 250 } 251 else 252 if(type == ParameterType_InputVectorData || type == ParameterType_InputImage 253 || type == ParameterType_ComplexInputImage || type == ParameterType_InputVectorData 254 || type == ParameterType_InputFilename){ 255 char tmp[1024]; 256 char* ext="json"; 257 if(tmpVal!=NULL){ 258 char *val=(char*)malloc((strlen(tmpPath->value)+strlen(s->name)+strlen(tmpSid->value)+strlen(file_ext)+10)*sizeof(char)); 259 sprintf(val,"%s/Input_%s_%s.%s",tmpPath->value,s->name,tmpSid->value,file_ext); 260 int length=0; 261 map* tmpSize=getMap(test,"size"); 262 if(tmpSize!=NULL){ 263 length=atoi(tmpSize->value); 264 } 265 writeFile(val,test->value,length); 266 267 if(strncasecmp(tmpVal->value,"application/zip",14)==0){ 268 269 char tmpName[1024]; 270 sprintf(tmpName,"/vsizip/%s",val); 271 char **files=VSIReadDir(tmpName); 272 int nFiles = CSLCount( files ); 273 char tmpSSName[1024]; 274 sprintf(tmpSSName,"%s/Input_%s_%s",tmpPath->value,s->name,tmpSid->value); 275 mkdir(tmpSSName,0777); 276 277 char tmpSName[1024]; 278 for(int kk=0;kk<nFiles;kk++){ 279 sprintf(tmpSName,"%s/%s",tmpName,files[kk]); 280 VSILFILE* fmain=VSIFOpenL(tmpSName, "rb"); 281 if(fmain!=NULL){ 282 VSIFSeekL(fmain,0,SEEK_END); 283 long count=VSIFTellL(fmain); 284 VSIRewindL(fmain); 285 286 char *content=(char*) malloc((count+1)*sizeof(char)); 287 VSIFReadL(content,1,count*sizeof(char),fmain); 288 289 char tmpSSSName[1024]; 290 sprintf(tmpSSSName,"%s/%s",tmpSSName,files[kk]); 291 292 FILE* fx=fopen(tmpSSSName, "wb"); 293 fwrite(content,1,count,fx); 294 fclose(fx); 295 VSIFCloseL(fmain); 296 free(content); 297 std::string test1(tmpSSSName); 298 if(test1.find(".shp")!=std::string::npos){ 299 setMapInMaps(inputs,paramKey.c_str(),"cache_file",tmpSSSName); 300 test=getMapFromMaps(inputs,paramKey.c_str(),"cache_file"); 301 } 302 } 303 } 304 m_Application->SetParameterString(paramKey, test->value); 305 }else{ 306 m_Application->SetParameterString(paramKey, val); 307 } 308 free(val); 309 } 310 } 311 else 312 if(test->value!=NULL) 313 m_Application->SetParameterString(paramKey, test->value); 314 } 315 193 } 194 else{ 195 if(test!=NULL && test->value!=NULL) 196 m_Application->SetParameterString(paramKey, test->value); 197 } 316 198 }else{ 317 199 if(type == ParameterType_OutputVectorData){
Note: See TracChangeset
for help on using the changeset viewer.