Blame Connect.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//         Dan Holloway <dan@hollywood.gso.uri.edu>
Packit a4aae4
//         Reza Nekovei <reza@intcomm.net>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1994-1999,2001,2002
Packit a4aae4
// Please first read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
// dan  Dan Holloway <dholloway@gso.uri.edu>
Packit a4aae4
// reza  Reza Nekovei <rnekovei@ieee.org>
Packit a4aae4
Packit a4aae4
// Connect objects are used as containers for information pertaining to a
Packit a4aae4
// connection that a user program makes to a dataset. The dataset may be
Packit a4aae4
// either local (i.e., a file on the user's own computer) or a remote
Packit a4aae4
// dataset. In the later case a DAP2 URL will be used to reference the
Packit a4aae4
// dataset.
Packit a4aae4
//
Packit a4aae4
// Connect contains methods which can be used to read the DOS DAS and DDS
Packit a4aae4
// objects from the remote dataset as well as reading reading data. The class
Packit a4aae4
// understands in a rudimentary way how DAP2 constraint expressions are
Packit a4aae4
// formed and how to manage the CEs generated by a API to request specific
Packit a4aae4
// variables with the URL initially presented to the class when the object
Packit a4aae4
// was instantiated.
Packit a4aae4
//
Packit a4aae4
// Connect also provides additional services such as error processing.
Packit a4aae4
//
Packit a4aae4
// Connect is not intended for use on the server-side.
Packit a4aae4
//
Packit a4aae4
// jhrg 9/29/94
Packit a4aae4
Packit a4aae4
#ifndef _connect_h
Packit a4aae4
#define _connect_h
Packit a4aae4
Packit a4aae4
Packit a4aae4
#include <string>
Packit a4aae4
Packit a4aae4
#ifndef _das_h
Packit a4aae4
#include "DAS.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _dds_h
Packit a4aae4
#include "DDS.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _error_h
Packit a4aae4
#include "Error.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _util_h
Packit a4aae4
#include "util.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _datadds_h
Packit a4aae4
#include "DataDDS.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef _httpconnect_h
Packit a4aae4
#include "HTTPConnect.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifndef response_h
Packit a4aae4
#include "Response.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
using std::string;
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
/** Connect objects are used as containers for information pertaining
Packit a4aae4
    to the connection a user program makes to a dataset. The
Packit a4aae4
    dataset may be either local (for example, a file on the user's own
Packit a4aae4
    computer) or a remote dataset. In the latter case a DAP2 URL will
Packit a4aae4
    be used to reference the dataset, instead of a filename.
Packit a4aae4
Packit a4aae4
    Connect contains methods which can be used to read the DAP2 DAS and
Packit a4aae4
    DDS objects from the remote dataset as well as reading
Packit a4aae4
    data. The class understands in a rudimentary way how DAP2
Packit a4aae4
    constraint expressions are formed and how to manage them.
Packit a4aae4
Packit a4aae4
    Connect also provides additional services such as automatic
Packit a4aae4
    decompression of compressed data and and error processing.
Packit a4aae4
Packit a4aae4
    @note Update: I removed the DEFAULT_BASETYPE_FACTORY switch because it
Packit a4aae4
    caused more confusion than it avoided. See Trac #130.
Packit a4aae4
Packit a4aae4
    @note The compile-time symbol DEFAULT_BASETYPE_FACTORY controls whether
Packit a4aae4
    the old (3.4 and earlier) DDS and DataDDS constructors are supported.
Packit a4aae4
    These constructors now use a default factory class (BaseTypeFactory,
Packit a4aae4
    implemented by this library) to instantiate Byte, ..., Grid variables. To
Packit a4aae4
    use the default ctor in your code you must also define this symbol. If
Packit a4aae4
    you \e do choose to define this and fail to provide a specialization of
Packit a4aae4
    BaseTypeFactory when your software needs one, you code may not link or
Packit a4aae4
    may fail at run time. In addition to the older ctors for DDS and DataDDS,
Packit a4aae4
    defining the symbol also makes some of the older methods in Connect
Packit a4aae4
    available (because those methods require the older DDS and DataDDS ctors.
Packit a4aae4
Packit a4aae4
    @brief Holds information about the link from a DAP2 client to a
Packit a4aae4
    dataset.
Packit a4aae4
    @see DDS
Packit a4aae4
    @see DAS
Packit a4aae4
    @see Error
Packit a4aae4
    @author jhrg */
