Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

disco.h

00001 /*
00002   Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 
00015 #ifndef DISCO_H__
00016 #define DISCO_H__
00017 
00018 #include "gloox.h"
00019 
00020 #include "iqhandler.h"
00021 #include "jid.h"
00022 
00023 #include <string>
00024 #include <list>
00025 #include <map>
00026 
00027 namespace gloox
00028 {
00029 
00030   class ClientBase;
00031   class DataForm;
00032   class DiscoHandler;
00033   class DiscoNodeHandler;
00034   class IQ;
00035 
00045   class GLOOX_API Disco : public IqHandler
00046   {
00047     friend class ClientBase;
00048 
00049     public:
00050 
00051       class Identity; // declared below class Info
00052 
00056       typedef std::list<Identity*> IdentityList;
00057 
00065       class GLOOX_API Info : public StanzaExtension
00066       {
00067         friend class Disco;
00068 
00069         public:
00074           const std::string& node() const { return m_node; }
00075 
00080           const StringList& features() const { return m_features; }
00081 
00087           bool hasFeature( const std::string& feature ) const;
00088 
00093           const IdentityList& identities() const { return m_identities; }
00094 
00099           const DataForm* form() const { return m_form; }
00100 
00101           // reimplemented from StanzaExtension
00102           virtual const std::string& filterString() const;
00103 
00104           // reimplemented from StanzaExtension
00105           virtual StanzaExtension* newInstance( const Tag* tag ) const
00106           {
00107             return new Info( tag );
00108           }
00109 
00110           // reimplemented from StanzaExtension
00111           virtual Tag* tag() const;
00112 
00113         private:
00114 #ifdef DISCO_INFO_TEST
00115         public:
00116 #endif
00117 
00124           Info( const std::string& node = EmptyString, bool defaultFeatures = false );
00125 
00131           Info( const Tag* tag );
00132 
00136           virtual ~Info();
00137 
00142           void setNode( const std::string& node ) { m_node = node; }
00143 
00148           void setFeatures( const StringList& features )
00149             { StringList fl( features ); m_features.merge( fl ); } // FIXME is this really necessary?
00150 
00157           void setIdentities( const IdentityList& identities ) { m_identities = identities; }
00158 
00159           std::string m_node;
00160           StringList m_features;
00161           IdentityList m_identities;
00162           DataForm* m_form;
00163       };
00164 
00171       class GLOOX_API Identity
00172       {
00173         friend class Info;
00174         friend class Disco;
00175 
00176         public:
00184           Identity( const std::string& category,
00185                     const std::string& type,
00186                     const std::string& name );
00187 
00192           Identity( const Identity& id );
00193 
00197           ~Identity();
00198 
00203           const std::string& category() const { return m_category; }
00204 
00209           const std::string& type() const { return m_type; }
00210 
00215           const std::string& name() const { return m_name; }
00216 
00221           Tag* tag() const;
00222 
00223         private:
00228           Identity( const Tag* tag );
00229 
00230           std::string m_category;   
00231           std::string m_type;       
00232           std::string m_name;       
00234       };
00235 
00236       class Item; // declared below class Items
00237 
00241       typedef std::list<Item*> ItemList;
00242 
00250       class GLOOX_API Items : public StanzaExtension
00251       {
00252         friend class Disco;
00253 
00254         public:
00255           // This needs to be public so one can proactively send a list of adhoc commands
00256           // see XEP-0050
00261           Items( const std::string& node = EmptyString );
00262 
00266           virtual ~Items();
00267 
00274           void setItems( const ItemList& items ) { m_items = items; }
00275 
00280           const std::string& node() const { return m_node; }
00281 
00286           const ItemList& items() const { return m_items; }
00287 
00288           // reimplemented from StanzaExtension
00289           virtual const std::string& filterString() const;
00290 
00291           // reimplemented from StanzaExtension
00292           virtual StanzaExtension* newInstance( const Tag* tag ) const
00293           {
00294             return new Items( tag );
00295           }
00296 
00297           // reimplemented from StanzaExtension
00298           virtual Tag* tag() const;
00299 
00300         private:
00301 #ifdef DISCO_ITEMS_TEST
00302         public:
00303 #endif
00304 
00309           Items( const Tag* tag );
00310 
00311           std::string m_node;
00312           ItemList m_items;
00313       };
00314 
00321       class GLOOX_API Item
00322       {
00323         friend class Items;
00324 
00325         public:
00332           Item( const JID& jid,
00333                 const std::string& node,
00334                 const std::string& name )
00335           : m_jid( jid ), m_node( node ), m_name( name ) {}
00336 
00340           ~Item() {}
00341 
00346           const JID& jid() const { return m_jid; }
00347 
00352           const std::string& node() const { return m_node; }
00353 
00358           const std::string& name() const { return m_name; }
00359 
00364           Tag* tag() const;
00365 
00366         private:
00371           Item( const Tag* tag );
00372 
00373           JID m_jid;                
00374           std::string m_node;       
00375           std::string m_name;       
00377       };
00378 
00391       void addFeature( const std::string& feature )
00392         { m_features.push_back( feature ); }
00393 
00399       void removeFeature( const std::string& feature )
00400         { m_features.remove( feature ); }
00401 
00406       const StringList& features() const { return m_features; }
00407 
00419       void getDiscoInfo( const JID& to, const std::string& node, DiscoHandler* dh, int context,
00420                          const std::string& tid = EmptyString )
00421         { getDisco( to, node, dh, context, GetDiscoInfo, tid ); }
00422 
00434       void getDiscoItems( const JID& to, const std::string& node, DiscoHandler* dh, int context,
00435                           const std::string& tid = EmptyString )
00436         { getDisco( to, node, dh, context, GetDiscoItems, tid ); }
00437 
00446       void setVersion( const std::string& name, const std::string& version,
00447                        const std::string& os = EmptyString );
00448 
00453       const std::string& name() const { return m_versionName; }
00454 
00459       const std::string& version() const { return m_versionVersion; }
00460 
00465       const std::string& os() const { return m_versionOs; }
00466 
00480       void setIdentity( const std::string& category, const std::string& type,
00481                         const std::string& name = EmptyString );
00482 
00489       void addIdentity( const std::string& category, const std::string& type,
00490                         const std::string& name = EmptyString )
00491         { m_identities.push_back( new Identity( category, type, name ) ); }
00492 
00497       const IdentityList& identities() const { return m_identities; }
00498 
00505       void registerDiscoHandler( DiscoHandler* dh )
00506         { m_discoHandlers.push_back( dh ); }
00507 
00512       void removeDiscoHandler( DiscoHandler* dh )
00513         { m_discoHandlers.remove( dh ); }
00514 
00523       void registerNodeHandler( DiscoNodeHandler* nh, const std::string& node );
00524 
00531       void removeNodeHandler( DiscoNodeHandler* nh, const std::string& node );
00532 
00537       void removeNodeHandlers( DiscoNodeHandler* nh );
00538 
00539       // reimplemented from IqHandler.
00540       virtual bool handleIq( const IQ& iq );
00541 
00542       // reimplemented from IqHandler.
00543       virtual void handleIqID( const IQ& iq, int context );
00544 
00545     private:
00546 #ifdef DISCO_TEST
00547     public:
00548 #endif
00549 
00555       class SoftwareVersion : public StanzaExtension
00556       {
00557 
00558         public:
00563           SoftwareVersion( const std::string& name, const std::string& version, const std::string& os );
00564 
00569           SoftwareVersion( const Tag* tag = 0 );
00570 
00575           const std::string& name() const { return m_name; }
00576 
00581           const std::string& version() const { return m_version; }
00582 
00587           const std::string& os() const { return m_os; }
00588 
00592           virtual ~SoftwareVersion();
00593 
00594           // reimplemented from StanzaExtension
00595           virtual const std::string& filterString() const;
00596 
00597           // reimplemented from StanzaExtension
00598           virtual StanzaExtension* newInstance( const Tag* tag ) const
00599           {
00600             return new SoftwareVersion( tag );
00601           }
00602 
00603           // reimplemented from StanzaExtension
00604           virtual Tag* tag() const;
00605 
00606         private:
00607           std::string m_name;
00608           std::string m_version;
00609           std::string m_os;
00610       };
00611 
00612       Disco( ClientBase* parent );
00613       virtual ~Disco();
00614 
00615       enum IdType
00616       {
00617         GetDiscoInfo,
00618         GetDiscoItems
00619       };
00620 
00621       void getDisco( const JID& to, const std::string& node, DiscoHandler* dh,
00622                      int context, IdType idType, const std::string& tid );
00623 
00624       struct DiscoHandlerContext
00625       {
00626         DiscoHandler* dh;
00627         int context;
00628       };
00629 
00630       ClientBase* m_parent;
00631 
00632       typedef std::list<DiscoHandler*> DiscoHandlerList;
00633       typedef std::list<DiscoNodeHandler*> DiscoNodeHandlerList;
00634       typedef std::map<std::string, DiscoNodeHandlerList> DiscoNodeHandlerMap;
00635       typedef std::map<std::string, DiscoHandlerContext> DiscoHandlerMap;
00636 
00637       DiscoHandlerList m_discoHandlers;
00638       DiscoNodeHandlerMap m_nodeHandlers;
00639       DiscoHandlerMap m_track;
00640       IdentityList m_identities;
00641       StringList m_features;
00642       StringMap  m_queryIDs;
00643 
00644       std::string m_versionName;
00645       std::string m_versionVersion;
00646       std::string m_versionOs;
00647 
00648   };
00649 
00650 }
00651 
00652 #endif // DISCO_H__

Generated on Mon Sep 1 09:25:10 2008 for gloox by  doxygen 1.4.1