Permalink
Browse files

refactor: test for missing adapters in dataclientadapter base class

  • Loading branch information...
Chris Williams
Chris Williams committed Mar 29, 2012
1 parent 7383211 commit e37304e225cdc802293786547834879ed7e69df8
@@ -29,9 +29,9 @@ class AbstractAdaptingDataClient : public AbstractDataClient
public:
//PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
AbstractAdaptingDataClient( const ConfigNode& configNode,
- const QList<DataRequirements>& types,
- const Config* config,
- FactoryConfig<AbstractAdapter>* adapterFactory );
+ const DataTypes& types,
+ const Config* config
+ );
~AbstractAdaptingDataClient();
/// Returns the type of data associated with the data name
@@ -9,6 +9,7 @@
#include "pelican/utility/FactoryRegistrar.h"
#include "pelican/utility/Config.h"
#include "pelican/utility/ConfigNode.h"
+#include "pelican/utility/FactoryConfig.h"
#include <QtCore/QHash>
#include <QtCore/QList>
@@ -64,34 +65,35 @@ class AbstractDataClient
typedef QHash<QString, DataBlob*> DataBlobHash;
public:
- PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
/// Data client constructor.
AbstractDataClient(const ConfigNode& configNode, const DataTypes& types,
- const Config* config);
+ const Config* config
+ );
/// Data client destructor.
virtual ~AbstractDataClient();
+ PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
+
public:
/// Retrieves data requested by pipelines and fills the given data hash,
/// and returns another hash of valid data.
/// (\todo what is valid data in this context?)
virtual DataBlobHash getData(DataBlobHash&) = 0;
/// Returns the list of data requirements for each pipeline.
- const QList<DataRequirements>& dataRequirements()
- { return _dataReqs.dataRequirements(); }
+ const QList<DataRequirements>& dataRequirements() { return _dataRequirements; }
- /// Returns the type of data associated with the data name
- /// (stream/service/unknown)
- AbstractAdapter::AdapterType_t type(const QString& dataName) const
- { return _dataReqs.type(dataName); }
protected:
/// Writes a message to the log.
void log(const QString& msg);
+ /// Returns a pointer to the configuration node.
+ const ConfigNode& configNode() const {return _configNode;}
+
+/*
/// Adapts (de-serialises) stream data.
DataBlobHash adaptStream(QIODevice& device, const StreamData* d,
DataBlobHash& dataHash);
@@ -100,8 +102,6 @@ class AbstractDataClient
DataBlobHash adaptService(QIODevice& device, const DataChunk* sd,
DataBlobHash& dataHash);
- /// Returns a pointer to the configuration node.
- const ConfigNode& configNode() const {return _configNode;}
/// Returns the adapter for service data of the required type.
AbstractServiceAdapter* serviceAdapter(const QString& type) const
@@ -110,12 +110,12 @@ class AbstractDataClient
/// Returns the adapter for stream data of the required type.
AbstractStreamAdapter* streamAdapter(const QString& type) const
{ return _dataReqs.streamAdapter(type); }
-
- private:
- ConfigNode _configNode; ///< The configuration node for the data client.
- DataTypes _dataReqs; ///< The DataTypes and requirements.
+*/
protected:
+ ConfigNode _configNode; ///< The configuration node for the data client.
+ QList<DataRequirements> _dataRequirements;
+ //DataTypes _dataReqs; ///< The DataTypes and requirements.
const Config* _config;
QSet<QString> _requireSet;
};
@@ -6,6 +6,7 @@
*/
#include "pelican/core/AbstractDataClient.h"
+#include "pelican/core/AbstractAdapterFactory.h"
#include "pelican/utility/FactoryConfig.h"
#include <QtCore/QList>
@@ -31,12 +32,12 @@ class DataRequirements;
class DataClientFactory : public FactoryConfig<AbstractDataClient>
{
private:
- FactoryConfig<AbstractAdapter>* _adapterFactory;
+ AbstractAdapterFactory* _adapterFactory;
public:
/// Constructs the data client factory.
DataClientFactory(const Config* config, const QString& section,
- const QString& group, FactoryConfig<AbstractAdapter>* aFactory)
+ const QString& group, AbstractAdapterFactory* aFactory)
: FactoryConfig<AbstractDataClient>(config, section, group),
_adapterFactory(aFactory) {}
View
@@ -52,6 +52,9 @@ class DataTypes
/// Return the adapter type associated with the given data stream.
AbstractAdapter::AdapterType_t type(const QString& dataName) const;
+ /// return true is the object maps an adapter to the specified type
+ bool adapterAvailable( const QString& type ) const;
+
private:
QList<DataRequirements> _dataRequirements;
QHash<QString,AbstractAdapter*> _adapters;
@@ -5,7 +5,7 @@
* @file DirectStreamDataClient.h
*/
-#include "pelican/core/AbstractDataClient.h"
+#include "pelican/core/AbstractAdaptingDataClient.h"
namespace pelican {
@@ -30,12 +30,13 @@ class Config;
* Add the chunkers using the addChunker() method in a derived class
* constructor.
*/
-class DirectStreamDataClient : public AbstractDataClient
+class DirectStreamDataClient : public AbstractAdaptingDataClient
{
public:
/// Constructs the direct stream data client.
DirectStreamDataClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config);
+ const DataTypes& types, const Config* config
+ );
/// Destroys the direct stream data client.
virtual ~DirectStreamDataClient();
@@ -5,7 +5,7 @@
* @file FileDataClient.h
*/
-#include "pelican/core/AbstractDataClient.h"
+#include "pelican/core/AbstractAdaptingDataClient.h"
#include <QtCore/QHash>
#include <QtCore/QString>
class QFile;
@@ -30,7 +30,7 @@ class DataTypes;
* makes it available to the pipelines via the pipeline driver.
*/
-class FileDataClient : public AbstractDataClient
+class FileDataClient : public AbstractAdaptingDataClient
{
public:
/// Data client constructor.
@@ -5,7 +5,7 @@
* @file PelicanServerClient.h
*/
-#include "AbstractDataClient.h"
+#include "AbstractAdaptingDataClient.h"
#include <boost/shared_ptr.hpp>
using boost::shared_ptr;
@@ -29,12 +29,13 @@ class ServiceDataRequest;
* @details
*/
-class PelicanServerClient : public AbstractDataClient
+class PelicanServerClient : public AbstractAdaptingDataClient
{
public:
/// Construct and initialise the Pelican server client.
PelicanServerClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config);
+ const DataTypes& types, const Config* config
+ );
virtual ~PelicanServerClient();
@@ -21,6 +21,7 @@ class AbstractDataClient;
class Config;
class PipelineDriver;
class DataClientFactory;
+class AbstractAdapterFactory;
class OutputStreamManager;
class PipelineSwitcher;
@@ -92,7 +93,7 @@ class PipelineApplication
~PipelineApplication();
/// Return a pointer to the adapter factory.
- FactoryConfig<AbstractAdapter>* adapterFactory();
+ AbstractAdapterFactory* adapterFactory();
/// Return a pointer to the client factory.
DataClientFactory* clientFactory();
@@ -150,7 +151,7 @@ class PipelineApplication
// Base nodes to define configuration file.
Config::TreeAddress _osmanagerBase;
- FactoryConfig<AbstractAdapter>* _adapterFactory;
+ AbstractAdapterFactory* _adapterFactory;
DataClientFactory* _clientFactory;
FactoryConfig<AbstractModule>* _moduleFactory;
};
@@ -12,31 +12,17 @@ namespace pelican {
*@details AbstractAdaptingDataClient
*/
AbstractAdaptingDataClient::AbstractAdaptingDataClient( const ConfigNode& configNode,
- const QList<DataRequirements>& requirements,
- const Config* config, FactoryConfig<AbstractAdapter>* adapterFactory )
- : AbstractDataClient( configNode, requirements, config, adapterFactory )
+ const DataTypes& requirements,
+ const Config* config )
+ : AbstractDataClient( configNode, requirements, config )
{
- _dataReqs.addData(requirements);
-
- // Find the configuration information for adapters.
- QHash<QString, QString> adapterNames = configNode.getOptionHash("data", "type", "adapter");
-
- // Construct the adapters and add them to the DataTypes structure.
- foreach (const DataRequirements& req, requirements)
- {
- QSet<QString> all = req.allData();
- foreach (const QString& dataType, all)
- {
- if (!adapterNames.contains(dataType))
- throw QString("DataClientFactory: Unable to find adapter for "
- "data type '%1'.").arg(dataType);
- AbstractAdapter* adapter =
- _adapterFactory->create(adapterNames.value(dataType),
- configNode.getNamedOption("data","name","") );
- _dataReqs.setAdapter(dataType, adapter);
- }
+ _dataReqs = requirements;
+ // check we have adapters for each type
+ foreach (const QString& dataType, _requireSet) {
+ if (!_dataReqs.adapterAvailable(dataType))
+ throw QString("AbstractAdaptingDataClient: Unable to find adapter for "
+ "data type '%1'.").arg(dataType);
}
-
}
/**
@@ -25,11 +25,13 @@ namespace pelican {
* @param[in] config \todo needs description
*/
AbstractDataClient::AbstractDataClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config)
-: _configNode(configNode), _dataReqs(types), _config(config)
+ const DataTypes& types, const Config* config )
+: _configNode(configNode), _config(config)
{
+ _dataRequirements = types.dataRequirements();
+
// Quick sanity check.
- if (_dataReqs.dataRequirements().size() == 0)
+ if (_dataRequirements.size() == 0)
throw QString("AbstractDataClient: No data requirements specified");
// Construct the total set of requirements.
@@ -65,6 +67,7 @@ void AbstractDataClient::log(const QString& msg)
*
* @return
*/
+/*
AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
QIODevice& device, const StreamData* sd, DataBlobHash& dataHash)
{
@@ -80,6 +83,7 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
return validData;
}
+*/
/**
* @details
@@ -90,7 +94,6 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
* @param dataHash
*
* @return
- */
AbstractDataClient::DataBlobHash AbstractDataClient::adaptService(
QIODevice& device, const DataChunk* d, DataBlobHash& dataHash)
{
@@ -104,5 +107,6 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptService(
validData.insert(type, dataHash.value(type));
return validData;
}
+ */
} // namespace pelican
@@ -34,19 +34,22 @@ AbstractDataClient* DataClientFactory::create(const QString& type,
QSet<QString> all = req.allData();
foreach (const QString& dataType, all)
{
- if (!adapterNames.contains(dataType))
- throw QString("DataClientFactory: Unable to find adapter for "
- "data type '%1'.").arg(dataType);
- AbstractAdapter* adapter =
- _adapterFactory->create(adapterNames.value(dataType),
- conf(type, name).getNamedOption("data","name","") );
- dataTypes.setAdapter(dataType, adapter);
+ //if (!adapterNames.contains(dataType))
+ // throw QString("DataClientFactory: Unable to find adapter for "
+ // "data type '%1'.").arg(dataType);
+ if (adapterNames.contains(dataType)) {
+ AbstractAdapter* adapter =
+ _adapterFactory->create(adapterNames.value(dataType),
+ conf(type, name).getNamedOption("data","name","") );
+ dataTypes.setAdapter(dataType, adapter);
+ }
}
}
// Call the base class implementation and set the data requirements.
AbstractDataClient* client = FactoryConfig<AbstractDataClient>::create(
- type, dataTypes, _config, name);
+ type, dataTypes, _config , name);
+
return client;
}
@@ -88,4 +88,8 @@ const QList<DataRequirements>& DataTypes::dataRequirements() const
return _dataRequirements;
}
+bool DataTypes::adapterAvailable( const QString& type ) const {
+ return _adapters.contains(type);
+}
+
} // namespace pelican
@@ -21,8 +21,9 @@ class ConfigNode;
* @details Constructs the DirectStreamDataClient.
*/
DirectStreamDataClient::DirectStreamDataClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config)
-: AbstractDataClient(configNode, types, config)
+ const DataTypes& types, const Config* config
+ )
+ : AbstractAdaptingDataClient(configNode, types, config )
{
// Initialise members.
_started = false;
@@ -15,8 +15,8 @@ namespace pelican {
* This creates a new file data client.
*/
FileDataClient::FileDataClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config) :
- AbstractDataClient(configNode, types, config)
+ const DataTypes& types, const Config* config)
+ : AbstractAdaptingDataClient(configNode, types, config)
{
// Get the configuration options.
_getConfig();
@@ -35,8 +35,9 @@ namespace pelican {
* @param config
*/
PelicanServerClient::PelicanServerClient(const ConfigNode& configNode,
- const DataTypes& types, const Config* config)
- : AbstractDataClient(configNode, types, config), _protocol(0)
+ const DataTypes& types, const Config* config
+ )
+ : AbstractAdaptingDataClient(configNode, types, config), _protocol(0)
{
_protocol = new PelicanClientProtocol;
Oops, something went wrong.

0 comments on commit e37304e

Please sign in to comment.