gloox  1.0.28
jingleplugin.h
1 /*
2  Copyright (c) 2008-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef JINGLEPLUGIN_H__
15 #define JINGLEPLUGIN_H__
16 
17 #include "macros.h"
18 #include "util.h"
19 
20 #include <string>
21 #include <list>
22 
23 namespace gloox
24 {
25 
26  class Tag;
27 
28  namespace Jingle
29  {
30 
31  class Plugin;
32  class PluginFactory;
33 
38  {
44  PluginUser
47  };
48 
52  typedef std::list<const Plugin*> PluginList;
53 
67  class GLOOX_API Plugin
68  {
69 
70  friend class PluginFactory;
71 
72  public:
76  Plugin( JinglePluginType type ) : m_factory( 0 ), m_pluginType( type ) {}
77 
81  virtual ~Plugin() { util::clearList( m_plugins ) ; }
82 
87  void addPlugin( const Plugin* plugin ) { if( plugin ) m_plugins.push_back( plugin ); }
88 
94  const Plugin* findPlugin( int type ) const
95  {
96  PluginList::const_iterator it = m_plugins.begin();
97  for( ; it != m_plugins.end() && (*it)->pluginType() != type; ++it ) ;
98  return it != m_plugins.end() ? (*it) : 0;
99  }
100 
110  template< class T >
111  inline const T* findPlugin( int type ) const
112  {
113  return static_cast<const T*>( findPlugin( type ) );
114  }
115 
120  const PluginList& plugins() const { return m_plugins; }
121 
127  virtual const StringList features() const { return StringList(); }
128 
136  virtual const std::string& filterString() const = 0;
137 
142  virtual Tag* tag() const = 0;
143 
150  virtual Plugin* newInstance( const Tag* tag ) const = 0;
151 
156  virtual Plugin* clone() const = 0;
157 
162  JinglePluginType pluginType() const { return m_pluginType; }
163 
164  protected:
165  PluginList m_plugins;
166  PluginFactory* m_factory;
167 
168  private:
169  void setFactory( PluginFactory* factory ) { m_factory = factory; }
170 
171  JinglePluginType m_pluginType;
172 
173  };
174 
175  }
176 
177 }
178 
179 #endif // JINGLEPLUGIN_H__
A factory for which creates Plugin instances based on Tags. This is part of Jingle (XEP-0166).
An abstraction of a Jingle plugin. This is part of Jingle (XEP-0166 et al.)
Definition: jingleplugin.h:68
virtual const StringList features() const
Definition: jingleplugin.h:127
JinglePluginType pluginType() const
Definition: jingleplugin.h:162
virtual const std::string & filterString() const =0
virtual Tag * tag() const =0
virtual Plugin * newInstance(const Tag *tag) const =0
Plugin(JinglePluginType type)
Definition: jingleplugin.h:76
const Plugin * findPlugin(int type) const
Definition: jingleplugin.h:94
void addPlugin(const Plugin *plugin)
Definition: jingleplugin.h:87
const T * findPlugin(int type) const
Definition: jingleplugin.h:111
const PluginList & plugins() const
Definition: jingleplugin.h:120
virtual Plugin * clone() const =0
This is an abstraction of an XML element.
Definition: tag.h:47
std::list< const Plugin * > PluginList
Definition: jingleplugin.h:52
void clearList(std::list< T * > &L)
Definition: util.h:152
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< std::string > StringList
Definition: gloox.h:1251