Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

roster.hh

00001 // roster.hh
00002 // Jabber client library
00003 //
00004 // Original Code Copyright (C) 1999-2001 Dave Smith (dave@jabber.org)
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 // 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 // Contributor(s): Julian Missig
00021 //
00022 // This Original Code has been modified by IBM Corporation. Modifications 
00023 // made by IBM described herein are Copyright (c) International Business 
00024 // Machines Corporation, 2002.
00025 //
00026 // Date             Modified by     Description of modification
00027 // 01/20/2002       IBM Corp.       Updated to libjudo 1.1.1
00028 // 2002-03-05       IBM Corp.       Updated to libjudo 1.1.5
00029 // 2002-07-09       IBM Corp.       Added Roster::getSession()
00030 //
00031 // =====================================================================================
00032 
00033 #ifndef ROSTER_HH
00034 #define ROSTER_HH
00035 
00036 #include <string>
00037 #include <set>
00038 #include <map>
00039 #include <sigc++/object.h>
00040 #include <sigc++/signal.h>
00041 #include <XCP.hh>
00042 #include <jabberoofwd.h>
00043 #include <presence.hh>
00044 #include <jutil.hh>
00045 
00046 namespace jabberoo
00047 {
00052      class Roster
00053           : public SigC::Object
00054           {
00055           public:
00060                enum Subscription {
00061                 rsNone,  
00062                 rsTo,    
00063                 rsFrom,  
00064                 rsBoth,  
00065                 rsRemove 
00066                };
00067 
00068                // Exceptions
00069                class XCP_InvalidJID : public XCP{};
00070 
00074                class Item {
00075                public:
00076                     // Initializers
00082                     Item(const judo::Element& t);
00090                     Item(Roster& r, const judo::Element& t);
00096                     Item(const std::string& jid, const std::string& nickname);
00100                     ~Item();
00101                public:
00102                     // Group modifiers
00108                     void addToGroup(const std::string& group);
00114                     void delFromGroup(const std::string& group);
00118                     void clearGroups();
00123                     void setNickname(const std::string& nickname);
00131                     void setJID(const std::string& jid);
00132         
00133                     // Info ops
00137                     bool             isAvailable() const;
00141                     std::string           getNickname() const;
00145                     std::string           getJID() const;
00150                     Subscription     getSubsType() const;
00154                     bool             isPending() const;
00155 
00156                     // Group pseudo-container ops/iterators
00157                     typedef std::set<std::string>::const_iterator iterator;
00162                     iterator begin() const { return _groups.begin(); }
00167                     iterator end()   const { return _groups.end(); }
00172                     bool     empty() const { return _groups.empty(); }
00173 
00174                protected:
00175                     // Update handlers
00176                     void update(Roster& r, const std::string& jid, const Presence& p, Presence::Type prev_type);
00177                     bool update(const judo::Element& t);
00178                     bool update(Roster& r, const judo::Element& t);
00179                private:
00180                     friend class Roster;
00181                     int          _rescnt;
00182             std::set<std::string>  _groups;
00183                     Subscription _type;
00184                     bool         _pending;
00185                     std::string       _nickname;
00186                     std::string       _jid;
00187                };
00188                
00189                typedef std::map<std::string, Item, jutil::CaseInsensitiveCmp> ItemMap;
00190 
00191                // Non-const iterators
00192                typedef jutil::ValueIterator<ItemMap::iterator, Item > iterator;
00197                iterator begin() { return _items.begin(); }
00202                iterator end() { return _items.end(); }
00203 
00204                // Const iterators
00205                typedef jutil::ValueIterator<ItemMap::const_iterator, const Item> const_iterator;
00210                const_iterator begin() const { return _items.begin(); }
00215                const_iterator end() const { return _items.end(); }
00216 
00217                // Intializers
00223                Roster(Session& s);
00224 
00225                // Accessors
00230                Session& getSession() { return _owner; }
00231 
00232                // Operators
00236                const Roster::Item& operator[](const std::string& jid) const;
00237                Roster::Item& operator[](const std::string& jid);
00241                Roster& operator<<(const Item& i) { update(i); return *this; }
00242           public:
00243                void reset();
00244 
00245                // Information
00250                bool containsJID(const std::string& jid) const;
00251 
00252                // Update ops
00258                void update(const judo::Element& t);        // Roster push
00264                void update(const Presence& p, Presence::Type prev_type);     // Roster presence
00273                void update(const Item& i);         // Roster item add/modify
00274 
00275                // Control ops
00280                void deleteUser(const std::string& jid); /* Remove the user w/ JID */
00284                void fetch() const;                 /* Retrieve roster from server */             
00288                int size() const
00289                { return _items.size(); }
00290 
00291                // Translation
00292                static std::string translateS10N(Subscription stype);
00293                static Subscription translateS10N(const std::string& stype);
00294                static std::string filterJID(const std::string& jid);
00295 
00296                // Item/Group access -- HACK
00297                const std::map<std::string, std::set<std::string> >& getGroups() const { return _groups;} 
00298           public:
00302                SigC::Signal0<void, SigC::Marshal<void> >                      evtRefresh;
00309            SigC::Signal3<void, const std::string&, bool, Presence::Type, SigC::Marshal<void> > evtPresence;
00310           private:
00311                friend class Item;
00312                void mergeItemGroups(const std::string& itemjid, const std::set<std::string>& oldgrp, const std::set<std::string>& newgrp);
00313                void removeItemFromGroup(const std::string& group, const std::string& jid);
00314                void removeItemFromAllGroups(const Item& item);
00315                void deleteAgent(const judo::Element& iq);
00316                ItemMap                   _items;
00317                std::map<std::string, std::set<std::string> > _groups;
00318                Session&                  _owner;
00319      };
00320 
00321 }  // namespace jabberoo
00322 #endif // #ifndef ROSTER_HH

Generated on Thu Jul 24 13:31:51 2003 for jabberoo by doxygen1.3-rc3