aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SConstruct1
-rw-r--r--src/net/builtinServices.inl8
-rw-r--r--src/net/serviceFactory.cpp6
-rw-r--r--src/net/serviceRegistration.inl98
-rw-r--r--vmime/net/service.hpp16
-rw-r--r--vmime/net/serviceFactory.hpp65
-rw-r--r--vmime/vmime.hpp2
7 files changed, 117 insertions, 79 deletions
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,12 +21,12 @@
// the GNU General Public License cover the whole combination.
//
-#ifndef VMIME_BUILDING_DOC
+
+// Include registration helpers
+#include "src/net/serviceRegistration.inl"
-#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)
+#ifndef VMIME_BUILDING_DOC
#if VMIME_BUILTIN_MESSAGING_PROTO_POP3
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 <ref <const serviceFactory::registeredService> > serviceFactor
}
+void serviceFactory::registerService(ref <registeredService> 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 <[email protected]>
+//
+// 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
+
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 S>
- class initializer
- {
- public:
-
- initializer(const string& protocol, const Type type)
- {
- serviceFactory::getInstance()->
- template registerServiceByProtocol <S>(protocol, type);
- }
- };
-#endif // VMIME_BUILDING_DOC
-
private:
ref <session> 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 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.
*
- * @param protocol protocol name
- * @param type service type
+ * @param reg service registration infos
*/
- template <class S>
- 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));
- }
+ void registerService(ref <registeredService> reg);
/** Create a new service instance from a protocol name.
*
@@ -201,6 +146,10 @@ public:
* @return list of registered services
*/
const std::vector <ref <const registeredService> > getServiceList() const;
+
+private:
+
+ std::vector <ref <registeredService> > 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"