You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
5.5 KiB
Plaintext
178 lines
5.5 KiB
Plaintext
1 year ago
|
/***************************************************************************
|
||
|
* Copyright (C) gempa GmbH *
|
||
|
* All rights reserved. *
|
||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||
|
* *
|
||
|
* GNU Affero General Public License Usage *
|
||
|
* This file may be used under the terms of the GNU Affero *
|
||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||
|
* file. Please review the following information to ensure the GNU Affero *
|
||
|
* Public License version 3.0 requirements will be met: *
|
||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||
|
* *
|
||
|
* Other Usage *
|
||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||
|
* conditions contained in a signed written agreement between you and *
|
||
|
* gempa GmbH. *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include <string.h>
|
||
|
#include <seiscomp/core/exceptions.h>
|
||
|
|
||
|
namespace Seiscomp {
|
||
|
namespace Core {
|
||
|
namespace Generic {
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
InterfaceFactoryInterface<T>::InterfaceFactoryInterface(const char* serviceName) {
|
||
|
_serviceName = serviceName;
|
||
|
RegisterFactory(this);
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
InterfaceFactoryInterface<T>::~InterfaceFactoryInterface() {
|
||
|
UnregisterFactory(this);
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
T* InterfaceFactoryInterface<T>::Create(const char* serviceName) {
|
||
|
InterfaceFactoryInterface* factoryInterface = Find(serviceName);
|
||
|
if ( factoryInterface != nullptr )
|
||
|
return factoryInterface->create();
|
||
|
|
||
|
return nullptr;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
T* InterfaceFactoryInterface<T>::Create(const std::string &serviceName) {
|
||
|
return Create(serviceName.c_str());
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
unsigned int InterfaceFactoryInterface<T>::ServiceCount() {
|
||
|
return Pool().size();
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
typename InterfaceFactoryInterface<T>::ServiceNames*
|
||
|
InterfaceFactoryInterface<T>::Services() {
|
||
|
if ( ServiceCount() == 0 ) return nullptr;
|
||
|
|
||
|
ServiceNames* names = new ServiceNames;
|
||
|
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it )
|
||
|
names->push_back((*it)->serviceName());
|
||
|
|
||
|
return names;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
InterfaceFactoryInterface<T>*
|
||
|
InterfaceFactoryInterface<T>::Find(const char* serviceName) {
|
||
|
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it ) {
|
||
|
if ( !strcmp((*it)->serviceName(), serviceName) )
|
||
|
return *it;
|
||
|
}
|
||
|
|
||
|
return nullptr;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
const char* InterfaceFactoryInterface<T>::serviceName() const {
|
||
|
return _serviceName.c_str();
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
bool InterfaceFactoryInterface<T>::RegisterFactory(InterfaceFactoryInterface* factory) {
|
||
|
if ( factory == nullptr )
|
||
|
return false;
|
||
|
|
||
|
if ( Find(factory->serviceName()) != nullptr )
|
||
|
return false;
|
||
|
|
||
|
Pool().push_back(factory);
|
||
|
return true;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
bool InterfaceFactoryInterface<T>::UnregisterFactory(InterfaceFactoryInterface* factory) {
|
||
|
for ( typename ServicePool::iterator it = Pool().begin(); it != Pool().end(); ++it ) {
|
||
|
if ( *it == factory ) {
|
||
|
Pool().erase(it);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename T>
|
||
|
typename InterfaceFactoryInterface<T>::ServicePool &InterfaceFactoryInterface<T>::Pool() {
|
||
|
static ServicePool* pool = new ServicePool;
|
||
|
return *pool;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
}
|
||
|
}
|
||
|
}
|