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

discoDB.hh

00001 // discoDB.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 DISCODB_HH
00034 #define DISCODB_HH
00035 
00036 #include <time.h>
00037 #include <cstdio>
00038 #include <cstring>
00039 #include <map>
00040 #include <list>
00041 #include <utility>
00042 #include <set>
00043 #include <algorithm>
00044 #include <functional>
00045 #include <iostream>
00046 
00047 #include <jutil.hh>
00048 #include <judo.hpp>
00049 #include <XPath.h>
00050 #include <XCP.hh>
00051 #include <packet.hh>
00052 #include <message.hh>
00053 #include <presence.hh>
00054 #include <judo.hpp>
00055 #include <sigc++/object.h>
00056 #include <sigc++/signal.h>
00057 #include <sigc++/slot.h>
00058 #include <string>
00059 #include <jabberoofwd.h>
00060 
00061 namespace jabberoo {
00062 
00067     class DiscoDB : public SigC::Object
00068     {
00069     public:
00070         class Item
00071         {
00072         public:
00074             class Identity
00075             {
00076             public:
00077                 Identity(const judo::Element& e);
00078                 Identity(const std::string& category, const std::string& type);
00079                 ~Identity();
00080 
00081                 const std::string& getType() const;
00082                 const std::string& getCategory() const;
00083 
00084             private:
00085                 std::string _category;
00086                 std::string _type;
00087             };
00088 
00089             typedef std::list<std::string> FeatureList;
00090             typedef std::list<Identity*> IdentityList;
00091             typedef std::list<DiscoDB::Item*>::iterator iterator;
00092             typedef std::list<DiscoDB::Item*>::const_iterator const_iterator;
00093 
00094 
00095             Item(const std::string& jid);
00096             ~Item();
00097 
00098             const std::string& getJID() const;
00099             void setNode(const std::string& val);
00100             const std::string& getNode() const;
00101             void setName(const std::string& val);
00102             const std::string& getName() const;
00103             const IdentityList& getIdentityList() const;
00104             const FeatureList& getFeatureList() const;
00105             bool hasChildren();
00106             iterator begin();
00107             const_iterator begin() const;
00108             iterator end();
00109             const_iterator end() const;
00110             void appendChild(DiscoDB::Item* item);
00111             void addFeature(const std::string& feature);
00112             void addIdentity(const judo::Element& e);
00113             void addIdentity(const std::string& category, 
00114                              const std::string& type);
00115 
00116         private:
00117             std::string _jid;
00118             std::string _node;
00119             std::string _name;
00120             std::list<DiscoDB::Item*> _children;
00121             FeatureList _features;
00122             IdentityList _identities;
00123         };
00124 /*RL: std:map na std:multimap*/
00125         typedef std::multimap<std::string, DiscoDB::Item*>::iterator iterator;
00126         typedef std::multimap<std::string, DiscoDB::Item*>::const_iterator const_iterator;
00127         typedef SigC::Slot1<void, const DiscoDB::Item*> DiscoCallbackFunc;
00128         typedef std::list<std::string> JIDList;
00130         class FilterPred : public std::unary_function<DiscoDB::Item, bool>
00131         {
00132         public:
00133             virtual bool operator()(const DiscoDB::Item& item)
00134             { return false; }
00135         };
00136         struct DiscoFilter
00137         {
00138             DiscoFilter(FilterPred pred, JIDList& jid_list) : 
00139                 pred_(pred), jid_list_(jid_list)
00140             { }
00141             FilterPred pred_;
00142             JIDList& jid_list_;
00143         };
00144 
00145         class XCP_NotCached : public XCP{};
00146 
00147 
00148         DiscoDB(jabberoo::Session& sess);
00149         ~DiscoDB();
00150 
00159         DiscoDB::Item& operator[](const std::string& jid);
00160 
00162         void cache(const std::string& jid, DiscoCallbackFunc f);
00163         void cache(const std::string& jid, const std::string& node,
00164                    DiscoCallbackFunc f);
00165 
00167         void clear();
00168 
00169         iterator begin()
00170         { return _items.begin(); }
00171         
00172         const_iterator begin() const
00173         { return _items.begin(); }
00174 
00175         iterator end()
00176         { return _items.end(); }
00177 
00178         const_iterator end() const
00179         { return _items.end(); }
00180 
00181         void erase(iterator it)
00182         { delete it->second; _items.erase(it); }
00183 
00189         void addFilter(DiscoFilter* filter)
00190         { _filters.push_back(filter); }
00191 
00195         void removeFilter(DiscoFilter* filter)
00196         { _filters.remove(filter); }
00197 
00198     private:
00199         typedef std::multimap<std::string, DiscoDB::Item*> ItemMap;
00200         typedef std::multimap<std::string, DiscoCallbackFunc> CallbackMap;
00201         typedef std::list<DiscoFilter*> FilterMap;
00202 
00203         jabberoo::Session& _session;
00204         CallbackMap _callbacks;
00205         ItemMap _items;
00206         FilterMap _filters;
00207 
00208         void browseCB(const judo::Element& e);
00209         void discoInfoCB(const judo::Element& e);
00210         void discoItemsCB(const judo::Element& e);
00211         void runCallbacks(const std::string& jid, const DiscoDB::Item* item);
00212     };
00213 } // namespace jabberoo
00214 
00215 #endif  // #ifndef DISCODB_HH

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