gloox  0.9.9.12
adhoc.h
1 /*
2  Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef ADHOC_H__
16 #define ADHOC_H__
17 
18 #include "disconodehandler.h"
19 #include "discohandler.h"
20 #include "iqhandler.h"
21 
22 #include <string>
23 #include <list>
24 #include <map>
25 
26 namespace gloox
27 {
28 
29  class DataForm;
30  class ClientBase;
31  class Stanza;
32  class AdhocHandler;
33  class AdhocCommandProvider;
34 
78  class GLOOX_API Adhoc : public DiscoNodeHandler, public DiscoHandler, public IqHandler
79  {
80  public:
85  {
89  AdhocCommandStatusUnknown
90  };
91 
96  {
97  ActionDefault = 0,
98  ActionPrevious = 1,
99  ActionNext = 2,
100  ActionComplete = 4,
101  ActionCancel = 8
102  };
103 
108  {
109  AdhocNoteInfo,
111  AdhocNoteWarn,
113  AdhocNoteError
115  };
116 
122  Adhoc( ClientBase *parent );
123 
127  virtual ~Adhoc();
128 
129  // reimplemented from DiscoNodeHandler
130  virtual StringList handleDiscoNodeFeatures( const std::string& node );
131 
132  // reimplemented from DiscoNodeHandler
133  virtual StringMap handleDiscoNodeIdentities( const std::string& node, std::string& name );
134 
135  // reimplemented from DiscoNodeHandler
136  virtual DiscoNodeItemList handleDiscoNodeItems( const std::string& node );
137 
138  // reimplemented from IqHandler
139  virtual bool handleIq( Stanza *stanza );
140 
141  // reimplemented from IqHandler
142  virtual bool handleIqID( Stanza *stanza, int context );
143 
144  // reimplemented from DiscoHandler
145  virtual void handleDiscoInfoResult( Stanza *stanza, int context );
146 
147  // reimplemented from DiscoHandler
148  virtual void handleDiscoItemsResult( Stanza *stanza, int context );
149 
150  // reimplemented from DiscoHandler
151  virtual void handleDiscoError( Stanza *stanza, int context );
152 
160  void registerAdhocCommandProvider( AdhocCommandProvider *acp, const std::string& command,
161  const std::string& name );
162 
168  void checkSupport( const JID& remote, AdhocHandler *ah );
169 
176  void getCommands( const JID& remote, AdhocHandler *ah );
177 
192  void execute( const JID& remote, const std::string& command, AdhocHandler *ah,
193  const std::string& sessionid = "", DataForm *form = 0,
194  AdhocExecuteActions action = ActionDefault );
195 
201  void removeAdhocCommandProvider( const std::string& command );
202 
203  private:
204  typedef std::map<const std::string, AdhocCommandProvider*> AdhocCommandProviderMap;
205  AdhocCommandProviderMap m_adhocCommandProviders;
206 
207  enum AdhocContext
208  {
209  CheckAdhocSupport,
210  FetchAdhocCommands,
211  ExecuteAdhocCommand
212  };
213 
214  struct TrackStruct
215  {
216  JID remote;
217  AdhocContext context;
218  AdhocHandler *ah;
219  };
220  typedef std::map<std::string, TrackStruct> AdhocTrackMap;
221  AdhocTrackMap m_adhocTrackMap;
222 
223  ClientBase *m_parent;
224 
225  StringMap m_items;
226 
227  };
228 
229 }
230 
231 #endif // ADHOC_H__