bes  Updated for version 3.20.13
GDALModule.cc
1 // GDALModule.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // This file is part of the GDAL OPeNDAP Adapter
7 
8 // Copyright (c) 2004 OPeNDAP, Igdal.
9 // Author: Frank Warmerdam <warmerdam@pobox.com>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Igdal., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Igdal. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 #include "config.h"
28 
29 #include <iostream>
30 
31 #include <dispatch/BESRequestHandlerList.h>
32 #include <dispatch/BESContainerStorageList.h>
33 #include <dispatch/BESFileContainerStorage.h>
34 #include <dispatch/BESCatalogDirectory.h>
35 #include <dispatch/BESCatalogList.h>
36 #include <dispatch/BESReturnManager.h>
37 #include <dispatch/BESServiceRegistry.h>
38 #include <dispatch/BESDebug.h>
39 
40 #include <dap/BESDapNames.h>
41 #include <dap/BESDapService.h>
42 
43 #include "GDALModule.h"
44 #include "GDALRequestHandler.h"
45 #include "writer/GeoTiffTransmitter.h"
46 #include "writer/JPEG2000Transmitter.h"
47 
48 #define GDAL_CATALOG "catalog"
49 #define RETURNAS_GEOTIFF "geotiff"
50 #define RETURNAS_JPEG2000 "jpeg2000"
51 
52 #define JP2 1
53 
54 using namespace std;
55 
56 void GDALModule::initialize(const string & modname)
57 {
58  BESDEBUG("gdal", "Initializing GDAL module " << modname << endl);
59 
60  BESRequestHandler *handler = new GDALRequestHandler(modname);
61  BESRequestHandlerList::TheList()->add_handler(modname, handler);
62 
63  // This part if the module responds to requests for DMR, DAP, etc., responses.
64 
66 
67  if (!BESCatalogList::TheCatalogList()->ref_catalog(GDAL_CATALOG)) {
68  BESCatalogList::TheCatalogList()-> add_catalog(new BESCatalogDirectory(GDAL_CATALOG));
69  }
70 
71  if (!BESContainerStorageList::TheList()->ref_persistence(GDAL_CATALOG)) {
72  BESFileContainerStorage *csc = new BESFileContainerStorage(GDAL_CATALOG);
73  BESContainerStorageList::TheList()->add_persistence(csc);
74  }
75 
76  // This part of the handler sets up transmitters that return geotiff and jp2000 responses
77  BESReturnManager::TheManager()->add_transmitter(RETURNAS_GEOTIFF, new GeoTiffTransmitter());
78  BESServiceRegistry::TheRegistry()->add_format(OPENDAP_SERVICE, DATA_SERVICE, RETURNAS_GEOTIFF);
79 
80 #if JP2
81  BESReturnManager::TheManager()->add_transmitter(RETURNAS_JPEG2000, new JPEG2000Transmitter());
82  BESServiceRegistry::TheRegistry()->add_format(OPENDAP_SERVICE, DATA_SERVICE, RETURNAS_JPEG2000);
83 #endif
84 
85  BESDebug::Register("gdal");
86 
87  BESDEBUG("gdal", "Done Initializing GDAL module " << modname << endl);
88 }
89 
90 void GDALModule::terminate(const string & modname)
91 {
92  BESDEBUG("gdal", "Cleaning GDAL module " << modname << endl);
93 
94  BESContainerStorageList::TheList()->deref_persistence(GDAL_CATALOG);
95 
96  BESCatalogList::TheCatalogList()->deref_catalog(GDAL_CATALOG);
97 
98  BESReturnManager::TheManager()->del_transmitter(RETURNAS_GEOTIFF);
99 #if JP2
100  BESReturnManager::TheManager()->del_transmitter(RETURNAS_JPEG2000);
101 #endif
102 
103  delete BESRequestHandlerList::TheList()->remove_handler(modname);
104 
105  BESDEBUG("gdal", "Done Cleaning GDAL module " << modname << endl);
106 }
107 
114 void GDALModule::dump(ostream & strm) const
115 {
116  strm << BESIndent::LMarg << "GDALModule::dump - (" << (void *) this << ")" << endl;
117 }
118 
119 extern "C" BESAbstractModule * maker()
120 {
121  return new GDALModule;
122 }
123 
Catalogs from a directory structure.
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
virtual bool deref_persistence(const std::string &persist_name)
dereference a persistent store in the list.
static void handle_dap_service(const std::string &handler)
static function to register a handler to handle the dap services
static void Register(const std::string &flagName)
register the specified debug flag
Definition: BESDebug.h:149
implementation of BESContainerStorage that represents a data within a catalog repository
virtual bool add_handler(const std::string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
virtual BESRequestHandler * remove_handler(const std::string &handler_name)
remove and return the specified request handler
Represents a specific data type request handler.
virtual void add_format(const std::string &service, const std::string &cmd, const std::string &format)
add a format response to a command of a service
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: GDALModule.cc:114
BESTransmitter class named "geotiff" that transmits an OPeNDAP data object as a geotiff file.
BESTransmitter class named "geotiff" that transmits an OPeNDAP data object as a geotiff file.