static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsigned char>& data) { RecipientCatcher sigCatcher; QObject::connect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), &sigCatcher, SLOT(getRecipient(SendCoinsRecipient))); // Write data to a temp file: QTemporaryFile f; f.open(); f.write((const char*)data.data(), data.size()); f.close(); // Create a QObject, install event filter from PaymentServer // and send a file open event to the object QObject object; object.installEventFilter(server); QFileOpenEvent event(f.fileName()); // If sending the event fails, this will cause sigCatcher to be empty, // which will lead to a test failure anyway. QCoreApplication::sendEvent(&object, &event); QObject::disconnect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), &sigCatcher, SLOT(getRecipient(SendCoinsRecipient))); // Return results from sigCatcher return sigCatcher.recipient; }
bool Mailbox::sendItem(Creature* actor, Item* item) { uint32_t depotId = 0; std::string name; if(!getRecipient(item, name, depotId) || name.empty() || !depotId) return false; return IOLoginData::getInstance()->playerMail(actor, name, depotId, item); }
static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsigned char>& data) { RecipientCatcher sigCatcher; QObject::connect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), &sigCatcher, SLOT(getRecipient(SendCoinsRecipient))); // Write data to a temp file: QTemporaryFile f; f.open(); f.write((const char*)&data[0], data.size()); f.close(); // Create a FileOpenEvent and send it directly to the server's event filter: QFileOpenEvent event(f.fileName()); server->eventFilter(NULL, &event); QObject::disconnect(server, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)), &sigCatcher, SLOT(getRecipient(SendCoinsRecipient))); // Return results from sigCatcher return sigCatcher.recipient; }
std::pair<string, int> LoadBalancer::getRecipient(const slobrok::api::IMirrorAPI::SpecList& choices) { std::pair<string, int> retVal("", -1); if (choices.size() == 0) { return retVal; } double weightSum = 0.0; for (uint32_t i = 0; i < choices.size(); i++) { const std::pair<string, string>& curr = choices[i]; uint32_t index = getIndex(curr.first); if (_nodeInfo.size() < (index + 1)) { _nodeInfo.resize(index + 1); } NodeInfo& info = _nodeInfo[index]; info.valid = true; weightSum += info.weight; if (weightSum > _position) { retVal.first = curr.second; retVal.second = index; info.lastSpec = retVal.first; break; } } if (retVal.second == -1) { _position -= weightSum; return getRecipient(choices); } else { _position += 1.0; } return retVal; }