gloox  1.0.28
lastactivity.h
1 /*
2  Copyright (c) 2005-2023 by Jakob Schröter <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 #ifndef LASTACTIVITY_H__
15 #define LASTACTIVITY_H__
16 
17 #include "iqhandler.h"
18 
19 #include <ctime>
20 
21 namespace gloox
22 {
23 
24  class JID;
25  class ClientBase;
26  class LastActivityHandler;
27 
39  class GLOOX_API LastActivity : public IqHandler
40  {
41  public:
52  class GLOOX_API Query : public StanzaExtension
53  {
54  public:
59  Query( const Tag* tag = 0 );
60 
66  Query( const std::string& status, long seconds );
67 
71  virtual ~Query();
72 
78  long seconds() const { return m_seconds; }
79 
85  const std::string& status() const { return m_status; }
86 
87  // reimplemented from StanzaExtension
88  virtual const std::string& filterString() const;
89 
90  // reimplemented from StanzaExtension
91  virtual StanzaExtension* newInstance( const Tag* tag ) const
92  {
93  return new Query( tag );
94  }
95 
96  // reimplemented from StanzaExtension
97  virtual Tag* tag() const;
98 
99  // reimplemented from StanzaExtension
100  virtual StanzaExtension* clone() const
101  {
102  return new Query( *this );
103  }
104 
105  private:
106  long m_seconds;
107  std::string m_status;
108 
109  };
110 
115  LastActivity( ClientBase* parent );
116 
120  virtual ~LastActivity();
121 
127  void query( const JID& jid );
128 
134  void registerLastActivityHandler( LastActivityHandler* lah ) { m_lastActivityHandler = lah; }
135 
139  void removeLastActivityHandler() { m_lastActivityHandler = 0; }
140 
145  void resetIdleTimer();
146 
147  // reimplemented from IqHandler
148  virtual bool handleIq( const IQ& iq );
149 
150  // reimplemented from IqHandler
151  virtual void handleIqID( const IQ& iq, int context );
152 
153  private:
154 #ifdef LASTACTIVITY_TEST
155  public:
156 #endif
157  LastActivityHandler* m_lastActivityHandler;
158  ClientBase* m_parent;
159 
160  time_t m_active;
161 
162  };
163 
164 }
165 
166 #endif // LASTACTIVITY_H__
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:79
An abstraction of an IQ stanza.
Definition: iq.h:34
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:32
An abstraction of a JID.
Definition: jid.h:31
This is an virtual interface that, once reimplemented, allows to receive the results of Last-Activity...
This is an abstraction of a LastActivity Query that can be used in XEP-0012 as well as XEP-0256.
Definition: lastactivity.h:53
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: lastactivity.h:91
virtual StanzaExtension * clone() const
Definition: lastactivity.h:100
const std::string & status() const
Definition: lastactivity.h:85
This is an implementation of XEP-0012 (Last Activity) for both clients and components.
Definition: lastactivity.h:40
void removeLastActivityHandler()
Definition: lastactivity.h:139
void registerLastActivityHandler(LastActivityHandler *lah)
Definition: lastactivity.h:134
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28