2013-10-11 14:10:06 -04:00
|
|
|
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
#ifndef _USER_DATA_SOURCE_H
|
|
|
|
#define _USER_DATA_SOURCE_H
|
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @file user_data_source.h Defines the base class, UserDataSource.
|
|
|
|
#include <exceptions/exceptions.h>
|
2013-10-11 14:10:06 -04:00
|
|
|
#include <user.h>
|
|
|
|
|
2013-12-31 15:38:13 -05:00
|
|
|
namespace user_chk {
|
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Thrown if UserDataSource encounters an error
|
|
|
|
class UserDataSourceError : public isc::Exception {
|
2013-10-11 14:10:06 -04:00
|
|
|
public:
|
2013-10-21 08:29:21 -04:00
|
|
|
UserDataSourceError(const char* file, size_t line,
|
|
|
|
const char* what) :
|
|
|
|
isc::Exception(file, line, what) { };
|
|
|
|
};
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Defines an interface for reading user data into a registry.
|
|
|
|
/// This is an abstract class which defines the interface for reading Users
|
|
|
|
/// from an IO source such as a file.
|
|
|
|
class UserDataSource {
|
|
|
|
public:
|
|
|
|
/// @brief Constructor.
|
|
|
|
UserDataSource() {};
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Virtual Destructor.
|
|
|
|
virtual ~UserDataSource() {};
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Opens the data source.
|
|
|
|
///
|
|
|
|
/// Prepares the data source for reading. Upon successful completion the
|
|
|
|
/// data source is ready to read from the beginning of its content.
|
|
|
|
///
|
|
|
|
/// @throw UserDataSourceError if the source fails to open.
|
|
|
|
virtual void open() = 0;
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Fetches the next user from the data source.
|
|
|
|
///
|
|
|
|
/// Reads the next User from the data source and returns it. If no more
|
|
|
|
/// data is available it should return an empty (null) user.
|
|
|
|
///
|
|
|
|
/// @throw UserDataSourceError if an error occurs.
|
|
|
|
virtual UserPtr readNextUser() = 0;
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Closes that data source.
|
|
|
|
///
|
|
|
|
/// Closes the data source.
|
|
|
|
///
|
|
|
|
/// This method must not throw exceptions.
|
|
|
|
virtual void close() = 0;
|
2013-10-11 14:10:06 -04:00
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Returns true if the data source is open.
|
|
|
|
///
|
|
|
|
/// This method should return true once the data source has been
|
|
|
|
/// successfully opened and until it has been closed.
|
|
|
|
///
|
|
|
|
/// It is assumed to be exception safe.
|
|
|
|
virtual bool isOpen() const = 0;
|
2013-10-11 14:10:06 -04:00
|
|
|
};
|
|
|
|
|
2013-10-21 08:29:21 -04:00
|
|
|
/// @brief Defines a smart pointer to a UserDataSource.
|
2013-10-11 14:10:06 -04:00
|
|
|
typedef boost::shared_ptr<UserDataSource> UserDataSourcePtr;
|
|
|
|
|
2013-12-31 15:38:13 -05:00
|
|
|
} // namespace user_chk
|
|
|
|
|
2013-10-11 14:10:06 -04:00
|
|
|
#endif
|