serviceRegistration.inl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // VMime library (http://www.vmime.org)
  3. // Copyright (C) 2002-2008 Vincent Richard <vincent@vincent-richard.net>
  4. //
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License as
  7. // published by the Free Software Foundation; either version 2 of
  8. // the License, or (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License along
  16. // with this program; if not, write to the Free Software Foundation, Inc.,
  17. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. //
  19. // Linking this library statically or dynamically with other modules is making
  20. // a combined work based on this library. Thus, the terms and conditions of
  21. // the GNU General Public License cover the whole combination.
  22. //
  23. #include <memory>
  24. #include <vmime/net/serviceFactory.hpp>
  25. #ifndef VMIME_BUILDING_DOC
  26. namespace vmime {
  27. namespace net {
  28. template <class S>
  29. class registeredServiceImpl : public serviceFactory::registeredService {
  30. public:
  31. registeredServiceImpl(const string& name, const int type)
  32. : m_type(type), m_name(name), m_servInfos(S::getInfosInstance())
  33. {
  34. }
  35. vmime::shared_ptr<service> create(vmime::shared_ptr<session> sess,
  36. vmime::shared_ptr<security::authenticator> auth) const
  37. {
  38. return vmime::make_shared<S>(sess, auth);
  39. }
  40. const serviceInfos& getInfos() const
  41. {
  42. return (m_servInfos);
  43. }
  44. const string& getName() const
  45. {
  46. return (m_name);
  47. }
  48. int getType() const
  49. {
  50. return (m_type);
  51. }
  52. private:
  53. const int m_type;
  54. const string m_name;
  55. const serviceInfos& m_servInfos;
  56. };
  57. // Basic service registerer
  58. template<class S> class serviceRegisterer {
  59. public:
  60. serviceRegisterer(const string& protocol, const service::Type type)
  61. {
  62. serviceFactory::getInstance()->registerService
  63. (vmime::make_shared<net::registeredServiceImpl<S> >(protocol, type));
  64. }
  65. };
  66. } // net
  67. } // vmime
  68. #define REGISTER_SERVICE(p_class, p_name, p_type) \
  69. vmime::net::serviceRegisterer <vmime::net::p_class> \
  70. p_name(#p_name, vmime::net::service::p_type)
  71. #endif // VMIME_BUILDING_DOC