WEB开发网
开发学院手机开发Symbian 开发 Symbian进程间通信 消息队列 阅读

Symbian进程间通信 消息队列

 2010-07-21 04:17:00 来源:WEB开发网   
核心提示:length of the above class(Here it is 8) and with 10 such number of messages._LIT(KGlobalQName, "MyGlobalQ");const TInt KNumberOfMsgs = 10;RMsgQueue ms
length of the above class(Here it is 8) and with 10 such number of messages.

_LIT(KGlobalQName, "MyGlobalQ");

const TInt KNumberOfMsgs = 10;

RMsgQueue msgq;

TInt ret = msgq.CreateGlobal(KGlobalQName, KNumberOfMsgs, EOwnerProcess);

Creating a local message queue is also similar, as shown below:

const TInt KNumberOfMsgs = 2;

RMsgQueue msgq;

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 msgqueue;

//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

Tags:Symbian 进程 通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接