Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OGDI Bridge 4 : * Purpose: Implements OGROGDIDriver class. 5 : * Author: Daniel Morissette, danmo@videotron.ca 6 : * (Based on some code contributed by Frank Warmerdam :) 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2000, Daniel Morissette 10 : * 11 : * Permission is hereby granted, free of charge, to any person obtaining a 12 : * copy of this software and associated documentation files (the "Software"), 13 : * to deal in the Software without restriction, including without limitation 14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 : * and/or sell copies of the Software, and to permit persons to whom the 16 : * Software is furnished to do so, subject to the following conditions: 17 : * 18 : * The above copyright notice and this permission notice shall be included 19 : * in all copies or substantial portions of the Software. 20 : * 21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 : * DEALINGS IN THE SOFTWARE. 28 : ****************************************************************************/ 29 : 30 : #include "ogrogdi.h" 31 : #include "ogrogdidrivercore.h" 32 : 33 : #include "cpl_conv.h" 34 : 35 : /************************************************************************/ 36 : /* MyOGDIReportErrorFunction() */ 37 : /************************************************************************/ 38 : 39 : #if OGDI_RELEASEDATE >= 20160705 40 0 : static int MyOGDIReportErrorFunction(int errorcode, const char *error_message) 41 : { 42 0 : CPLError(CE_Failure, CPLE_AppDefined, "OGDI error %d: %s", errorcode, 43 : error_message); 44 0 : return FALSE; // go on 45 : } 46 : #endif 47 : 48 : /************************************************************************/ 49 : /* Open() */ 50 : /************************************************************************/ 51 : 52 4 : static GDALDataset *OGROGDIDriverOpen(GDALOpenInfo *poOpenInfo) 53 : 54 : { 55 4 : const char *pszFilename = poOpenInfo->pszFilename; 56 4 : if (!STARTS_WITH_CI(pszFilename, "gltp:")) 57 0 : return nullptr; 58 : 59 : #if OGDI_RELEASEDATE >= 20160705 60 : // Available only in post OGDI 3.2.0beta2 61 : // and only called if env variable OGDI_STOP_ON_ERROR is set to NO 62 4 : ecs_SetReportErrorFunction(MyOGDIReportErrorFunction); 63 : #endif 64 : 65 4 : OGROGDIDataSource *poDS = new OGROGDIDataSource(); 66 : 67 4 : if (!poDS->Open(pszFilename)) 68 : { 69 0 : delete poDS; 70 0 : poDS = nullptr; 71 : } 72 : 73 4 : const bool bUpdate = (poOpenInfo->nOpenFlags & GDAL_OF_UPDATE) != 0; 74 4 : if (poDS != nullptr && bUpdate) 75 : { 76 0 : CPLError(CE_Failure, CPLE_OpenFailed, 77 : "OGDI Driver doesn't support update."); 78 0 : delete poDS; 79 0 : poDS = nullptr; 80 : } 81 : 82 4 : return poDS; 83 : } 84 : 85 : /************************************************************************/ 86 : /* RegisterOGROGDI() */ 87 : /************************************************************************/ 88 : 89 8 : void RegisterOGROGDI() 90 : 91 : { 92 8 : if (!GDAL_CHECK_VERSION("OGR/OGDI driver")) 93 0 : return; 94 : 95 8 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 96 0 : return; 97 : 98 8 : GDALDriver *poDriver = new GDALDriver(); 99 8 : OGROGDIDriverSetCommonMetadata(poDriver); 100 : 101 8 : poDriver->pfnOpen = OGROGDIDriverOpen; 102 : 103 8 : GetGDALDriverManager()->RegisterDriver(poDriver); 104 : }