Packit a4aae4
Packit a4aae4
class Connect
Packit a4aae4
{
Packit a4aae4
private:
Packit a4aae4
    bool _local;  // Is this a local connection?
Packit a4aae4
Packit a4aae4
    HTTPConnect *d_http;
Packit a4aae4
    string _URL;  // URL to remote dataset (minus CE)
Packit a4aae4
    string _proj;  // Projection part of initial CE.
Packit a4aae4
    string _sel;  // Selection of initial CE
Packit a4aae4
Packit a4aae4
    string d_version;           // Server implementation information
Packit a4aae4
    string d_protocol;          // DAP protocol from the server
Packit a4aae4
Packit a4aae4
    void process_data(DataDDS &data, Response *rs);
Packit a4aae4
    void process_data(DDS &data, Response *rs);
Packit a4aae4
Packit a4aae4
    // Use when you cannot use libwww/libcurl. Reads HTTP response.
Packit a4aae4
    void parse_mime(Response *rs);
Packit a4aae4
Packit a4aae4
protected:
Packit a4aae4
    /** @name Suppress the C++ defaults for these. */
Packit a4aae4
    //@{
Packit a4aae4
    Connect();
Packit a4aae4
    Connect(const Connect &);
Packit a4aae4
    Connect &operator=(const Connect &);
Packit a4aae4
    //@}
Packit a4aae4
Packit a4aae4
public:
Packit a4aae4
    Connect(const string &name, string uname = "", string password = "");
Packit a4aae4
Packit a4aae4
    virtual ~Connect();
Packit a4aae4
Packit a4aae4
    bool is_local();
Packit a4aae4
Packit a4aae4
    // *** Add get_* versions of accessors. 02/27/03 jhrg
Packit a4aae4
    virtual string URL(bool CE = true);
Packit a4aae4
    virtual string CE();
Packit a4aae4
Packit a4aae4
    void set_credentials(string u, string p);
Packit a4aae4
    void set_accept_deflate(bool deflate);
Packit a4aae4
    void set_xdap_protocol(int major, int minor);
Packit a4aae4
Packit a4aae4
    void set_cache_enabled(bool enabled);
Packit a4aae4
    bool is_cache_enabled();
Packit a4aae4
Packit a4aae4
    void set_xdap_accept(int major, int minor);
Packit a4aae4
Packit a4aae4
    /** Return the protocol/implementation version of the most recent
Packit a4aae4
    response. This is a poorly designed method, but it returns
Packit a4aae4
    information that is useful when used correctly. Before a response is
Packit a4aae4
    made, this contains the string "unknown." This should ultimately hold
Packit a4aae4
    the \e protocol version; it currently holds the \e implementation
Packit a4aae4
    version.
Packit a4aae4
Packit a4aae4
        @see get_protocol()
Packit a4aae4
        @deprecated */
Packit a4aae4
    string get_version()
Packit a4aae4
    {
Packit a4aae4
        return d_version;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /** Return the DAP protocol version of the most recent
Packit a4aae4
        response. Before a response is made, this contains the string "2.0."
Packit a4aae4
        */
Packit a4aae4
    string get_protocol()
Packit a4aae4
    {
Packit a4aae4
        return d_protocol;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    virtual string request_version();
Packit a4aae4
    virtual string request_protocol();
Packit a4aae4
Packit a4aae4
    virtual void request_das(DAS &das);
Packit a4aae4
    virtual void request_das_url(DAS &das);
Packit a4aae4
Packit a4aae4
    virtual void request_dds(DDS &dds, string expr = "");
Packit a4aae4
    virtual void request_dds_url(DDS &dds;;
Packit a4aae4
Packit a4aae4
    virtual void request_ddx(DDS &dds, string expr = "");
Packit a4aae4
    virtual void request_ddx_url(DDS &dds;;
Packit a4aae4
Packit a4aae4
    virtual void request_data(DataDDS &data, string expr = "");
Packit a4aae4
    virtual void request_data_url(DataDDS &data);
Packit a4aae4
Packit a4aae4
    virtual void request_data_ddx(DataDDS &data, string expr = "");
Packit a4aae4
    virtual void request_data_ddx_url(DataDDS &data);
Packit a4aae4
Packit a4aae4
    virtual void read_data(DataDDS &data, Response *rs);
Packit a4aae4
    virtual void read_data_no_mime(DataDDS &data, Response *rs);
Packit a4aae4
    virtual void read_data(DDS &data, Response *rs);
Packit a4aae4
    virtual void read_data_no_mime(DDS &data, Response *rs);
Packit a4aae4
};
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif // _connect_h