Changeset 2957
- Timestamp:
- 04/27/06 17:11:29 (3 years ago)
- Files:
-
- hydranode/hncgcomm/cgcomm.cpp (modified) (5 diffs)
- hydranode/hncgcomm/cgcomm.h (modified) (2 diffs)
- hydranode/hncore/cgcomm/sub_modules.cpp (modified) (5 diffs)
- hydranode/hncore/cgcomm/sub_modules.h (modified) (2 diffs)
- hydranode/hngui/plugins/donkeypage.cpp (modified) (4 diffs)
- hydranode/hngui/plugins/donkeypage.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hncgcomm/cgcomm.cpp
r2952 r2957 1008 1008 if (found) { 1009 1009 found->update(obj); 1010 updatedObject(found); 1010 1011 obj = found; 1011 1012 } else { … … 1014 1015 lastObject = obj; 1015 1016 } 1016 lastObject->findChildren(); 1017 receivedObject(lastObject); 1017 if (lastObject) { 1018 lastObject->findChildren(); 1019 receivedObject(lastObject); 1020 } 1018 1021 break; 1019 1022 } … … 1024 1027 if (found) { 1025 1028 found->update(child); 1029 updatedObject(found); 1026 1030 child = found; 1027 1031 } else { … … 1135 1139 std::ostringstream tmp; 1136 1140 Utils::putVal<uint8_t>(tmp, OC_MONITOR); 1137 Utils::putVal<uint32_t>(tmp, 0);1138 1141 Utils::putVal<uint32_t>(tmp, interval); 1139 1142 sendPacket(tmp.str()); 1140 1143 } 1141 1144 1142 void Modules::getObject(ModulePtr mod, const std::string &name, bool recurse) { 1145 void Modules::getObject( 1146 ModulePtr mod, const std::string &name, bool recurse, uint32_t timer 1147 ) { 1143 1148 std::ostringstream tmp; 1144 1149 Utils::putVal<uint8_t>(tmp, OC_GET); … … 1147 1152 Utils::putVal(tmp, name, name.size()); 1148 1153 Utils::putVal<uint8_t>(tmp, recurse); 1154 Utils::putVal<uint32_t>(tmp, timer); 1149 1155 sendPacket(tmp.str()); 1150 1156 } hydranode/hncgcomm/cgcomm.h
r2942 r2957 559 559 * Request an object to be sent 560 560 * 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) 564 565 */ 565 566 void getObject( 566 567 ModulePtr mod, const std::string &name, 567 bool recurse = true 568 bool recurse = true, uint32_t monitorTimer = 0 568 569 ); 569 570 /** … … 608 609 */ 609 610 boost::signal<void (ObjectPtr)> updatedObject; 611 612 boost::signal<void (ObjectPtr)> addedObject; 613 boost::signal<void (ObjectPtr)> removedObject; 610 614 protected: 611 615 virtual void handle(std::istream &i); hydranode/hncore/cgcomm/sub_modules.cpp
r2942 r2957 28 28 Modules::Modules( 29 29 boost::function<void (const std::string&)> sendFunc 30 ) : SubSysBase(SUB_MODULES, sendFunc), m_monitorTimer() {30 ) : SubSysBase(SUB_MODULES, sendFunc), m_monitorTimer(), m_monitorObjTimer() { 31 31 ModManager::instance().onModuleLoaded.connect( 32 32 boost::bind(&Modules::onLoaded, this, _1) … … 75 75 76 76 void Modules::monitor(std::istream &i) { 77 uint32_t id = Utils::getVal<uint32_t>(i);78 77 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 ); 92 83 } 93 84 m_monitorTimer = timer; … … 138 129 std::string name = Utils::getVal<std::string>(i, len); 139 130 bool recurse = Utils::getVal<uint8_t>(i); 131 uint32_t timer = Utils::getVal<uint32_t>(i); 140 132 141 133 logDebug("Received request for object " + name); … … 143 135 if (!obj) { 144 136 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; 162 167 } 163 168 } … … 238 243 } 239 244 240 void Modules::objUpdated(Object *obj) { 241 m_dirty.insert(obj); 245 void 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 268 void 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 } 242 288 } 243 289 hydranode/hncore/cgcomm/sub_modules.h
r2942 r2957 40 40 uint32_t sendObject(Object *obj, bool recurse, std::ostream &tmp); 41 41 void sendNotFound(uint32_t id); 42 void objUpdated(Object *obj); 42 void objUpdated(Object *obj, ObjectEvent evt); 43 void sendDirtyObjects(); 43 44 std::set<Object*> m_dirty; 44 45 … … 48 49 std::string writeModule(ModuleBase *mod); 49 50 50 uint32_t m_monitorTimer ;51 uint32_t m_monitorTimer, m_monitorObjTimer; 51 52 }; 52 53 hydranode/hngui/plugins/donkeypage.cpp
r2948 r2957 124 124 while (i != p->end()) { 125 125 if (i->second->getName() == "ed2k") { 126 p->getObject(i->second, "serverlist", true );126 p->getObject(i->second, "serverlist", true, 1500); 127 127 break; 128 128 } … … 131 131 p->receivedObject.connect( 132 132 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) 133 142 ); 134 143 } … … 141 150 Engine::Object::CIter i = obj->begin(); 142 151 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 158 void 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 174 void 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); 144 179 for (int j = 3; j < m_ui->serverList->columnCount(); ++j) { 145 180 it->setTextAlignment(j, Qt::AlignRight); … … 147 182 it->setIcon(0, QIcon(":/transfer/icons/clear16")); 148 183 149 Engine::Object::DIter j = i->second->dbegin();184 Engine::Object::DIter j = obj->dbegin(); 150 185 int n = 0; 151 while (j != i->second->dend()) {186 while (j != obj->dend()) { 152 187 it->setText(n++, QString::fromStdString(*j)); 153 188 ++j; 154 189 } 155 ++i; 156 } 157 m_ui->serverList->sortItems(3, Qt::DescendingOrder); 158 } 190 m_list[obj->getId()] = it; 191 } 192 } 193 194 void 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 22 22 #include <QWidget> 23 23 #include <QTreeWidgetItem> 24 #include <QMap> 24 25 #include <hncgcomm/fwd.h> 25 26 #include "htreewidget.h" … … 28 29 class DonkeyPage; 29 30 } 30 31 class DonkeyPage : public QWidget {32 Q_OBJECT33 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 };41 31 42 32 class ServerList : public HTreeWidget { … … 54 44 }; 55 45 46 class DonkeyPage : public QWidget { 47 Q_OBJECT 48 public: 49 DonkeyPage(QWidget *parent, Engine::Modules *p); 50 private: 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 }; 56 60 57 61 #endif
