bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
AggMemberDatasetUsingLocationRef.cc
1
2// This file is part of the "NcML Module" project, a BES module designed
3// to allow NcML files to be used to be used as a wrapper to add
4// AIS to existing datasets of any format.
5//
6// Copyright (c) 2010 OPeNDAP, Inc.
7// Author: Michael Johnson <m.johnson@opendap.org>
8//
9// For more information, please also see the main website: http://opendap.org/
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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26//
27// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29
30#include "config.h"
31
32#include "AggMemberDatasetUsingLocationRef.h"
33
34#include "BESDataDDSResponse.h" // bes
35#include <libdap/DDS.h> // libdap
36
37#include "NCMLDebug.h" // ncml_module
38#include "NCMLUtil.h" // ncml_module
39#include "BESDebug.h"
40#include "BESStopWatch.h"
41
42using namespace std;
43
44#define MODULE "ncml"
45#define prolog string("AggMemberDatasetUsingLocationRef::").append(__func__).append("() - ")
46
47namespace agg_util {
48
49AggMemberDatasetUsingLocationRef::AggMemberDatasetUsingLocationRef(const std::string& locationToLoad,
50 const agg_util::DDSLoader& loaderToUse) :
51 AggMemberDatasetWithDimensionCacheBase(locationToLoad), _loader(loaderToUse), _pDataResponse(0)
52{
53}
54
55AggMemberDatasetUsingLocationRef::~AggMemberDatasetUsingLocationRef()
56{
57 cleanup();
58}
59
60AggMemberDatasetUsingLocationRef::AggMemberDatasetUsingLocationRef(const AggMemberDatasetUsingLocationRef& proto) :
61 RCObjectInterface(), AggMemberDatasetWithDimensionCacheBase(proto), _loader(proto._loader) // force a reload as needed for a copy
62{
63}
64
65AggMemberDatasetUsingLocationRef&
66AggMemberDatasetUsingLocationRef::operator=(const AggMemberDatasetUsingLocationRef& that)
67{
68 if (this != &that) {
69 // clear out any old loaded stuff
70 cleanup();
71 // assign
72 AggMemberDatasetWithDimensionCacheBase::operator=(that);
73 copyRepFrom(that);
74 }
75 return *this;
76}
77
78const libdap::DDS*
80{
81
82 if (!_pDataResponse) {
83 loadDDS();
84 }
85 DDS* pDDSRet = 0;
86 if (_pDataResponse) {
87 pDDSRet = _pDataResponse->get_dds();
88 }
89 return pDDSRet;
90}
91
93void AggMemberDatasetUsingLocationRef::loadDDS()
94{
95 BES_STOPWATCH_START(MODULE, prolog + "Timing");
96
97 // We cannot load an empty location, so avoid the exception later.
98 if (getLocation().empty()) {
99 THROW_NCML_INTERNAL_ERROR("AggMemberDatasetUsingLocationRef():"
100 " got empty location! Cannot load!");
101 }
102
103 // Make a new response and store the raw ptr, noting that we need to delete it in dtor.
104 unique_ptr<BESDapResponse> newResponse = agg_util::DDSLoader::makeResponseForType(DDSLoader::eRT_RequestDataDDS);
105
106 // static_cast should work here, but I want to be sure since DataDDX is in the works...
107 _pDataResponse = dynamic_cast<BESDataDDSResponse*>(newResponse.get());
108 NCML_ASSERT_MSG(_pDataResponse,
109 "AggMemberDatasetUsingLocationRef::loadDDS(): failed to get a BESDataDDSResponse back while loading location="
110 + getLocation());
111
112 // release after potential for exception to avoid double delete. Coverity reports
113 // this as a leak, but the _loader.loadInto() method takes ownership. jhrg 2/7/17
114 (void) newResponse.release();
115
116 BESDEBUG("ncml", "Loading loadDDS for aggregation member location = " << getLocation() << endl);
117 _loader.loadInto(getLocation(), DDSLoader::eRT_RequestDataDDS, _pDataResponse);
118}
119
120void AggMemberDatasetUsingLocationRef::cleanup() noexcept
121{
122 SAFE_DELETE(_pDataResponse);
123}
124
125void AggMemberDatasetUsingLocationRef::copyRepFrom(const AggMemberDatasetUsingLocationRef& rhs)
126{
127 _loader = rhs._loader;
128 _pDataResponse = nullptr; // force this to be NULL... we want to reload if we get an assignment
129}
130
131}
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
static std::unique_ptr< BESDapResponse > makeResponseForType(ResponseType type)
Definition DDSLoader.cc:427
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...