Changeset 2957

Show
Ignore:
Timestamp:
04/27/06 17:11:29 (3 years ago)
Author:
madcat
Message:

Support for object updates over cgcomm. Serverlist is now properly in sync with core (1s update rate).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hncgcomm/cgcomm.cpp

    r2952 r2957  
    10081008                                if (found) { 
    10091009                                        found->update(obj); 
     1010                                        updatedObject(found); 
    10101011                                        obj = found; 
    10111012                                } else { 
     
    10141015                                lastObject = obj; 
    10151016                        } 
    1016                         lastObject->findChildren(); 
    1017                         receivedObject(lastObject); 
     1017                        if (lastObject) { 
     1018                                lastObject->findChildren(); 
     1019                                receivedObject(lastObject); 
     1020                        } 
    10181021                        break; 
    10191022                } 
     
    10241027                        if (found) { 
    10251028                                found->update(child); 
     1029                                updatedObject(found); 
    10261030                                child = found; 
    10271031                        } else { 
     
    11351139        std::ostringstream tmp; 
    11361140        Utils::putVal<uint8_t>(tmp, OC_MONITOR); 
    1137         Utils::putVal<uint32_t>(tmp, 0); 
    11381141        Utils::putVal<uint32_t>(tmp, interval); 
    11391142        sendPacket(tmp.str()); 
    11401143} 
    11411144 
    1142 void Modules::getObject(ModulePtr mod, const std::string &name, bool recurse) { 
     1145void Modules::getObject( 
     1146        ModulePtr mod, const std::string &name, bool recurse, uint32_t timer 
     1147) { 
    11431148        std::ostringstream tmp; 
    11441149        Utils::putVal<uint8_t>(tmp, OC_GET); 
     
    11471152        Utils::putVal(tmp, name, name.size()); 
    11481153        Utils::putVal<uint8_t>(tmp, recurse); 
     1154        Utils::putVal<uint32_t>(tmp, timer); 
    11491155        sendPacket(tmp.str()); 
    11501156} 
  • hydranode/hncgcomm/cgcomm.h

    r2942 r2957  
    559559                 * Request an object to be sent 
    560560                 * 
    561                  * @param mod        Module for which the object is child of 
    562                  * @param name       Name of the object to be sent 
    563                  * @param recurse    Whether to send the entire subtree 
     561                 * @param mod          Module for which the object is child of 
     562                 * @param name         Name of the object to be sent 
     563                 * @param recurse      Whether to send the entire subtree 
     564                 * @param monitorTimer If non-zero, also setup monitoring (ms) 
    564565                 */ 
    565566                void getObject( 
    566567                        ModulePtr mod, const std::string &name,  
    567                         bool recurse = true 
     568                        bool recurse = true, uint32_t monitorTimer = 0 
    568569                ); 
    569570                /** 
     
    608609                 */ 
    609610                boost::signal<void (ObjectPtr)> updatedObject; 
     611 
     612                boost::signal<void (ObjectPtr)> addedObject; 
     613                boost::signal<void (ObjectPtr)> removedObject; 
    610614        protected: 
    611615                virtual void handle(std::istream &i); 
  • hydranode/hncore/cgcomm/sub_modules.cpp

    r2942 r2957  
    2828Modules::Modules( 
    2929        boost::function<void (const std::string&)> sendFunc 
    30 ) : SubSysBase(SUB_MODULES, sendFunc), m_monitorTimer()
     30) : SubSysBase(SUB_MODULES, sendFunc), m_monitorTimer(), m_monitorObjTimer()
    3131        ModManager::instance().onModuleLoaded.connect( 
    3232                boost::bind(&Modules::onLoaded, this, _1) 
     
    7575 
    7676void Modules::monitor(std::istream &i) { 
    77         uint32_t id = Utils::getVal<uint32_t>(i); 
    7877        uint32_t timer = Utils::getVal<uint32_t>(i); 
    79         if (!m_monitorTimer && timer && id) { 
    80                 Utils::timedCallback( 
    81                         boost::bind(&Modules::sendList, this, OC_UPDATE), timer 
    82                 ); 
    83         } else if (id) { 
    84                 Object *obj = Object::findObject(id); 
    85                 if (!obj) { 
    86                         sendNotFound(id); 
    87                 } else { 
    88 //                      obj->addHandler( 
    89 //                              boost::bind(&Modules::objUpdated, this, _1) 
    90 //                      ); 
    91                 } 
     78        if (!m_monitorTimer && timer) { 
     79                Utils::timedCallback( 
     80                        boost::bind(&Modules::sendList, this,OC_UPDATE), 
     81                        timer 
     82                ); 
    9283        } 
    9384        m_monitorTimer = timer; 
     
    138129        std::string name    = Utils::getVal<std::string>(i, len); 
    139130        bool        recurse = Utils::getVal<uint8_t>(i); 
     131        uint32_t    timer   = Utils::getVal<uint32_t>(i); 
    140132 
    141133        logDebug("Received request for object " + name); 
     
    143135        if (!obj) { 
    144136                sendNotFound(id); 
    145         } else { 
    146                 for (Object::CIter i = obj->begin(); i != obj->end(); ++i) { 
    147                         if (i->second->getName() == name) { 
    148                                 std::ostringstream tmp; 
    149                                 uint32_t cnt = sendObject( 
    150                                         i->second, recurse, tmp 
    151                                 ); 
    152                                 std::ostringstream final; 
    153                                 Utils::putVal<uint8_t>(final, OC_OBJLIST); 
    154                                 Utils::putVal<uint32_t>(final, cnt); 
    155                                 Utils::putVal<std::string>( 
    156                                         final, tmp.str(), tmp.str().size() 
    157                                 ); 
    158                                 sendPacket(final.str()); 
    159                                 break; 
    160                         } 
    161                 } 
     137                return; 
     138        }  
     139        for (Object::CIter i = obj->begin(); i != obj->end(); ++i) { 
     140                if (i->second->getName() == name) { 
     141                        std::ostringstream tmp; 
     142                        uint32_t cnt = sendObject(i->second, recurse, tmp); 
     143                        std::ostringstream final; 
     144                        Utils::putVal<uint8_t>(final, OC_OBJLIST); 
     145                        Utils::putVal<uint32_t>(final, cnt); 
     146                        Utils::putVal<std::string>( 
     147                                final, tmp.str(), tmp.str().size() 
     148                        ); 
     149                        sendPacket(final.str()); 
     150                        break; 
     151                } 
     152        } 
     153 
     154        if (timer) { 
     155                obj->objectNotify.connect( 
     156                        boost::bind(&Modules::objUpdated, this, _1, _2) 
     157                ); 
     158        } 
     159 
     160        if (timer && !m_monitorObjTimer) { 
     161                Utils::timedCallback( 
     162                        boost::bind(&Modules::sendDirtyObjects, this), timer 
     163                ); 
     164        } 
     165        if (timer) { 
     166                m_monitorObjTimer = timer; 
    162167        } 
    163168} 
     
    238243} 
    239244 
    240 void Modules::objUpdated(Object *obj) { 
    241         m_dirty.insert(obj); 
     245void Modules::objUpdated(Object *obj, ObjectEvent evt) { 
     246        logDebug("object was updated."); 
     247        if (evt == OBJ_MODIFIED) { 
     248                m_dirty.insert(obj); 
     249        } else if (evt == OBJ_ADDED && obj->getParent()) { 
     250                std::ostringstream tmp; 
     251                Utils::putVal<uint8_t>(tmp, OC_CADDED); 
     252                Utils::putVal<uint32_t>(tmp, obj->getParent()->getId()); 
     253                sendObject(obj, false, tmp); 
     254                sendPacket(tmp.str()); 
     255                m_dirty.erase(obj); 
     256                logDebug("Sending OBJ_ADDED to gui."); 
     257        } else if (evt == OBJ_REMOVED && obj->getParent()) { 
     258                std::ostringstream tmp; 
     259                Utils::putVal<uint8_t>(tmp, OC_CREMOVED); 
     260                Utils::putVal<uint32_t>(tmp, obj->getParent()->getId()); 
     261                Utils::putVal<uint32_t>(tmp, obj->getId()); 
     262                sendPacket(tmp.str()); 
     263                logDebug("Sending OBJ_REMOVED to gui."); 
     264                m_dirty.erase(obj); 
     265        } 
     266
     267 
     268void Modules::sendDirtyObjects() { 
     269        if (m_dirty.size()) { 
     270                std::ostringstream tmp; 
     271                Utils::putVal<uint8_t>(tmp, OC_OBJLIST); 
     272                Utils::putVal<uint32_t>(tmp, m_dirty.size()); 
     273                std::set<Object*>::iterator it = m_dirty.begin(); 
     274                while (it != m_dirty.end()) { 
     275                        sendObject(*it, false, tmp); 
     276                        ++it; 
     277                } 
     278                sendPacket(tmp.str()); 
     279                m_dirty.clear(); 
     280        } 
     281 
     282        if (m_monitorObjTimer) { 
     283                Utils::timedCallback( 
     284                        boost::bind(&Modules::sendDirtyObjects, this), 
     285                        m_monitorObjTimer 
     286                ); 
     287        } 
    242288} 
    243289 
  • hydranode/hncore/cgcomm/sub_modules.h

    r2942 r2957  
    4040        uint32_t sendObject(Object *obj, bool recurse, std::ostream &tmp); 
    4141        void sendNotFound(uint32_t id); 
    42         void objUpdated(Object *obj); 
     42        void objUpdated(Object *obj, ObjectEvent evt); 
     43        void sendDirtyObjects(); 
    4344        std::set<Object*> m_dirty; 
    4445 
     
    4849        std::string writeModule(ModuleBase *mod); 
    4950 
    50         uint32_t m_monitorTimer
     51        uint32_t m_monitorTimer, m_monitorObjTimer
    5152}; 
    5253 
  • hydranode/hngui/plugins/donkeypage.cpp

    r2948 r2957  
    124124        while (i != p->end()) { 
    125125                if (i->second->getName() == "ed2k") { 
    126                         p->getObject(i->second, "serverlist", true); 
     126                        p->getObject(i->second, "serverlist", true, 1500); 
    127127                        break; 
    128128                } 
     
    131131        p->receivedObject.connect( 
    132132                boost::bind(&DonkeyPage::gotServers, this, _1) 
     133        ); 
     134        p->updatedObject.connect( 
     135                boost::bind(&DonkeyPage::updateObject, this, _1) 
     136        ); 
     137        p->addedObject.connect( 
     138                boost::bind(&DonkeyPage::addObject, this, _1) 
     139        ); 
     140        p->removedObject.connect( 
     141                boost::bind(&DonkeyPage::delObject, this, _1) 
    133142        ); 
    134143} 
     
    141150        Engine::Object::CIter i = obj->begin(); 
    142151        while (i != obj->end()) { 
    143                 QTreeWidgetItem *it = new ServerListItem(m_ui->serverList); 
     152                addObject(i->second); 
     153                ++i; 
     154        } 
     155        m_ui->serverList->sortItems(3, Qt::DescendingOrder); 
     156
     157 
     158void DonkeyPage::updateObject(Engine::ObjectPtr obj) { 
     159        QMap<quint32, ServerListItem*>::iterator it =m_list.find(obj->getId()); 
     160        if (it != m_list.end()) { 
     161                int n = 0; 
     162                Engine::Object::DIter j = obj->dbegin(); 
     163                while (j != obj->dend()) { 
     164                        it.value()->setText(n++, QString::fromStdString(*j)); 
     165                        ++j; 
     166                } 
     167        } 
     168        m_ui->serverList->sortItems( 
     169                m_ui->serverList->sortColumn(), 
     170                m_ui->serverList->header()->sortIndicatorOrder() 
     171        ); 
     172
     173 
     174void DonkeyPage::addObject(Engine::ObjectPtr obj) { 
     175        logDebug("Adding object..."); 
     176        if (obj->getParent() && obj->getParent()->getName() == "serverlist") { 
     177                logDebug(" -> adding [add-real]"); 
     178                ServerListItem *it = new ServerListItem(m_ui->serverList); 
    144179                for (int j = 3; j < m_ui->serverList->columnCount(); ++j) { 
    145180                        it->setTextAlignment(j, Qt::AlignRight); 
     
    147182                it->setIcon(0, QIcon(":/transfer/icons/clear16")); 
    148183 
    149                 Engine::Object::DIter j = i->second->dbegin(); 
     184                Engine::Object::DIter j = obj->dbegin(); 
    150185                int n = 0; 
    151                 while (j != i->second->dend()) { 
     186                while (j != obj->dend()) { 
    152187                        it->setText(n++, QString::fromStdString(*j)); 
    153188                        ++j; 
    154189                } 
    155                 ++i; 
    156         } 
    157         m_ui->serverList->sortItems(3, Qt::DescendingOrder); 
    158 
     190                m_list[obj->getId()] = it; 
     191        } 
     192
     193 
     194void DonkeyPage::delObject(Engine::ObjectPtr obj) { 
     195        logDebug("Removing object..."); 
     196        QMap<quint32, ServerListItem*>::iterator it =m_list.find(obj->getId()); 
     197        if (it != m_list.end()) { 
     198                logDebug(" -> removing [del-real]"); 
     199                delete it.value(); 
     200                m_list.erase(it); 
     201        } 
     202
  • hydranode/hngui/plugins/donkeypage.h

    r2948 r2957  
    2222#include <QWidget> 
    2323#include <QTreeWidgetItem> 
     24#include <QMap> 
    2425#include <hncgcomm/fwd.h> 
    2526#include "htreewidget.h" 
     
    2829        class DonkeyPage; 
    2930} 
    30  
    31 class DonkeyPage : public QWidget { 
    32         Q_OBJECT 
    33 public: 
    34         DonkeyPage(QWidget *parent, Engine::Modules *p); 
    35 private: 
    36         void gotServers(Engine::ObjectPtr obj); 
    37  
    38         Ui::DonkeyPage  *m_ui; 
    39         Engine::Modules *m_modules; 
    40 }; 
    4131 
    4232class ServerList : public HTreeWidget { 
     
    5444}; 
    5545 
     46class DonkeyPage : public QWidget { 
     47        Q_OBJECT 
     48public: 
     49        DonkeyPage(QWidget *parent, Engine::Modules *p); 
     50private: 
     51        void gotServers(Engine::ObjectPtr obj); 
     52        void updateObject(Engine::ObjectPtr obj); 
     53        void addObject(Engine::ObjectPtr obj); 
     54        void delObject(Engine::ObjectPtr obj); 
     55 
     56        Ui::DonkeyPage  *m_ui; 
     57        Engine::Modules *m_modules; 
     58        QMap<quint32, ServerListItem*> m_list; 
     59}; 
    5660 
    5761#endif