/*********************************************************************************** ** Set the absolute progress of current action ** ** ProgressInfo::SetCurrentActionProgress ** @param count How many actions have already been performed ** @param total How many actions should be performed in total ** ***********************************************************************************/ void ProgressInfo::SetCurrentActionProgress(unsigned count, unsigned total_count) { m_count = count; m_total_count = total_count; AlertListeners(); }
/*********************************************************************************** ** Sets whether we are connected to a server ** ** ProgressInfo::SetConnected ** ***********************************************************************************/ void ProgressInfo::SetConnected(BOOL connected) { if (m_connected != connected) { m_connected = connected; AlertListeners(); } }
/*********************************************************************************** ** End the current action ** ** ProgressInfo::EndCurrentAction ** @param end_connection Ends the connection as well ** ***********************************************************************************/ OP_STATUS ProgressInfo::EndCurrentAction(BOOL end_connection) { Reset(end_connection); AlertListeners(); return OpStatus::OK; }
void NetworkTable::ProcessTransaction(bool confirmed, NetworkTables::NetworkQueue *transaction) { if (transaction->IsEmpty()) return; NetworkTables::Connection *source = ((NetworkTables::Entry *)transaction->Peek())->GetSource(); Synchronized sync(m_dataLock); std::set<NetworkTables::Connection *>::iterator it, end; it = m_connections.begin(); end = m_connections.end(); for (; it != end; it++) if (*it != source) (*it)->OfferTransaction(transaction); while (!transaction->IsEmpty()) { std::pair<NetworkTables::Data *, bool> data = transaction->Poll(); // TODO: Remove this if (!data.second) printf("Internal error!"); std::auto_ptr<NetworkTables::Entry> entry = std::auto_ptr<NetworkTables::Entry>((NetworkTables::Entry *)data.first); std::auto_ptr<NetworkTables::Entry> oldEntry = entry->GetKey()->SetEntry(entry); if (oldEntry.get() == NULL) m_hasAdded->Offer(entry.get()); else // TODO: Filter unchanged values m_hasChanged->Offer(entry.get()); } while (!m_hasAdded->IsEmpty()) { NetworkTables::Entry *entry = (NetworkTables::Entry *)m_hasAdded->Poll().first; AlertListeners(true, confirmed, entry->GetKey()->GetName().c_str(), entry); } while (!m_hasChanged->IsEmpty()) { NetworkTables::Entry *entry = (NetworkTables::Entry *)m_hasChanged->Poll().first; AlertListeners(true, confirmed, entry->GetKey()->GetName().c_str(), entry); } }
/** * This method should be called by children when they want to add a new value. * It will notify listeners of the value * @param confirmed whether or not this value was confirmed or received * @param key the key * @param value the value */ void NetworkTable::Got(bool confirmed, NetworkTables::Key *key, std::auto_ptr<NetworkTables::Entry> value) { std::auto_ptr<NetworkTables::Entry> old; { Synchronized sync(m_dataLock); old = key->SetEntry(value); } // TODO: return if value didn't change Send(key->GetEntry()); AlertListeners(old.get() == NULL, confirmed, key->GetName().c_str(), key->GetEntry()); }
/*********************************************************************************** ** Listener, in case this progress keeper listens to other progress updates ** ** ProgressInfo::OnProgressChanged ** ***********************************************************************************/ void ProgressInfo::OnProgressChanged(const ProgressInfo& progress) { AccountManager* account_mgr = MessageEngine::GetInstance()->GetAccountManager(); if (!account_mgr) return; Reset(TRUE); // Check all accounts, merge progress for (unsigned i = 0; i < account_mgr->GetAccountCount(); i++) { Account* account = account_mgr->GetAccountByIndex(i); if (account) { Merge(account->GetProgress(TRUE)); Merge(account->GetProgress(FALSE)); } } AlertListeners(); }
/*********************************************************************************** ** Set the current action for this progress keeper ** ** ProgressInfo::SetCurrentAction ** @param current_action The action to set ** @param total_count How many times this action will have to be performed ** ***********************************************************************************/ OP_STATUS ProgressInfo::SetCurrentAction(ProgressAction current_action, unsigned total_count) { BOOL status_changed = FALSE; // Check if we have to end an action before setting the new action if (m_current_action != NONE && m_current_action != current_action) Reset(FALSE); else status_changed = m_current_action == NONE && current_action != NONE; m_current_action = current_action; m_total_count = total_count; AlertListeners(); if (status_changed) { for (OpListenersIterator iterator(m_listeners); m_listeners.HasNext(iterator);) m_listeners.GetNext(iterator)->OnStatusChanged(*this); } return OpStatus::OK; }