本文整理汇总了C++中MessageID::toInt方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageID::toInt方法的具体用法?C++ MessageID::toInt怎么用?C++ MessageID::toInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageID
的用法示例。
在下文中一共展示了MessageID::toInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendOutgoingMessage
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments)
{
ASSERT(m_socket);
// We put the message ID last.
arguments->encodeUInt32(messageID.toInt());
size_t bufferSize = arguments->bufferSize();
// Write message size first
// FIXME: Should just do a single write.
qint64 bytesWrittenForSize = m_socket->write(reinterpret_cast<char*>(&bufferSize), sizeof(bufferSize));
if (bytesWrittenForSize != sizeof(bufferSize)) {
connectionDidClose();
return false;
}
qint64 bytesWrittenForBuffer = m_socket->write(reinterpret_cast<char*>(arguments->buffer()), arguments->bufferSize());
if (bytesWrittenForBuffer != arguments->bufferSize()) {
connectionDidClose();
return false;
}
m_socket->flush();
return true;
}
示例2: locker
std::auto_ptr<ArgumentDecoder> Connection::waitForMessage(MessageID messageID, uint64_t destinationID, double timeout)
{
// First, check if this message is already in the incoming messages queue.
{
MutexLocker locker(m_incomingMessagesLock);
for (size_t i = 0; i < m_incomingMessages.size(); ++i) {
const IncomingMessage& message = m_incomingMessages[i];
if (equalIgnoringFlags(message.messageID(), messageID) && message.arguments()->destinationID() == destinationID) {
std::auto_ptr<ArgumentDecoder> arguments(message.arguments());
// Erase the incoming message.
m_incomingMessages.remove(i);
return arguments;
}
}
}
double absoluteTime = currentTime() + timeout;
std::pair<unsigned, uint64_t> messageAndDestination(std::make_pair(messageID.toInt(), destinationID));
{
MutexLocker locker(m_waitForMessageMutex);
// We don't support having multiple clients wait for the same message.
ASSERT(!m_waitForMessageMap.contains(messageAndDestination));
// Insert our pending wait.
m_waitForMessageMap.set(messageAndDestination, 0);
}
bool timedOut = false;
// Now wait for it to be set.
while (!timedOut) {
MutexLocker locker(m_waitForMessageMutex);
HashMap<std::pair<unsigned, uint64_t>, ArgumentDecoder*>::iterator it = m_waitForMessageMap.find(messageAndDestination);
if (it->second) {
std::auto_ptr<ArgumentDecoder> arguments(it->second);
m_waitForMessageMap.remove(it);
return arguments;
}
// We didn't find it, keep waiting.
timedOut = !m_waitForMessageCondition.timedWait(m_waitForMessageMutex, absoluteTime);
}
// We timed out, now remove the pending wait.
{
MutexLocker locker(m_waitForMessageMutex);
m_waitForMessageMap.remove(messageAndDestination);
}
return std::auto_ptr<ArgumentDecoder>();
}
示例3: sendOutgoingMessage
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<MessageEncoder> encoder)
{
ASSERT(!m_pendingWriteEncoder);
// Just bail if the handle has been closed.
if (m_connectionPipe == INVALID_HANDLE_VALUE)
return false;
// We put the message ID last.
encoder->encode(static_cast<uint32_t>(messageID.toInt()));
// Write the outgoing message.
if (::WriteFile(m_connectionPipe, encoder->buffer(), encoder->bufferSize(), 0, &m_writeState)) {
// We successfully sent this message.
return true;
}
DWORD error = ::GetLastError();
if (error == ERROR_NO_DATA) {
// The pipe is being closed.
connectionDidClose();
return false;
}
if (error != ERROR_IO_PENDING) {
ASSERT_NOT_REACHED();
return false;
}
// The message will be sent soon. Hold onto the encoder so that it won't be destroyed
// before the write completes.
m_pendingWriteEncoder = encoder;
// We can only send one asynchronous message at a time (see comment in platformCanSendOutgoingMessages).
return false;
}
示例4: processIncomingMessage
void Connection::processIncomingMessage(MessageID messageID, std::auto_ptr<ArgumentDecoder> arguments)
{
// First, check if we're waiting for this message.
{
MutexLocker locker(m_waitForMessageMutex);
HashMap<std::pair<unsigned, uint64_t>, ArgumentDecoder*>::iterator it = m_waitForMessageMap.find(std::make_pair(messageID.toInt(), arguments->destinationID()));
if (it != m_waitForMessageMap.end()) {
it->second = arguments.release();
m_waitForMessageCondition.signal();
return;
}
}
if (messageID == MessageID(CoreIPCMessage::SyncMessageReply)) {
// FIXME: We got a reply for another sync message someone sent, handle this.
ASSERT_NOT_REACHED();
}
MutexLocker locker(m_incomingMessagesLock);
m_incomingMessages.append(IncomingMessage(messageID, arguments));
m_clientRunLoop->scheduleWork(WorkItem::create(this, &Connection::dispatchMessages));
}
示例5: processIncomingMessage
void Connection::processIncomingMessage(MessageID messageID, PassOwnPtr<ArgumentDecoder> arguments)
{
// Check if this is a sync reply.
if (messageID == MessageID(CoreIPCMessage::SyncMessageReply)) {
MutexLocker locker(m_pendingSyncRepliesMutex);
ASSERT(!m_pendingSyncReplies.isEmpty());
PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
ASSERT(pendingSyncReply.syncRequestID == arguments->destinationID());
pendingSyncReply.replyDecoder = arguments.leakPtr();
pendingSyncReply.didReceiveReply = true;
m_waitForSyncReplySemaphore.signal();
return;
}
// Check if we're waiting for this message.
{
MutexLocker locker(m_waitForMessageMutex);
HashMap<std::pair<unsigned, uint64_t>, ArgumentDecoder*>::iterator it = m_waitForMessageMap.find(std::make_pair(messageID.toInt(), arguments->destinationID()));
if (it != m_waitForMessageMap.end()) {
it->second = arguments.leakPtr();
m_waitForMessageCondition.signal();
return;
}
}
MutexLocker locker(m_incomingMessagesLock);
m_incomingMessages.append(IncomingMessage(messageID, arguments));
m_clientRunLoop->scheduleWork(WorkItem::create(this, &Connection::dispatchMessages));
}