gloox 1.0

simanager.h

00001 /*
00002   Copyright (c) 2007-2009 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 #ifndef SIMANAGER_H__
00015 #define SIMANAGER_H__
00016 
00017 #include "iqhandler.h"
00018 
00019 namespace gloox
00020 {
00021 
00022   class ClientBase;
00023   class SIProfileHandler;
00024   class SIHandler;
00025 
00034   class GLOOX_API SIManager : public IqHandler
00035   {
00036 
00037     public:
00041       enum SIError
00042       {
00043         NoValidStreams,             
00044         BadProfile,                 
00045         RequestRejected             
00046       };
00047 
00048       class SI : public StanzaExtension
00049       {
00050         public:
00055           SI( const Tag* tag = 0 );
00056 
00062           SI( Tag* tag1, Tag* tag2, const std::string& id = EmptyString,
00063               const std::string& mimetype = EmptyString,
00064               const std::string& profile = EmptyString );
00065 
00069           virtual ~SI();
00070 
00075           const std::string& profile() const { return m_profile; };
00076 
00081           const std::string& mimetype() const { return m_mimetype; };
00082 
00087           const std::string& id() const { return m_id; };
00088 
00094           const Tag* tag1() const { return m_tag1; };
00095 
00101           const Tag* tag2() const { return m_tag2; };
00102 
00103           // reimplemented from StanzaExtension
00104           virtual const std::string& filterString() const;
00105 
00106           // reimplemented from StanzaExtension
00107           virtual StanzaExtension* newInstance( const Tag* tag ) const
00108           {
00109             return new SI( tag );
00110           }
00111 
00112           // reimplemented from StanzaExtension
00113           virtual Tag* tag() const;
00114 
00115           // reimplemented from StanzaExtension
00116           virtual StanzaExtension* clone() const
00117           {
00118             SI* s = new SI();
00119             s->m_tag1 = m_tag1 ? m_tag1->clone() : 0;
00120             s->m_tag2 = m_tag2 ? m_tag2->clone() : 0;
00121             s->m_id = m_id;
00122             s->m_mimetype = m_mimetype;
00123             s->m_profile = m_profile;
00124             return s;
00125           }
00126 
00127         private:
00128           Tag* m_tag1;
00129           Tag* m_tag2;
00130           std::string m_id;
00131           std::string m_mimetype;
00132           std::string m_profile;
00133       };
00134 
00140       SIManager( ClientBase* parent, bool advertise = true );
00141 
00145       virtual ~SIManager();
00146 
00164       const std::string requestSI( SIHandler* sih, const JID& to, const std::string& profile, Tag* child1,
00165                                    Tag* child2 = 0, const std::string& mimetype = "binary/octet-stream",
00166                                    const JID& from = JID(), const std::string& sid = EmptyString );
00167 
00181       void acceptSI( const JID& to, const std::string& id, Tag* child1, Tag* child2 = 0, const JID& from = JID() );
00182 
00191       void declineSI( const JID& to, const std::string& id, SIError reason,
00192                       const std::string& text = EmptyString );
00193 
00202       void registerProfile( const std::string& profile, SIProfileHandler* sih );
00203 
00208       void removeProfile( const std::string& profile );
00209 
00210       // reimplemented from IqHandler.
00211       virtual bool handleIq( const IQ& iq );
00212 
00213       // reimplemented from IqHandler.
00214       virtual void handleIqID( const IQ& iq, int context );
00215 
00216     private:
00217 #ifdef SIMANAGER_TEST
00218     public:
00219 #endif
00220       enum TrackContext
00221       {
00222         OfferSI
00223       };
00224 
00225       struct TrackStruct
00226       {
00227         std::string sid;
00228         std::string profile;
00229         SIHandler* sih;
00230       };
00231       typedef std::map<std::string, TrackStruct> TrackMap;
00232       TrackMap m_track;
00233 
00234       ClientBase* m_parent;
00235 
00236       typedef std::map<std::string, SIProfileHandler*> HandlerMap;
00237       HandlerMap m_handlers;
00238 
00239       bool m_advertise;
00240 
00241   };
00242 
00243 }
00244 
00245 #endif // SIMANAGER_H__