OLD | NEW |
(Empty) | |
| 1 // Copyright 2004 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_ |
| 6 #define WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_ |
| 7 |
| 8 #include "third_party/xmpp/module.h" |
| 9 #include "third_party/xmpp/xmppengine.h" |
| 10 |
| 11 namespace buzz { |
| 12 |
| 13 //! This is the base implementation class for extension modules. |
| 14 //! An engine is registered with the module and the module then hooks the |
| 15 //! appropriate parts of the engine to implement that set of features. It is |
| 16 //! important to unregister modules before destructing the engine. |
| 17 class XmppModuleImpl { |
| 18 protected: |
| 19 XmppModuleImpl(); |
| 20 virtual ~XmppModuleImpl(); |
| 21 |
| 22 //! Register the engine with the module. Only one engine can be associated |
| 23 //! with a module at a time. This method will return an error if there is |
| 24 //! already an engine registered. |
| 25 XmppReturnStatus RegisterEngine(XmppEngine* engine); |
| 26 |
| 27 //! Gets the engine that this module is attached to. |
| 28 XmppEngine* engine(); |
| 29 |
| 30 //! Process the given stanza. |
| 31 //! The module must return true if it has handled the stanza. |
| 32 //! A false return value causes the stanza to be passed on to |
| 33 //! the next registered handler. |
| 34 virtual bool HandleStanza(const XmlElement *) { return false; }; |
| 35 |
| 36 private: |
| 37 |
| 38 //! The ModuleSessionHelper nested class allows the Module |
| 39 //! to hook into and get stanzas and events from the engine. |
| 40 class ModuleStanzaHandler : public XmppStanzaHandler { |
| 41 friend class XmppModuleImpl; |
| 42 |
| 43 ModuleStanzaHandler(XmppModuleImpl* module) : |
| 44 module_(module) { |
| 45 } |
| 46 |
| 47 bool HandleStanza(const XmlElement* stanza) { |
| 48 return module_->HandleStanza(stanza); |
| 49 } |
| 50 |
| 51 XmppModuleImpl* module_; |
| 52 }; |
| 53 |
| 54 friend class ModuleStanzaHandler; |
| 55 |
| 56 XmppEngine* engine_; |
| 57 ModuleStanzaHandler stanza_handler_; |
| 58 }; |
| 59 |
| 60 |
| 61 // This macro will implement the XmppModule interface for a class |
| 62 // that derives from both XmppModuleImpl and XmppModule |
| 63 #define IMPLEMENT_XMPPMODULE \ |
| 64 XmppReturnStatus RegisterEngine(XmppEngine* engine) { \ |
| 65 return XmppModuleImpl::RegisterEngine(engine); \ |
| 66 } |
| 67 |
| 68 } |
| 69 |
| 70 #endif // WEBRTC_LIBJINGLE_XMPP_MODULEIMPL_H_ |
OLD | NEW |