Refactoring of built-in services registration system.
This commit is contained in:
parent
6f278de337
commit
1e94a4a70f
@ -207,6 +207,7 @@ libvmime_messaging_sources = [
|
|||||||
'net/service.cpp', 'net/service.hpp',
|
'net/service.cpp', 'net/service.hpp',
|
||||||
'net/serviceFactory.cpp', 'net/serviceFactory.hpp',
|
'net/serviceFactory.cpp', 'net/serviceFactory.hpp',
|
||||||
'net/serviceInfos.cpp', 'net/serviceInfos.hpp',
|
'net/serviceInfos.cpp', 'net/serviceInfos.hpp',
|
||||||
|
'net/serviceRegistration.inl',
|
||||||
'net/session.cpp', 'net/session.hpp',
|
'net/session.cpp', 'net/session.hpp',
|
||||||
'net/socket.hpp',
|
'net/socket.hpp',
|
||||||
'net/store.hpp',
|
'net/store.hpp',
|
||||||
|
@ -21,14 +21,14 @@
|
|||||||
// the GNU General Public License cover the whole combination.
|
// the GNU General Public License cover the whole combination.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
// Include registration helpers
|
||||||
|
#include "src/net/serviceRegistration.inl"
|
||||||
|
|
||||||
|
|
||||||
#ifndef VMIME_BUILDING_DOC
|
#ifndef VMIME_BUILDING_DOC
|
||||||
|
|
||||||
|
|
||||||
#define REGISTER_SERVICE(p_class, p_name, p_type) \
|
|
||||||
vmime::net::service::initializer <vmime::net::p_class> \
|
|
||||||
p_name(#p_name, vmime::net::service::p_type)
|
|
||||||
|
|
||||||
|
|
||||||
#if VMIME_BUILTIN_MESSAGING_PROTO_POP3
|
#if VMIME_BUILTIN_MESSAGING_PROTO_POP3
|
||||||
#include "vmime/net/pop3/POP3Store.hpp"
|
#include "vmime/net/pop3/POP3Store.hpp"
|
||||||
REGISTER_SERVICE(pop3::POP3Store, pop3, TYPE_STORE);
|
REGISTER_SERVICE(pop3::POP3Store, pop3, TYPE_STORE);
|
||||||
|
@ -122,5 +122,11 @@ const std::vector <ref <const serviceFactory::registeredService> > serviceFactor
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void serviceFactory::registerService(ref <registeredService> reg)
|
||||||
|
{
|
||||||
|
m_services.push_back(reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // net
|
} // net
|
||||||
} // vmime
|
} // vmime
|
||||||
|
98
src/net/serviceRegistration.inl
Normal file
98
src/net/serviceRegistration.inl
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
//
|
||||||
|
// VMime library (http://www.vmime.org)
|
||||||
|
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of
|
||||||
|
// the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
//
|
||||||
|
// Linking this library statically or dynamically with other modules is making
|
||||||
|
// a combined work based on this library. Thus, the terms and conditions of
|
||||||
|
// the GNU General Public License cover the whole combination.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "vmime/net/serviceFactory.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef VMIME_BUILDING_DOC
|
||||||
|
|
||||||
|
|
||||||
|
namespace vmime {
|
||||||
|
namespace net {
|
||||||
|
|
||||||
|
|
||||||
|
template <class S>
|
||||||
|
class registeredServiceImpl : public serviceFactory::registeredService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
registeredServiceImpl(const string& name, const int type)
|
||||||
|
: m_type(type), m_name(name), m_servInfos(S::getInfosInstance())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ref <service> create
|
||||||
|
(ref <session> sess,
|
||||||
|
ref <security::authenticator> auth) const
|
||||||
|
{
|
||||||
|
return vmime::create <S>(sess, auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
const serviceInfos& getInfos() const
|
||||||
|
{
|
||||||
|
return (m_servInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
const string& getName() const
|
||||||
|
{
|
||||||
|
return (m_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const int getType() const
|
||||||
|
{
|
||||||
|
return (m_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const int m_type;
|
||||||
|
const string m_name;
|
||||||
|
const serviceInfos& m_servInfos;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Basic service registerer
|
||||||
|
template <class S>
|
||||||
|
class serviceRegisterer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
serviceRegisterer(const string& protocol, const service::Type type)
|
||||||
|
{
|
||||||
|
serviceFactory::getInstance()->registerService
|
||||||
|
(vmime::create <vmime::net::registeredServiceImpl <S> >(protocol, type));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // net
|
||||||
|
} // vmime
|
||||||
|
|
||||||
|
|
||||||
|
#define REGISTER_SERVICE(p_class, p_name, p_type) \
|
||||||
|
vmime::net::serviceRegisterer <vmime::net::p_class> \
|
||||||
|
p_name(#p_name, vmime::net::service::p_type)
|
||||||
|
|
||||||
|
|
||||||
|
#endif // VMIME_BUILDING_DOC
|
||||||
|
|
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
#include "vmime/net/session.hpp"
|
#include "vmime/net/session.hpp"
|
||||||
|
|
||||||
#include "vmime/net/serviceFactory.hpp"
|
|
||||||
#include "vmime/net/serviceInfos.hpp"
|
#include "vmime/net/serviceInfos.hpp"
|
||||||
|
|
||||||
#include "vmime/net/socket.hpp"
|
#include "vmime/net/socket.hpp"
|
||||||
@ -192,21 +191,6 @@ public:
|
|||||||
m_session->getProperties()[getInfos().getPropertyPrefix() + name] = value;
|
m_session->getProperties()[getInfos().getPropertyPrefix() + name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef VMIME_BUILDING_DOC
|
|
||||||
// Basic service registerer
|
|
||||||
template <class S>
|
|
||||||
class initializer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
initializer(const string& protocol, const Type type)
|
|
||||||
{
|
|
||||||
serviceFactory::getInstance()->
|
|
||||||
template registerServiceByProtocol <S>(protocol, type);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif // VMIME_BUILDING_DOC
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ref <session> m_session;
|
ref <session> m_session;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "vmime/utility/stringUtils.hpp"
|
#include "vmime/utility/stringUtils.hpp"
|
||||||
#include "vmime/utility/url.hpp"
|
#include "vmime/utility/url.hpp"
|
||||||
|
|
||||||
|
#include "vmime/net/service.hpp"
|
||||||
#include "vmime/net/serviceInfos.hpp"
|
#include "vmime/net/serviceInfos.hpp"
|
||||||
#include "vmime/net/timeoutHandler.hpp"
|
#include "vmime/net/timeoutHandler.hpp"
|
||||||
|
|
||||||
@ -46,7 +47,6 @@ namespace net {
|
|||||||
|
|
||||||
|
|
||||||
class session;
|
class session;
|
||||||
class service;
|
|
||||||
|
|
||||||
|
|
||||||
/** A factory to create 'service' objects for a specified protocol.
|
/** A factory to create 'service' objects for a specified protocol.
|
||||||
@ -83,67 +83,12 @@ public:
|
|||||||
virtual const serviceInfos& getInfos() const = 0;
|
virtual const serviceInfos& getInfos() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
template <class S>
|
|
||||||
class registeredServiceImpl : public registeredService
|
|
||||||
{
|
|
||||||
friend class serviceFactory;
|
|
||||||
friend class vmime::creator;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
registeredServiceImpl(const string& name, const int type)
|
|
||||||
: m_type(type), m_name(name), m_servInfos(S::getInfosInstance())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ref <service> create
|
|
||||||
(ref <session> sess,
|
|
||||||
ref <security::authenticator> auth) const
|
|
||||||
{
|
|
||||||
return vmime::create <S>(sess, auth);
|
|
||||||
}
|
|
||||||
|
|
||||||
const serviceInfos& getInfos() const
|
|
||||||
{
|
|
||||||
return (m_servInfos);
|
|
||||||
}
|
|
||||||
|
|
||||||
const string& getName() const
|
|
||||||
{
|
|
||||||
return (m_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
const int getType() const
|
|
||||||
{
|
|
||||||
return (m_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
const int m_type;
|
|
||||||
const string m_name;
|
|
||||||
const serviceInfos& m_servInfos;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector <ref <registeredService> > m_services;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/** Register a new service by its protocol name.
|
/** Register a new service by its protocol name.
|
||||||
*
|
*
|
||||||
* @param protocol protocol name
|
* @param reg service registration infos
|
||||||
* @param type service type
|
|
||||||
*/
|
*/
|
||||||
template <class S>
|
void registerService(ref <registeredService> reg);
|
||||||
void registerServiceByProtocol(const string& protocol, const int type)
|
|
||||||
{
|
|
||||||
const string name = utility::stringUtils::toLower(protocol);
|
|
||||||
m_services.push_back(vmime::create <registeredServiceImpl <S> >(name, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a new service instance from a protocol name.
|
/** Create a new service instance from a protocol name.
|
||||||
*
|
*
|
||||||
@ -201,6 +146,10 @@ public:
|
|||||||
* @return list of registered services
|
* @return list of registered services
|
||||||
*/
|
*/
|
||||||
const std::vector <ref <const registeredService> > getServiceList() const;
|
const std::vector <ref <const registeredService> > getServiceList() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector <ref <registeredService> > m_services;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||||
#include "vmime/net/socket.hpp"
|
#include "vmime/net/socket.hpp"
|
||||||
|
|
||||||
#include "vmime/net/service.hpp"
|
#include "vmime/net/serviceFactory.hpp"
|
||||||
#include "vmime/net/store.hpp"
|
#include "vmime/net/store.hpp"
|
||||||
#include "vmime/net/transport.hpp"
|
#include "vmime/net/transport.hpp"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user