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

adhoc.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 ADHOC_H__
00016 #define ADHOC_H__
00017 
00018 #include "disco.h"
00019 #include "disconodehandler.h"
00020 #include "discohandler.h"
00021 #include "iqhandler.h"
00022 #include "stanzaextension.h"
00023 
00024 #include <string>
00025 #include <list>
00026 #include <map>
00027 
00028 namespace gloox
00029 {
00030 
00031   class ClientBase;
00032   class Stanza;
00033   class AdhocHandler;
00034   class AdhocCommandProvider;
00035   class DataForm;
00036 
00080   class GLOOX_API Adhoc : public DiscoNodeHandler, public DiscoHandler, public IqHandler
00081   {
00082     public:
00090       class GLOOX_API Command : public StanzaExtension
00091       {
00092         friend class Adhoc;
00093 
00094         public:
00095 
00099           enum Action
00100           {
00101             Execute       =  1,     
00103             Cancel        =  2,     
00104             Previous      =  4,     
00106             Next          =  8,     
00108             Complete      = 16,     
00109             InvalidAction = 32      
00110           };
00111 
00115           enum Status
00116           {
00117             Executing,              
00118             Completed,              
00119             Canceled,               
00120             InvalidStatus           
00121           };
00122 
00129           class GLOOX_API Note
00130           {
00131 
00132             friend class Command;
00133 
00134             public:
00138               enum Severity
00139               {
00140                 Info,               
00142                 Warning,            
00144                 Error,              
00146                 InvalidSeverity     
00147               };
00148 
00154               Note( Severity sev, const std::string& note )
00155                 : m_severity( sev ), m_note( note ) {}
00156 
00160               ~Note() {}
00161 
00166               Severity severity() const { return m_severity; }
00167 
00172               const std::string& content() const { return m_note; }
00173 
00178               Tag* tag() const;
00179 
00180             private:
00181 #ifdef ADHOC_COMMANDS_TEST
00182             public:
00183 #endif
00184 
00188               Note( const Tag* tag );
00189 
00190               Severity m_severity;      
00191               std::string m_note;       
00192           };
00193 
00197           typedef std::list<const Note*> NoteList;
00198 
00207           Command( const std::string& node, const std::string& sessionid, Action action );
00208 
00218           Command( const std::string& node, const std::string& sessionid, Status status,
00219                    DataForm* form = 0 );
00220 
00228           Command( const std::string& node, Action action );
00229 
00234           const std::string& node() const { return m_node; }
00235 
00240           const std::string& sessionID() const { return m_sessionid; }
00241 
00247           Status status() const { return m_status; }
00248 
00253           Action action() const { return m_action; }
00254 
00260           int actions() const { return m_actions; }
00261 
00266           const NoteList& notes() const { return m_notes; }
00267 
00273           void addNote( const Note* note ) { m_notes.push_back( note ); }
00274 
00279           const DataForm* form() const { return m_form; }
00280 
00281           // reimplemented from StanzaExtension
00282           virtual const std::string& filterString() const;
00283 
00284           // reimplemented from StanzaExtension
00285           virtual StanzaExtension* newInstance( const Tag* tag ) const
00286           {
00287             return new Command( tag );
00288           }
00289 
00290           // reimplemented from StanzaExtension
00291           virtual Tag* tag() const;
00292 
00293         private:
00294 #ifdef ADHOC_COMMANDS_TEST
00295         public:
00296 #endif
00297 
00301           Command( const Tag* tag = 0 );
00302 
00306           virtual ~Command();
00307 
00308           NoteList m_notes;
00309 
00310           std::string m_node;
00311           std::string m_sessionid;
00312           DataForm* m_form;
00313           Action m_action;
00314           Status m_status;
00315           int m_actions;
00316       };
00317 
00323       Adhoc( ClientBase* parent );
00324 
00328       virtual ~Adhoc();
00329 
00335       void checkSupport( const JID& remote, AdhocHandler* ah );
00336 
00343       void getCommands( const JID& remote, AdhocHandler* ah );
00344 
00355       void execute( const JID& remote, const Adhoc::Command* command, AdhocHandler* ah );
00356 
00369       void respond( const JID& remote, const Adhoc::Command* command, const Error* error = 0 );
00370 
00378       void registerAdhocCommandProvider( AdhocCommandProvider* acp, const std::string& command,
00379                                          const std::string& name );
00380 
00386       void removeAdhocCommandProvider( const std::string& command );
00387 
00388       // reimplemented from DiscoNodeHandler
00389       virtual StringList handleDiscoNodeFeatures( const JID& from, const std::string& node );
00390 
00391       // reimplemented from DiscoNodeHandler
00392       virtual Disco::IdentityList handleDiscoNodeIdentities( const JID& from,
00393           const std::string& node );
00394 
00395       // reimplemented from DiscoNodeHandler
00396       virtual Disco::ItemList handleDiscoNodeItems( const JID& from, const std::string& node );
00397 
00398       // reimplemented from IqHandler
00399       virtual bool handleIq( const IQ& iq );
00400 
00401       // reimplemented from IqHandler
00402       virtual void handleIqID( const IQ& iq, int context );
00403 
00404       // reimplemented from DiscoHandler
00405       virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
00406 
00407       // reimplemented from DiscoHandler
00408       virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
00409 
00410       // reimplemented from DiscoHandler
00411       virtual void handleDiscoError( const JID& from, const Error* error, int context );
00412 
00413     private:
00414 #ifdef ADHOC_TEST
00415     public:
00416 #endif
00417       typedef std::map<const std::string, AdhocCommandProvider*> AdhocCommandProviderMap;
00418       AdhocCommandProviderMap m_adhocCommandProviders;
00419 
00420       enum AdhocContext
00421       {
00422         CheckAdhocSupport,
00423         FetchAdhocCommands,
00424         ExecuteAdhocCommand
00425       };
00426 
00427       struct TrackStruct
00428       {
00429         JID remote;
00430         AdhocContext context;
00431         std::string session;
00432         AdhocHandler* ah;
00433       };
00434       typedef std::map<std::string, TrackStruct> AdhocTrackMap;
00435       AdhocTrackMap m_adhocTrackMap;
00436 
00437       ClientBase* m_parent;
00438 
00439       StringMap m_items;
00440       StringMap m_activeSessions;
00441 
00442   };
00443 
00444 }
00445 
00446 #endif // ADHOC_H__

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