2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_
12 #define WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_
14 #include "webrtc/libjingle/xmpp/module.h"
15 #include "webrtc/libjingle/xmpp/xmppengine.h"
19 //! This is the base implementation class for extension modules.
20 //! An engine is registered with the module and the module then hooks the
21 //! appropriate parts of the engine to implement that set of features. It is
22 //! important to unregister modules before destructing the engine.
23 class XmppModuleImpl {
26 virtual ~XmppModuleImpl();
28 //! Register the engine with the module. Only one engine can be associated
29 //! with a module at a time. This method will return an error if there is
30 //! already an engine registered.
31 XmppReturnStatus RegisterEngine(XmppEngine* engine);
33 //! Gets the engine that this module is attached to.
36 //! Process the given stanza.
37 //! The module must return true if it has handled the stanza.
38 //! A false return value causes the stanza to be passed on to
39 //! the next registered handler.
40 virtual bool HandleStanza(const XmlElement *) { return false; };
44 //! The ModuleSessionHelper nested class allows the Module
45 //! to hook into and get stanzas and events from the engine.
46 class ModuleStanzaHandler : public XmppStanzaHandler {
47 friend class XmppModuleImpl;
49 ModuleStanzaHandler(XmppModuleImpl* module) :
53 bool HandleStanza(const XmlElement* stanza) {
54 return module_->HandleStanza(stanza);
57 XmppModuleImpl* module_;
60 friend class ModuleStanzaHandler;
63 ModuleStanzaHandler stanza_handler_;
67 // This macro will implement the XmppModule interface for a class
68 // that derives from both XmppModuleImpl and XmppModule
69 #define IMPLEMENT_XMPPMODULE \
70 XmppReturnStatus RegisterEngine(XmppEngine* engine) { \
71 return XmppModuleImpl::RegisterEngine(engine); \
76 #endif // WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_