LCOV - code coverage report
Current view: directory - gcore - gdaldllmain.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 10 2 20.0 %
Date: 2013-03-30 Functions: 2 1 50.0 %

       1                 : /******************************************************************************
       2                 :  * $Id$
       3                 :  *
       4                 :  * Project:  GDAL Core
       5                 :  * Purpose:  The library set-up/clean-up routines.
       6                 :  * Author:   Mateusz Loskot <mateusz@loskot.net>
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2010, Mateusz Loskot <mateusz@loskot.net>
      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 "gdal.h"
      31                 : #include "ogr_api.h"
      32                 : #include "cpl_multiproc.h"
      33                 : #include "cpl_conv.h"
      34                 : #include "cpl_string.h"
      35                 : 
      36                 : /************************************************************************/
      37                 : /*  The library set-up/clean-up routines implemented with               */
      38                 : /*  GNU C/C++ extensions.                                               */
      39                 : /*  TODO: Is it Linux-only solution or Unix portable?                   */
      40                 : /************************************************************************/
      41                 : #ifdef __GNUC__
      42                 : 
      43                 : static void GDALInitialize(void) __attribute__ ((constructor)) ;
      44                 : static void GDALDestroy(void)    __attribute__ ((destructor)) ;
      45                 : 
      46                 : /************************************************************************/
      47                 : /* Called when GDAL is loaded by loader or by dlopen(),                 */
      48                 : /* and before dlopen() returns.                                         */
      49                 : /************************************************************************/
      50                 : 
      51             758 : static void GDALInitialize(void)
      52                 : {
      53                 :     // nothing to do
      54                 :     //CPLDebug("GDAL", "Library loaded");
      55             758 : }
      56                 : 
      57                 : /************************************************************************/
      58                 : /* Called when GDAL is unloaded by loader or by dlclose(),              */
      59                 : /* and before dlclose() returns.                                        */
      60                 : /************************************************************************/
      61                 : 
      62               0 : static void GDALDestroy(void)
      63                 : {
      64                 :     // TODO: Confirm if calling CPLCleanupTLS here is safe
      65                 :     //CPLCleanupTLS();
      66                 :     
      67               0 :     if( !CSLTestBoolean(CPLGetConfigOption("GDAL_DESTROY", "YES")) )
      68               0 :         return;
      69                 : 
      70               0 :     CPLDebug("GDAL", "In GDALDestroy - unloading GDAL shared library.");
      71               0 :     CPLSetConfigOption("GDAL_CLOSE_JP2ECW_RESOURCE", "NO");
      72               0 :     GDALDestroyDriverManager();
      73               0 :     CPLSetConfigOption("GDAL_CLOSE_JP2ECW_RESOURCE", NULL);
      74                 : 
      75                 : #ifdef OGR_ENABLED
      76               0 :     OGRCleanupAll();
      77                 : #endif
      78                 : }
      79                 : 
      80                 : #endif // __GNUC__
      81                 : 
      82                 : 
      83                 : /************************************************************************/
      84                 : /*  The library set-up/clean-up routine implemented as DllMain entry    */
      85                 : /*  point specific for Windows.                                         */
      86                 : /************************************************************************/
      87                 : #ifdef _MSC_VER
      88                 : 
      89                 : #include <windows.h>
      90                 : 
      91                 : extern "C" int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
      92                 : {
      93                 :     UNREFERENCED_PARAMETER(hInstance);
      94                 :     UNREFERENCED_PARAMETER(lpReserved);
      95                 : 
      96                 :     if (dwReason == DLL_PROCESS_ATTACH)
      97                 :     {
      98                 :         // nothing to do
      99                 :     }
     100                 :     else if (dwReason == DLL_THREAD_ATTACH)
     101                 :     {
     102                 :         // nothing to do
     103                 :     }
     104                 :     else if (dwReason == DLL_THREAD_DETACH)
     105                 :     {
     106                 :         ::CPLCleanupTLS();
     107                 :     }
     108                 :     else if (dwReason == DLL_PROCESS_DETACH)
     109                 :     {
     110                 :         ::GDALDestroyDriverManager();
     111                 : 
     112                 : #ifdef OGR_ENABLED
     113                 :         ::OGRCleanupAll();
     114                 : #endif
     115                 :     }
     116                 : 
     117                 :   return 1; // ignroed for all reasons but DLL_PROCESS_ATTACH
     118                 : }
     119                 : 
     120                 : #endif // _MSC_VER
     121                 : 

Generated by: LCOV version 1.7