'어플리케이션 간 통신'에 해당되는 글 2건

  1. 2014.01.13 단방향 메세지 포트 통신 처리(Handling Uni-directional Message Port Communication)

출처 : https://developer.tizen.org/dev-guide/2.2.0/org.tizen.native.appprogramming/html/tutorials/io_tutorial/unidirection_messageport.htm


Tizen Native 어플리케이션에서는 단방향 메세지 포트 통신(Uni-directional Message Port Communication)을 이용하여 어플리케이션간에 메세지를 보내고 받을 수 있다.


1. 서버 어플리케이션에서는 Tizen::Io::MessagePortManager클래스에 있는 RequestLocalMessagePort() 메소드를 이용하여 

Tizen::Io::LocalMessagePort클래스 인스턴스를 가져온다. AddMessagePortListener() 메소드는 클라이언트 어플리케이션으로부터 

메세지를 전달받는데 사용된다.

LocalMessagePort* pLocalPort = MessagePortManager::RequestLocalMessagePort(L"PortA");

pLocalPort->AddMessagePortListener(*this);


2. OnMessageReceivedN() 이벤트 핸들러는 클라이언트 어플리케이션으로부터 전달받은 메세지를 처리하는데 사용된다.

void
OnMessageReceivedN(IMap* pMessage)
{
   // Handle received messages from the client

   // Delete messages
   delete pMessage;
}


3. 클라이언트 어플리케이션에서는, Tizen::Io::LocalMessagePort클래스의 RequestRemoteMessagePort() 메소드를 이용하여 

Tizen::Io::RemoteMessagePort클래스 인스턴스를 가져온다.

RemoteMessagePort* pRemotePort = MessagePortManager::RequestRemoteMessagePort(L"123456789.ServerApp", L"PortA");


4. Tizen::Io::RemoteMessagePort클래스의 SendMessage() 메소드를 이용하여 클라이언트 어플리케이션에서 서버 어플리케이션으로 메세지를 전달한다.

void
SendMessage(void)
{
   HashMap* pMap = new HashMap(SingleObjectDeleter);
   pMap->Construct();
   pMap->Add(new String(L"Key data"), new String(L"Value data"));

   pRemotePort->SendMessage(pMap);

   delete pMap;
}


Posted by No names
,