mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-09 22:48:27 +00:00
ipcIService should be completely scriptable
This commit is contained in:
parent
a4e2003ed8
commit
f88f4c00f4
@ -152,10 +152,11 @@ interface ipcIService : nsISupports
|
||||
* @param aData the message data.
|
||||
* @param aDataLen the message length.
|
||||
*/
|
||||
[noscript] void sendMessage(in unsigned long aClientID,
|
||||
in nsIDRef aTarget,
|
||||
in string aData,
|
||||
in unsigned long aDataLen);
|
||||
void sendMessage(in unsigned long aClientID,
|
||||
in nsIDRef aTarget,
|
||||
[array, const, size_is(aDataLen)]
|
||||
in octet aData,
|
||||
in unsigned long aDataLen);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e40a4a3c-2dc1-470e-ab7f-5675fe1f1384)]
|
||||
@ -169,9 +170,10 @@ interface ipcIMessageObserver : nsISupports
|
||||
* @param aData the data of the message.
|
||||
* @param aDataLen the data length of the message.
|
||||
*/
|
||||
[noscript] void onMessageAvailable(in nsIDRef aTarget,
|
||||
in string aData,
|
||||
in unsigned long aDataLen);
|
||||
void onMessageAvailable(in nsIDRef aTarget,
|
||||
[array, const, size_is(aDataLen)]
|
||||
in octet aData,
|
||||
in unsigned long aDataLen);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e858d450-62b2-482d-99bb-3b5425aa28cc)]
|
||||
@ -200,7 +202,7 @@ interface ipcIClientObserver : nsISupports
|
||||
* @param aStatus client status (e.g. CLIENT_UP).
|
||||
*/
|
||||
void onClientStatus(in unsigned long aRequestToken,
|
||||
in unsigned long aStatus,
|
||||
in unsigned long aClientStatus,
|
||||
in unsigned long aClientID,
|
||||
in ipcIClientInfo aClientInfo);
|
||||
|
||||
|
@ -320,7 +320,7 @@ ipcService::SetMessageObserver(const nsID &target, ipcIMessageObserver *observer
|
||||
NS_IMETHODIMP
|
||||
ipcService::SendMessage(PRUint32 clientID,
|
||||
const nsID &target,
|
||||
const char *data,
|
||||
const PRUint8 *data,
|
||||
PRUint32 dataLen)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTransport, NS_ERROR_NOT_INITIALIZED);
|
||||
@ -332,9 +332,9 @@ ipcService::SendMessage(PRUint32 clientID,
|
||||
|
||||
ipcMessage *msg;
|
||||
if (clientID)
|
||||
msg = new ipcmMessageForward(clientID, target, data, dataLen);
|
||||
msg = new ipcmMessageForward(clientID, target, (const char *) data, dataLen);
|
||||
else
|
||||
msg = new ipcMessage(target, data, dataLen);
|
||||
msg = new ipcMessage(target, (const char *) data, dataLen);
|
||||
|
||||
if (!msg)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@ -406,7 +406,7 @@ ipcService::OnMessageAvailable(const ipcMessage *msg)
|
||||
ipcIMessageObserver *observer = (ipcIMessageObserver *) mObserverDB.Get(&key);
|
||||
if (observer)
|
||||
observer->OnMessageAvailable(msg->Target(),
|
||||
msg->Data(),
|
||||
(const PRUint8 *) msg->Data(),
|
||||
msg->DataLen());
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,15 @@ static PRBool gKeepRunning = PR_TRUE;
|
||||
//static PRInt32 gMsgCount = 0;
|
||||
static ipcIService *gIpcServ = nsnull;
|
||||
|
||||
static void
|
||||
SendMsg(ipcIService *ipc, PRUint32 cID, const nsID &target, const char *data, PRUint32 dataLen)
|
||||
{
|
||||
printf("*** sending message: [to-client=%u dataLen=%u]\n", cID, dataLen);
|
||||
|
||||
ipc->SendMessage(cID, target, (const PRUint8 *) data, dataLen);
|
||||
// gMsgCount++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class myIpcMessageObserver : public ipcIMessageObserver
|
||||
@ -79,9 +88,9 @@ public:
|
||||
NS_IMPL_ISUPPORTS1(myIpcMessageObserver, ipcIMessageObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
myIpcMessageObserver::OnMessageAvailable(const nsID &target, const char *data, PRUint32 dataLen)
|
||||
myIpcMessageObserver::OnMessageAvailable(const nsID &target, const PRUint8 *data, PRUint32 dataLen)
|
||||
{
|
||||
printf("*** got message: [%s]\n", data);
|
||||
printf("*** got message: [%s]\n", (const char *) data);
|
||||
|
||||
// if (--gMsgCount == 0)
|
||||
// gKeepRunning = PR_FALSE;
|
||||
@ -118,7 +127,7 @@ myIpcClientObserver::OnClientStatus(PRUint32 aReqToken,
|
||||
printf("*** name:%s --> ID:%u\n", cName.get(), aClientID);
|
||||
}
|
||||
const char hello[] = "hello friend!";
|
||||
gIpcServ->SendMessage(aClientID, kTestTargetID, hello, sizeof(hello));
|
||||
SendMsg(gIpcServ, aClientID, kTestTargetID, hello, sizeof(hello));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -126,14 +135,6 @@ myIpcClientObserver::OnClientStatus(PRUint32 aReqToken,
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SendMsg(ipcIService *ipc, const nsID &target, const char *data, PRUint32 dataLen)
|
||||
{
|
||||
printf("*** sending message: [dataLen=%u]\n", dataLen);
|
||||
|
||||
ipc->SendMessage(0, target, data, dataLen);
|
||||
// gMsgCount++;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
nsresult rv;
|
||||
@ -235,7 +236,7 @@ int main(int argc, char **argv)
|
||||
"58 this is a really long message.\n"
|
||||
"59 this is a really long message.\n"
|
||||
"60 this is a really long message.\n";
|
||||
SendMsg(ipcServ, kTestTargetID, data, strlen(data)+1);
|
||||
SendMsg(ipcServ, 0, kTestTargetID, data, strlen(data)+1);
|
||||
|
||||
PRUint32 reqToken;
|
||||
nsCOMPtr<ipcIClientObserver> obs(new myIpcClientObserver());
|
||||
|
Loading…
Reference in New Issue
Block a user