Symbian进程间通信 消息队列
2010-07-21 04:17:00 来源:WEB开发网_LIT(KGlobalQName, "MyGlobalQ");
const TInt KNumberOfMsgs = 10;
RMsgQueue
TInt ret = msgq.CreateGlobal(KGlobalQName, KNumberOfMsgs, EOwnerProcess);
Creating a local message queue is also similar, as shown below:
const TInt KNumberOfMsgs = 2;
RMsgQueue
TInt ret = msgq.CreateLocal(KNumberOfMsgs, EOwnerProcess);
Sending data to the Queue
Using the message queue handle, a message is sent to a queue by calling Send() or SendBlocking().
Here, if the queue is full, Send() returns the error code KErrOverflow and SendBlocking() waits until there is space available in the queue.
The following code creates a global queue and sends 2 integer to values to it. To demonstrate the usage of both Send() and SendBlocking(); the first call to Send() returns an error if the queue is full, the call to SendBlocking() waits until there is space in the queue.
_LIT(KGlobalQName, "GlobalMsgQ");
RMsgQueue
//Create a global Queue
TInt ret = msgqueue.CreateGlobal(KGlobalQName,1);
if (ret == KErrNone) //If creation is success
{
//Using Send()
TInt value = 100;
//KErrNone, if Send() successful; KErrOverflow, if queue is full
ret = msgqueue.Send(&value);
//Using SendBlocking()
value = 200;
msgqueue.SendBlocking(&value);
}
Receiving Messages from the Queue
Using the message queue handle, a message is received from a message queue by calling Receive() or ReceiveBlocking(). Receive() returns the error code KErrUnderflow if the queue is empty, ReceiveBlocking() waits until there is data
更多精彩
赞助商链接