diff --git a/SConstruct b/SConstruct index 8dcb53da..62e040cd 100644 --- a/SConstruct +++ b/SConstruct @@ -207,6 +207,7 @@ libvmime_messaging_sources = [ 'net/service.cpp', 'net/service.hpp', 'net/serviceFactory.cpp', 'net/serviceFactory.hpp', 'net/serviceInfos.cpp', 'net/serviceInfos.hpp', + 'net/serviceRegistration.inl', 'net/session.cpp', 'net/session.hpp', 'net/socket.hpp', 'net/store.hpp', diff --git a/src/net/builtinServices.inl b/src/net/builtinServices.inl index 803371ac..d8d4ea91 100644 --- a/src/net/builtinServices.inl +++ b/src/net/builtinServices.inl @@ -21,14 +21,14 @@ // the GNU General Public License cover the whole combination. // + +// Include registration helpers +#include "src/net/serviceRegistration.inl" + + #ifndef VMIME_BUILDING_DOC -#define REGISTER_SERVICE(p_class, p_name, p_type) \ - vmime::net::service::initializer \ - p_name(#p_name, vmime::net::service::p_type) - - #if VMIME_BUILTIN_MESSAGING_PROTO_POP3 #include "vmime/net/pop3/POP3Store.hpp" REGISTER_SERVICE(pop3::POP3Store, pop3, TYPE_STORE); diff --git a/src/net/serviceFactory.cpp b/src/net/serviceFactory.cpp index 222f3da2..e98e0e4c 100644 --- a/src/net/serviceFactory.cpp +++ b/src/net/serviceFactory.cpp @@ -122,5 +122,11 @@ const std::vector > serviceFactor } +void serviceFactory::registerService(ref reg) +{ + m_services.push_back(reg); +} + + } // net } // vmime diff --git a/src/net/serviceRegistration.inl b/src/net/serviceRegistration.inl new file mode 100644 index 00000000..104e4d72 --- /dev/null +++ b/src/net/serviceRegistration.inl @@ -0,0 +1,98 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2005 Vincent Richard +// +// 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 registeredServiceImpl : public serviceFactory::registeredService +{ +public: + + registeredServiceImpl(const string& name, const int type) + : m_type(type), m_name(name), m_servInfos(S::getInfosInstance()) + { + } + + ref create + (ref sess, + ref auth) const + { + return vmime::create (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 serviceRegisterer +{ +public: + + serviceRegisterer(const string& protocol, const service::Type type) + { + serviceFactory::getInstance()->registerService + (vmime::create >(protocol, type)); + } +}; + + +} // net +} // vmime + + +#define REGISTER_SERVICE(p_class, p_name, p_type) \ + vmime::net::serviceRegisterer \ + p_name(#p_name, vmime::net::service::p_type) + + +#endif // VMIME_BUILDING_DOC + diff --git a/vmime/net/service.hpp b/vmime/net/service.hpp index 6f071e89..c96a8c4b 100644 --- a/vmime/net/service.hpp +++ b/vmime/net/service.hpp @@ -30,7 +30,6 @@ #include "vmime/net/session.hpp" -#include "vmime/net/serviceFactory.hpp" #include "vmime/net/serviceInfos.hpp" #include "vmime/net/socket.hpp" @@ -192,21 +191,6 @@ public: m_session->getProperties()[getInfos().getPropertyPrefix() + name] = value; } -#ifndef VMIME_BUILDING_DOC - // Basic service registerer - template - class initializer - { - public: - - initializer(const string& protocol, const Type type) - { - serviceFactory::getInstance()-> - template registerServiceByProtocol (protocol, type); - } - }; -#endif // VMIME_BUILDING_DOC - private: ref m_session; diff --git a/vmime/net/serviceFactory.hpp b/vmime/net/serviceFactory.hpp index ec5f03ad..70dbd933 100644 --- a/vmime/net/serviceFactory.hpp +++ b/vmime/net/serviceFactory.hpp @@ -33,6 +33,7 @@ #include "vmime/utility/stringUtils.hpp" #include "vmime/utility/url.hpp" +#include "vmime/net/service.hpp" #include "vmime/net/serviceInfos.hpp" #include "vmime/net/timeoutHandler.hpp" @@ -46,7 +47,6 @@ namespace net { class session; -class service; /** A factory to create 'service' objects for a specified protocol. @@ -83,67 +83,12 @@ public: virtual const serviceInfos& getInfos() const = 0; }; -private: - - template - 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 create - (ref sess, - ref auth) const - { - return vmime::create (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 > m_services; - -public: /** Register a new service by its protocol name. * - * @param protocol protocol name - * @param type service type + * @param reg service registration infos */ - template - void registerServiceByProtocol(const string& protocol, const int type) - { - const string name = utility::stringUtils::toLower(protocol); - m_services.push_back(vmime::create >(name, type)); - } + void registerService(ref reg); /** Create a new service instance from a protocol name. * @@ -201,6 +146,10 @@ public: * @return list of registered services */ const std::vector > getServiceList() const; + +private: + + std::vector > m_services; }; diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp index 8e6f3dd3..c878ae60 100644 --- a/vmime/vmime.hpp +++ b/vmime/vmime.hpp @@ -111,7 +111,7 @@ #if VMIME_HAVE_MESSAGING_FEATURES #include "vmime/net/socket.hpp" - #include "vmime/net/service.hpp" + #include "vmime/net/serviceFactory.hpp" #include "vmime/net/store.hpp" #include "vmime/net/transport.hpp"