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

pubsubmanager.h

00001 /*
00002   Copyright (c) 2007-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 #ifndef PUBSUBMANAGER_H__
00014 #define PUBSUBMANAGER_H__
00015 
00016 #include "pubsub.h"
00017 #include "iqhandler.h"
00018 
00019 #include <map>
00020 #include <string>
00021 
00022 namespace gloox
00023 {
00024 
00025   class ClientBase;
00026   class DataForm;
00027 
00028   namespace PubSub
00029   {
00030 
00031     class EventHandler;
00032     class ResultHandler;
00033 
00112     class GLOOX_API Manager : public IqHandler
00113     {
00114       public:
00115 
00120         Manager( ClientBase* parent );
00121 
00125         virtual ~Manager() {}
00126 
00139         void subscribe( const JID& service, const std::string& node,
00140                         ResultHandler* handler, const JID& jid = JID(),
00141                         SubscriptionObject type = SubscriptionNodes,
00142                         int depth = 1 );
00143 
00155         void unsubscribe( const JID& service,
00156                           const std::string& node,
00157                           ResultHandler* handler,
00158                           const JID& jid = JID() );
00159 
00168         void getSubscriptions( const JID& service, ResultHandler* handler );
00169 
00178         void getAffiliations( const JID& service, ResultHandler* handler );
00179 
00180 private:
00181         void subscriptionOptions( const JID& service,
00182                                   const JID& jid,
00183                                   const std::string& node,
00184                                   ResultHandler* handler,
00185                                   const DataForm* df );
00186 
00187 public:
00199         void getSubscriptionOptions( const JID& service,
00200                                      const JID& jid,
00201                                      const std::string& node,
00202                                      ResultHandler* handler)
00203           { subscriptionOptions( service, jid, node, handler, 0 ); }
00204 
00215         void setSubscriptionOptions( const JID& service,
00216                                      const JID& jid,
00217                                      const std::string& node,
00218                                      const DataForm& df,
00219                                      ResultHandler* handler )
00220           { subscriptionOptions( service, jid, node, handler, &df ); }
00221 
00231         void getAffiliations( const JID& service,
00232                               const std::string& node,
00233                               ResultHandler* handler );
00234 
00245         void publishItem( const JID& service,
00246                           const std::string& node,
00247                           Tag* item,
00248                           ResultHandler* handler );
00249 
00259         void deleteItem( const JID& service,
00260                          const std::string& node,
00261                          const std::string& item,
00262                          ResultHandler* handler );
00263 
00273         void getItems( const JID& service,
00274                        const std::string& node,
00275                        ResultHandler* handler );
00276 
00296         void createNode( NodeType type, const JID& service,
00297                                         const std::string& node,
00298                                         ResultHandler* handler,
00299                                         const std::string& name = EmptyString,
00300                                         const std::string& parent = EmptyString,
00301                                         AccessModel access = AccessDefault,
00302                                         const StringMap* config = 0 );
00303 
00322         void createLeafNode( const JID& service,
00323                              const std::string& node,
00324                              ResultHandler* handler,
00325                              const std::string& name,
00326                              const std::string& parent = EmptyString,
00327                              AccessModel access = AccessDefault,
00328                              const StringMap* config = 0 )
00329           { createNode( NodeLeaf, service, node, handler, name, parent, access, config ); }
00330 
00349         void createCollectionNode( const JID& service,
00350                                    const std::string& node,
00351                                    ResultHandler* handler,
00352                                    const std::string& name,
00353                                    const std::string& parent = EmptyString,
00354                                    AccessModel access = AccessDefault,
00355                                    const StringMap* config = 0 )
00356           { createNode( NodeCollection, service, node, handler, name, parent, access, config ); }
00357 
00366         void deleteNode( const JID& service,
00367                          const std::string& node,
00368                          ResultHandler* handler );
00369 
00370 /*
00371         void associateNode( const JID& service,
00372                             const std::string& node,
00373                             const std::string& collection );
00374 
00375         void disassociateNode( const JID& service,
00376                                const std::string& node,
00377                                const std::string& collection );
00378 */
00388         void getDefaultNodeConfig( const JID& service,
00389                                    NodeType type,
00390                                    ResultHandler* handler );
00391 
00401         void purgeNode( const JID& service,
00402                         const std::string& node,
00403                         ResultHandler* handler );
00404 
00414         void getSubscribers( const JID& service,
00415                              const std::string& node,
00416                              ResultHandler* handler )
00417           { subscriberList( service, node, 0, handler ); }
00418 
00429         void setSubscribers( const JID& service,
00430                              const std::string& node,
00431                              const SubscriberList& list,
00432                              ResultHandler* handler )
00433           { subscriberList( service, node, &list, handler ); }
00434 
00444         void getAffiliates( const JID& service,
00445                             const std::string& node,
00446                             ResultHandler* handler )
00447           { affiliateList( service, node, 0, handler ); }
00448 
00458         void setAffiliates( const JID& service,
00459                             const std::string& node,
00460                             const AffiliateList& list,
00461                             ResultHandler* handler )
00462           { affiliateList( service, node, &list, handler ); }
00463 
00473         void getNodeConfig( const JID& service,
00474                             const std::string& node,
00475                             ResultHandler* handler )
00476           { nodeConfig( service, node, 0, handler ); }
00477 
00487         void setNodeConfig( const JID& service,
00488                             const std::string& node,
00489                             const DataForm& config,
00490                             ResultHandler* handler  )
00491           { nodeConfig( service, node, &config, handler ); }
00492 
00498         void registerEventHandler( EventHandler* handler )
00499           { m_eventHandlerList.push_back( handler ); }
00500 
00505         void removeEventHandler( EventHandler* handler )
00506           { m_eventHandlerList.remove( handler ); }
00507 
00508         // reimplemented from DiscoHandler
00509         void handleDiscoInfoResult( IQ* iq, int context );
00510         void handleDiscoItemsResult( IQ* iq, int context );
00511         void handleDiscoError( IQ* iq, int context );
00512         bool handleDiscoSet( IQ* ) { return 0; }
00513 
00514         // reimplemented from IqHandler.
00515         virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
00516 
00517         // reimplemented from IqHandler.
00518         virtual void handleIqID( const IQ& iq, int context );
00519 
00520       private:
00521 
00533         void nodeConfig( const JID& service, const std::string& node,
00534                          const DataForm* config, ResultHandler* handler );
00535 
00547         void subscriberList( const JID& service,
00548                              const std::string& node,
00549                              const SubscriberList* config,
00550                              ResultHandler* handler );
00551 
00563         void affiliateList( const JID& service,
00564                             const std::string& node,
00565                             const AffiliateList* config,
00566                             ResultHandler* handler );
00567 
00568         typedef std::pair< std::string, std::string > TrackedItem;
00569         typedef std::map < std::string, TrackedItem > ItemOperationTrackMap;
00570         typedef std::map < std::string, std::string > NodeOperationTrackMap;
00571 
00572         typedef std::map < std::string, ResultHandler* > ResultHandlerTrackMap;
00573         typedef std::list< EventHandler* > EventHandlerList;
00574 
00575         ClientBase* m_parent;
00576 
00577         ItemOperationTrackMap  m_iopTrackMap;
00578         NodeOperationTrackMap  m_nopTrackMap;
00579 
00580         ResultHandlerTrackMap  m_resultHandlerTrackMap;
00581         EventHandlerList       m_eventHandlerList;
00582     };
00583 
00584   }
00585 
00586 }
00587 
00588 #endif // PUBSUBMANAGER_H__

Generated on Mon Oct 13 10:45:12 2008 for gloox by  doxygen 1.4.1