[580] | 1 | /* |
---|
[550] | 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2015 GeoLabs SARL |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
[558] | 23 | * |
---|
| 24 | * See Ref: http://hg.orfeo-toolbox.org/OTB/ Copyright |
---|
| 25 | * Some parts of this code are derived from ITK. See ITKCopyright.txt for |
---|
| 26 | * details. |
---|
[550] | 27 | */ |
---|
| 28 | |
---|
| 29 | #include "service_internal_otb.h" |
---|
| 30 | |
---|
| 31 | using namespace otb::Wrapper; |
---|
| 32 | |
---|
[580] | 33 | /** |
---|
| 34 | * The ZooWatcher list |
---|
| 35 | */ |
---|
[561] | 36 | WatcherListType m_WatcherList; |
---|
[580] | 37 | /** |
---|
| 38 | * A pointer to the conf maps containing the main.cfg settings |
---|
| 39 | */ |
---|
[561] | 40 | maps* m_Conf; |
---|
| 41 | |
---|
[580] | 42 | /** |
---|
| 43 | * The command to create a ZooWatcher and add it to the global m_WatcherList |
---|
| 44 | */ |
---|
[558] | 45 | class MyCommand : public itk::Command |
---|
| 46 | { |
---|
| 47 | public: |
---|
| 48 | itkNewMacro( MyCommand ); |
---|
| 49 | public: |
---|
| 50 | |
---|
[580] | 51 | /** |
---|
| 52 | * The method that defines the action to be taken by the command. |
---|
| 53 | * |
---|
| 54 | * @param caller an itk::Object pointer |
---|
| 55 | * @param event an itk::EventObject pointer |
---|
| 56 | */ |
---|
[558] | 57 | void Execute(itk::Object *caller, const itk::EventObject & event) |
---|
| 58 | { |
---|
| 59 | Execute( (const itk::Object *)caller, event); |
---|
| 60 | } |
---|
| 61 | |
---|
[580] | 62 | /** |
---|
| 63 | * The method that defines the action to be taken by the command. |
---|
| 64 | * Create a new ZooWatcher instance then add it to the m_WatcherList. |
---|
| 65 | * |
---|
| 66 | * @param caller a const itk::Object pointer |
---|
| 67 | * @param event an itk::EventObject pointer |
---|
| 68 | * @see ZooWatcher,ZooWatcher::SetConf |
---|
| 69 | */ |
---|
| 70 | void Execute(const itk::Object *caller, const itk::EventObject & event) |
---|
[558] | 71 | { |
---|
| 72 | const AddProcessToWatchEvent* eventToWatch = dynamic_cast< const AddProcessToWatchEvent*> ( &event ); |
---|
| 73 | std::string m_CurrentDescription = eventToWatch->GetProcessDescription(); |
---|
| 74 | ZooWatcher * watch = new ZooWatcher(eventToWatch->GetProcess(), |
---|
| 75 | eventToWatch->GetProcessDescription()); |
---|
| 76 | watch->SetConf(&m_Conf); |
---|
| 77 | m_WatcherList.push_back(watch); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | }; |
---|
| 81 | |
---|
[580] | 82 | /** |
---|
| 83 | * Replace all occurence of from by to in a str string |
---|
| 84 | * |
---|
| 85 | * @param str the string to transform |
---|
| 86 | * @param from the string to replace |
---|
| 87 | * @param to the string used as replacement |
---|
| 88 | * @return the resulting string |
---|
| 89 | */ |
---|
[550] | 90 | std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) { |
---|
| 91 | size_t start_pos = 0; |
---|
| 92 | while((start_pos = str.find(from, start_pos)) != std::string::npos) { |
---|
| 93 | str.replace(start_pos, from.length(), to); |
---|
| 94 | start_pos += to.length(); // Handles case where 'to' is a substring of 'from' |
---|
| 95 | } |
---|
| 96 | return str; |
---|
| 97 | } |
---|
| 98 | |
---|
[580] | 99 | /** |
---|
| 100 | * Load and run an OTB Application corresponding to the service by using inputs parameters. |
---|
| 101 | * Define the m_Conf |
---|
| 102 | * |
---|
| 103 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 104 | * @param request the map containing the HTTP request |
---|
| 105 | * @param s the service structure |
---|
| 106 | * @param real_inputs the maps containing the inputs |
---|
| 107 | * @param real_outputs the maps containing the outputs |
---|
| 108 | */ |
---|
[550] | 109 | int zoo_otb_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ |
---|
| 110 | maps* m=*main_conf; |
---|
| 111 | maps* inputs=*real_inputs; |
---|
| 112 | maps* outputs=*real_outputs; |
---|
[558] | 113 | map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd"); |
---|
| 114 | char *ntmp=tmp0->value; |
---|
[550] | 115 | map* tmp=NULL; |
---|
| 116 | int res=-1; |
---|
| 117 | std::vector<std::string> list = ApplicationRegistry::GetAvailableApplications(); |
---|
| 118 | if (list.size() == 0){ |
---|
| 119 | map* tmps=createMap("text","No OTB Application found."); |
---|
| 120 | addToMap(tmps,"code","InternalError"); |
---|
| 121 | printExceptionReportResponse(m,tmps); |
---|
| 122 | freeMap(&tmps); |
---|
| 123 | free(tmps); |
---|
| 124 | res=-1; |
---|
[631] | 125 | return res; |
---|
[550] | 126 | } |
---|
| 127 | else{ |
---|
[631] | 128 | dumpMapsValuesToFiles(main_conf,real_inputs); |
---|
[550] | 129 | for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it){ |
---|
| 130 | if(s->name==*it){ |
---|
| 131 | Application::Pointer m_Application=ApplicationRegistry::CreateApplication(*it); |
---|
| 132 | if (m_Application.IsNull()){ |
---|
| 133 | char tmpS[1024]; |
---|
| 134 | sprintf(tmpS, "The OTB Application %s cannot be loaded.", (*it).c_str()); |
---|
| 135 | map* tmps=createMap("text",tmpS); |
---|
| 136 | addToMap(tmps,"code","InternalError"); |
---|
| 137 | printExceptionReportResponse(m,tmps); |
---|
| 138 | freeMap(&tmps); |
---|
| 139 | free(tmps); |
---|
| 140 | res=-1; |
---|
| 141 | }else{ |
---|
[558] | 142 | // Create Observer on AddProcessToWatchEvent |
---|
| 143 | m_Conf=m; |
---|
| 144 | MyCommand::Pointer myCommand = MyCommand::New(); |
---|
| 145 | m_Application->AddObserver(AddProcessToWatchEvent(), myCommand); |
---|
[550] | 146 | char tmpS[1024]; |
---|
| 147 | const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); |
---|
| 148 | for (unsigned int i = 0; i < appKeyList.size(); i++){ |
---|
| 149 | const std::string paramKey(appKeyList[i]); |
---|
| 150 | std::vector<std::string> values; |
---|
| 151 | Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); |
---|
| 152 | ParameterType type = m_Application->GetParameterType(paramKey); |
---|
| 153 | if (type != ParameterType_Group && paramKey!="inxml" && paramKey!="outxml"){ |
---|
| 154 | map* test=getMapFromMaps(inputs,paramKey.c_str(),"cache_file"); |
---|
| 155 | if(test==NULL){ |
---|
| 156 | test=getMapFromMaps(inputs,paramKey.c_str(),"inRequest"); |
---|
[558] | 157 | map* tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
| 158 | map* tmpSid=getMapFromMaps(m,"lenv","usid"); |
---|
| 159 | char tmp[1024]; |
---|
| 160 | map* tmpVal=getMapFromMaps(outputs,paramKey.c_str(),"mimeType"); |
---|
[618] | 161 | maps* tmpMaps=getMaps(outputs,paramKey.c_str()); |
---|
[550] | 162 | if(test!=NULL && test->value!=NULL && strncasecmp(test->value,"true",4)==0){ |
---|
| 163 | test=getMapFromMaps(inputs,paramKey.c_str(),"value"); |
---|
| 164 | if(type == ParameterType_OutputImage){ |
---|
| 165 | ImagePixelType outPixType = ImagePixelType_float; |
---|
| 166 | if (strncasecmp(test->value,"uint8",5)==0) |
---|
| 167 | outPixType = ImagePixelType_uint8; |
---|
| 168 | else if (strncasecmp(test->value,"int16",5)==0) |
---|
| 169 | outPixType = ImagePixelType_int16; |
---|
| 170 | else if (strncasecmp(test->value,"uint16",6)==0) |
---|
| 171 | outPixType = ImagePixelType_uint16; |
---|
| 172 | else if (strncasecmp(test->value,"int32",5)==0) |
---|
| 173 | outPixType = ImagePixelType_int32; |
---|
| 174 | else if (strncasecmp(test->value,"uint32",6)==0) |
---|
| 175 | outPixType = ImagePixelType_uint32; |
---|
| 176 | else if (strncasecmp(test->value,"double",6)==0) |
---|
| 177 | outPixType = ImagePixelType_double; |
---|
[576] | 178 | const char* ext="tiff"; |
---|
[550] | 179 | if(tmpVal!=NULL){ |
---|
| 180 | if(strncasecmp(tmpVal->value,"image/jp2",9)==0) |
---|
| 181 | ext="j2k"; |
---|
| 182 | else |
---|
| 183 | if(strncasecmp(tmpVal->value,"image/png",9)==0) |
---|
| 184 | ext="png"; |
---|
| 185 | else |
---|
| 186 | if(strncasecmp(tmpVal->value,"image/jpeg",10)==0) |
---|
| 187 | ext="jpeg"; |
---|
| 188 | } |
---|
| 189 | sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext); |
---|
| 190 | m_Application->SetParameterString(paramKey, tmp); |
---|
| 191 | setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp); |
---|
| 192 | dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType); |
---|
| 193 | } |
---|
[631] | 194 | else{ |
---|
| 195 | if(test!=NULL && test->value!=NULL) |
---|
| 196 | m_Application->SetParameterString(paramKey, test->value); |
---|
| 197 | } |
---|
[550] | 198 | }else{ |
---|
| 199 | if(type == ParameterType_OutputVectorData){ |
---|
| 200 | char* ext="json"; |
---|
| 201 | if(tmpVal!=NULL){ |
---|
| 202 | if(strncasecmp(tmpVal->value,"text/xml",8)==0) |
---|
| 203 | ext="gml"; |
---|
| 204 | else |
---|
| 205 | if(strncasecmp(tmpVal->value,"applicaton/json",15)==0) |
---|
| 206 | ext="json"; |
---|
| 207 | else |
---|
| 208 | if(strncasecmp(tmpVal->value,"application/zip",14)==0) |
---|
| 209 | ext="shp"; |
---|
| 210 | else |
---|
| 211 | if(strncasecmp(tmpVal->value,"application/vnd.google-earth.kml+xml",36)==0) |
---|
| 212 | ext="kml"; |
---|
| 213 | } |
---|
| 214 | sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext); |
---|
| 215 | m_Application->SetParameterString(paramKey, tmp); |
---|
| 216 | setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp); |
---|
| 217 | } |
---|
| 218 | else |
---|
| 219 | if(type == ParameterType_OutputFilename){ |
---|
| 220 | char* ext="txt"; |
---|
| 221 | if(tmpVal!=NULL){ |
---|
| 222 | if(strncasecmp(tmpVal->value,"text/xml",8)==0) |
---|
| 223 | ext="xml"; |
---|
| 224 | else |
---|
| 225 | if(strncasecmp(tmpVal->value,"text/csv",15)==0) |
---|
| 226 | ext="csv"; |
---|
| 227 | else |
---|
| 228 | if(strncasecmp(tmpVal->value,"application/zip",14)==0) |
---|
| 229 | ext="shp"; |
---|
| 230 | else |
---|
[564] | 231 | if(strncasecmp(tmpVal->value,"application/vnd.google-earth.kml+xml",36)==0) |
---|
| 232 | ext="kml"; |
---|
| 233 | else |
---|
[565] | 234 | if(strncasecmp(tmpVal->value,"application/vnd.google-earth.kmz",32)==0){ |
---|
[564] | 235 | ext="kmz"; |
---|
[565] | 236 | sprintf(tmp,"%s/%s_%sxt.%s",tmpPath->value,s->name,tmpSid->value,ext); |
---|
| 237 | m_Application->SetParameterString(paramKey, tmp); |
---|
| 238 | setMapInMaps(outputs,paramKey.c_str(),"expected_generated_file",tmp); |
---|
| 239 | } |
---|
[564] | 240 | |
---|
[550] | 241 | } |
---|
| 242 | sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext); |
---|
| 243 | m_Application->SetParameterString(paramKey, tmp); |
---|
| 244 | setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | } |
---|
| 248 | }else{ |
---|
| 249 | if(type == ParameterType_InputImageList){ |
---|
| 250 | values.push_back(test->value); |
---|
| 251 | map* tmpPath=getMapFromMaps(inputs,paramKey.c_str(),"length"); |
---|
| 252 | if(tmpPath!=NULL){ |
---|
| 253 | int len=atoi(tmpPath->value); |
---|
| 254 | for(int k=1;k<len;k++){ |
---|
[555] | 255 | char tmp[15]; |
---|
[550] | 256 | sprintf(tmp,"cache_file_%d",k); |
---|
| 257 | map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),tmp); |
---|
| 258 | if(tmpVal!=NULL){ |
---|
| 259 | values.push_back(tmpVal->value); |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | dynamic_cast<InputImageListParameter *> (param.GetPointer())->SetListFromFileName(values); |
---|
| 264 | } |
---|
| 265 | else |
---|
| 266 | if(type == ParameterType_InputVectorData || type == ParameterType_InputFilename){ |
---|
| 267 | map* tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
| 268 | map* tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
| 269 | char tmp[1024]; |
---|
| 270 | map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),"mimeType"); |
---|
| 271 | char* ext="json"; |
---|
| 272 | if(tmpVal!=NULL){ |
---|
| 273 | if(strncasecmp(tmpVal->value,"application/zip",14)==0){ |
---|
[632] | 274 | char *tmpName=(char*)malloc((strlen(test->value)+9)*sizeof(char)); |
---|
| 275 | std::string test0(test->value); |
---|
| 276 | if(test0.find(".zca")!=std::string::npos){ |
---|
| 277 | symlink(test->value,ReplaceAll(test->value,".zca",".zip").c_str()); |
---|
| 278 | sprintf(tmpName,"/vsizip/%s",ReplaceAll(test->value,".zca",".zip").c_str()); |
---|
| 279 | }else |
---|
| 280 | sprintf(tmpName,"/vsizip/%s",test->value); |
---|
[550] | 281 | char **files=VSIReadDir(tmpName); |
---|
| 282 | int nFiles = CSLCount( files ); |
---|
[632] | 283 | char *tmpSSName=(char*)malloc((strlen(tmpPath->value)+strlen(paramKey.c_str())+strlen(tmpSid->value)+9)*sizeof(char)); |
---|
| 284 | sprintf(tmpSSName,"%s/Input_%s_%s",tmpPath->value,paramKey.c_str(),tmpSid->value); |
---|
[550] | 285 | mkdir(tmpSSName,0777); |
---|
| 286 | |
---|
| 287 | for(int kk=0;kk<nFiles;kk++){ |
---|
[632] | 288 | char *tmpSName=(char*)malloc((strlen(tmpName)+strlen(files[kk])+2)*sizeof(char)); |
---|
[550] | 289 | sprintf(tmpSName,"%s/%s",tmpName,files[kk]); |
---|
| 290 | VSILFILE* fmain=VSIFOpenL(tmpSName, "rb"); |
---|
| 291 | if(fmain!=NULL){ |
---|
| 292 | VSIFSeekL(fmain,0,SEEK_END); |
---|
| 293 | long count=VSIFTellL(fmain); |
---|
| 294 | VSIRewindL(fmain); |
---|
| 295 | |
---|
| 296 | char *content=(char*) malloc((count+1)*sizeof(char)); |
---|
| 297 | VSIFReadL(content,1,count*sizeof(char),fmain); |
---|
| 298 | |
---|
[632] | 299 | char *tmpSSSName=(char*)malloc((strlen(tmpSSName)+strlen(files[kk])+2)*sizeof(char)); |
---|
[550] | 300 | sprintf(tmpSSSName,"%s/%s",tmpSSName,files[kk]); |
---|
| 301 | |
---|
| 302 | FILE* fx=fopen(tmpSSSName, "wb"); |
---|
| 303 | fwrite(content,1,count,fx); |
---|
| 304 | fclose(fx); |
---|
| 305 | VSIFCloseL(fmain); |
---|
| 306 | free(content); |
---|
| 307 | std::string test1(tmpSSSName); |
---|
| 308 | if(test1.find(".shp")!=std::string::npos){ |
---|
| 309 | setMapInMaps(inputs,paramKey.c_str(),"cache_file",tmpSSSName); |
---|
| 310 | test=getMapFromMaps(inputs,paramKey.c_str(),"cache_file"); |
---|
| 311 | } |
---|
[632] | 312 | free(tmpSSSName); |
---|
[550] | 313 | } |
---|
[632] | 314 | free(tmpSName); |
---|
[550] | 315 | } |
---|
[632] | 316 | free(tmpSSName); |
---|
| 317 | free(tmpName); |
---|
[550] | 318 | } |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | m_Application->SetParameterString(paramKey, test->value); |
---|
| 322 | } |
---|
| 323 | else |
---|
| 324 | if(type == ParameterType_InputImage |
---|
| 325 | || type == ParameterType_ComplexInputImage || type == ParameterType_InputVectorData |
---|
| 326 | || type == ParameterType_InputFilename){ |
---|
| 327 | m_Application->SetParameterString(paramKey, test->value); |
---|
[618] | 328 | } |
---|
[550] | 329 | } |
---|
| 330 | } |
---|
| 331 | param->SetUserValue(true); |
---|
| 332 | m_Application->UpdateParameters(); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | try{ |
---|
| 336 | if( m_Application->ExecuteAndWriteOutput() == 0 ){ |
---|
| 337 | std::vector< std::pair<std::string, std::string> > paramList; |
---|
| 338 | paramList = m_Application->GetOutputParametersSumUp(); |
---|
| 339 | if(paramList.size()>0) |
---|
| 340 | for( unsigned int i=0; i<paramList.size(); i++){ |
---|
| 341 | setMapInMaps(outputs,paramList[i].first.c_str(),"value",paramList[i].second.c_str()); |
---|
| 342 | } |
---|
| 343 | else{ |
---|
| 344 | const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); |
---|
| 345 | for (unsigned int i = 0; i < appKeyList.size(); i++){ |
---|
| 346 | const std::string paramKey(appKeyList[i]); |
---|
| 347 | std::vector<std::string> values; |
---|
| 348 | Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); |
---|
| 349 | ParameterType type = m_Application->GetParameterType(paramKey); |
---|
| 350 | if (type != ParameterType_Group && paramKey!="inxml" && paramKey!="outxml" |
---|
| 351 | && (type == ParameterType_OutputImage || type == ParameterType_OutputFilename |
---|
| 352 | || type == ParameterType_OutputVectorData ) ){ |
---|
| 353 | if(type == ParameterType_OutputImage || type == ParameterType_OutputFilename || type == ParameterType_OutputVectorData){ |
---|
| 354 | map* test=getMapFromMaps(outputs,paramKey.c_str(),"mimeType"); |
---|
| 355 | if(test!=NULL && strncasecmp(test->value,"application/zip",15)==0){ |
---|
| 356 | |
---|
| 357 | test=getMapFromMaps(inputs,paramKey.c_str(),"generated_file"); |
---|
| 358 | char tmpName[1024]; |
---|
| 359 | sprintf(tmpName,"/vsizip/%s",ReplaceAll(test->value,".shp",".zip").c_str()); |
---|
| 360 | VSILFILE* fmain=VSIFOpenL(tmpName, "w"); |
---|
| 361 | FILE * file; |
---|
| 362 | char *tmp; |
---|
| 363 | char tmpSName[1024]; |
---|
| 364 | long count; |
---|
| 365 | |
---|
| 366 | char *exts[4]; |
---|
| 367 | exts[0]=".shp"; |
---|
| 368 | exts[1]=".shx"; |
---|
| 369 | exts[2]=".dbf"; |
---|
| 370 | exts[3]=".prj"; |
---|
| 371 | for(int c=0;c<4;c++){ |
---|
| 372 | sprintf(tmpSName,"%s/result%s",tmpName,exts[c]); |
---|
| 373 | |
---|
| 374 | file=fopen(ReplaceAll(test->value,".shp",exts[c]).c_str(),"rb"); |
---|
| 375 | if(file!=NULL){ |
---|
| 376 | fseek(file, 0, SEEK_END); |
---|
| 377 | count = ftell(file); |
---|
| 378 | rewind(file); |
---|
| 379 | |
---|
| 380 | tmp=(char*) malloc((count+1)*sizeof(char)); |
---|
| 381 | fread(tmp,1,count*sizeof(char),file); |
---|
| 382 | |
---|
| 383 | VSILFILE* fx=VSIFOpenL(tmpSName, "wb"); |
---|
| 384 | VSIFWriteL(tmp,1,count,fx); |
---|
| 385 | VSIFCloseL(fx); |
---|
| 386 | fclose(file); |
---|
| 387 | free(tmp); |
---|
| 388 | } |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | VSIFCloseL(fmain); |
---|
| 392 | |
---|
| 393 | FILE* file1=fopen(ReplaceAll(test->value,".shp",".zip").c_str(), "rb"); |
---|
| 394 | fseek(file1, 0, SEEK_END); |
---|
| 395 | count=ftell(file1); |
---|
| 396 | rewind(file1); |
---|
| 397 | |
---|
| 398 | tmp=(char*) malloc((count+1)*sizeof(char)); |
---|
| 399 | fread(tmp,1,count*sizeof(char),file1); |
---|
| 400 | |
---|
| 401 | file=fopen(ReplaceAll(test->value,".shp",".zip").c_str(),"wb"); |
---|
| 402 | fwrite(tmp,1,count,file); |
---|
| 403 | fclose(file); |
---|
| 404 | free(tmp); |
---|
| 405 | fclose(file1); |
---|
| 406 | setMapInMaps(inputs,paramKey.c_str(),"generated_file",ReplaceAll(test->value,".shp",".zip").c_str()); |
---|
| 407 | } |
---|
| 408 | test=getMapFromMaps(inputs,paramKey.c_str(),"generated_file"); |
---|
| 409 | |
---|
| 410 | if(test!=NULL){ |
---|
| 411 | setMapInMaps(outputs,paramKey.c_str(),"generated_file",test->value); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | res=3; |
---|
| 419 | break; |
---|
| 420 | } |
---|
| 421 | else{ |
---|
| 422 | sprintf(tmpS, "The OTB Application %s cannot be run.", s->name); |
---|
| 423 | setMapInMaps(m,"lenv","message",tmpS); |
---|
| 424 | res=SERVICE_FAILED; |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | catch(std::exception& err){ |
---|
| 428 | setMapInMaps(m,"lenv","message",err.what()); |
---|
| 429 | return SERVICE_FAILED; |
---|
| 430 | |
---|
| 431 | } |
---|
| 432 | catch(...){ |
---|
| 433 | setMapInMaps(m,"lenv","message","An unknown exception has been raised during application execution"); |
---|
| 434 | res=SERVICE_FAILED; |
---|
| 435 | } |
---|
| 436 | break; |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | } |
---|
[558] | 441 | |
---|
| 442 | for (unsigned int i = 0; i < m_WatcherList.size(); i++){ |
---|
| 443 | m_WatcherList[i]->FreeConf(); |
---|
| 444 | delete m_WatcherList[i]; |
---|
| 445 | m_WatcherList[i] = NULL; |
---|
| 446 | } |
---|
| 447 | m_WatcherList.clear(); |
---|
| 448 | |
---|
[550] | 449 | return res; |
---|
| 450 | } |
---|