Languages

Menu
Sites
Language
IPC MessagePort Communication

Hi,

I referred Uni-Directional Port communication (https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.appprogramming/html/tutorials/io_tutorial/unidirection_messageport.htm) and built a small application (implementing send/receive over ports).

I'm not able to receive messages in the receiver application.

I have done the following:

- Created a UI application to act as sender (This app ports the message using RemoteMessgaePort::SendMessage api)

- Another Service app (background application without UI) acts as receiver and receives the message in OnMessageReceivedN() as it inherits from IMessagePortListener

The problem I'm facing is, the messge gets sent (the last result is E_SUCCESS till SendMessage), but it is never received in the Receiver Application. The log inside OnMessageReceivedN never gets printed.

Please help me this. Where am I going wrong?Are there some manifest file changes or privileges to be added?

Kindly help me with this.

Thanks,
Priya

 

 

 

 

 

Responses

17 Replies
Alex Ashirov

Hi,

Did you register your IMessagePortListener with RequestLocalMessagePort::AddMessagePortListener() in the service app?

 

Sathya Priya R

Hi Alex,

Yes. I have done it in OnAppInitializing() method of the service app.

What could be missing yet?

Thanks,

Priya


 

Sathya Priya R

Any inputs?

Alex Ashirov

Hi,

Does MessagePortManager::RequestRemoteMessagePort() return non-Null value?

Sathya Priya R

Yes. It does return a non-null value.

Thanks

 

Alex Ashirov

Hi,

Have you solved the issue? If it still doesn’t work, could you please share your code snippet and I will take a look and try to help you.

Sathya Priya R
/*1.Code from the UI application which send data*/
/*****MsgPortCommSend.h***********/
class MsgPortCommSend
    : public Tizen::Base::Object
{
public:
	MsgPortCommSend();
	void SendPortMsg();
	void SetPorts();
private:
      Tizen::Io::LocalMessagePort* __pLocalMessagePort;
      Tizen::Io::RemoteMessagePort* __pRemoteMessagePort;
};

/*****MsgPortCommSend.cpp***********/
#include "MsgPortCommSend.h"

using namespace Tizen::Base::Collection;
using namespace Tizen::Base;

MsgPortCommSend::MsgPortCommSend(){
    __pLocalMessagePort = null;
	__pRemoteMessagePort = null;
}

void MsgPortCommSend::SetPorts() {
	ClearLastResult();
	__pRemoteMessagePort = MessagePortManager::RequestRemoteMessagePort("thJsXeoO2C.ServiceApp1",L"PortA");//(L"eijfDclFjT.Callee", L"PortA");//(L"8g7i89NTAQ.UniDirCommReceiver", L"PortA");
	result r = GetLastResult();
	AppLog("Hi %s RemotePort address %p",GetErrorMessage(r),__pRemoteMessagePort);
	AppLog("At address %p",MessagePortManager::RequestRemoteMessagePort("thJsXeoO2C.ServiceApp1",L"PortA"));
}

void MsgPortCommSend::SendPortMsg() {
	AppLog("SendPortMsg Start");
	
    HashMap* pMap = new HashMap(SingleObjectDeleter);
	pMap->Construct();
	pMap->Add(new String(L"Key data"), new String(L"Value data"));
	result r = __pRemoteMessagePort->SendMessage(pMap);
	AppLog("SendMessage %s", GetErrorMessage(r));
	delete pMap;
}

//MainForm.cpp
void
UniDirCommSenderMainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
{
    SceneManager* pSceneManager = SceneManager::GetInstance();
	AppAssert(pSceneManager);

	switch(actionId)
	{
	case IDA_BUTTON1: {
			AppLog("Send Button is clicked!");
			Tizen::App::UiApp::GetInstance()->GetAppFrame()->GetFrame()->SetShowMode(Tizen::Ui::Controls::FRAME_SHOW_MODE_MINIMIZED);
			//Send msg to the port
			MsgPortCommSend* msgPort = new MsgPortCommSend();
			msgPort->SetPorts();
			msgPort->SendPortMsg();
		}break;
	default:
		break;
	}
}

//Code the background service app which receives data
/****SampleMessagePort.h******/
class SampleMessagePort
    : public Tizen::Io::IMessagePortListener
{
public :
	SampleMessagePort(void);

	~SampleMessagePort(void);

	result Construct(const Tizen::Base::String& localPortName);

	virtual void OnMessageReceivedN(Tizen::Io::RemoteMessagePort* pRemoteMessagePort, Tizen::Base::Collection::IMap* pMessage);

	//result SendMessage(const Tizen::Base::Collection::IMap* pMessage);

private :
	Tizen::Io::LocalMessagePort* __pLocalMessagePort;
	Tizen::Io::RemoteMessagePort* __pRemoteMessagePort;
};

/***SampleMessagePort.cpp******/
SampleMessagePort::SampleMessagePort(void)
    : __pLocalMessagePort(null)
	, __pRemoteMessagePort(null)
{
}

SampleMessagePort::~SampleMessagePort(void)
{
}

result
SampleMessagePort::Construct(const String& localPortName)
{
	result r = E_SUCCESS;

	__pLocalMessagePort = MessagePortManager::RequestLocalMessagePort(localPortName);

	TryReturn(__pLocalMessagePort != null, E_FAILURE, "SampleServiceApp : [E_FAILURE] Failed to get LocalMessagePort instance.");

	__pLocalMessagePort->AddMessagePortListener(*this);

	AppLog("SampleServiceApp : LocalMessagePort is ready.");

	return r;
}

void
SampleMessagePort::OnMessageReceivedN(RemoteMessagePort* pRemoteMessagePort, IMap* pMessage)
{
	AppLog("Received Messages!");
}

//ServiceApp.cpp (mainclass)

bool
ServiceApp1App::OnAppInitializing(AppRegistry& appRegistry)
{
    // Initialize ServerChannel
	AppLog("SampleServiceApp::OnAppInitializing is called.");
	result r = E_SUCCESS;
	__pMessagePort = new (std::nothrow) SampleMessagePort();
	TryReturn(__pMessagePort != null, false,
			"SampleServiceApp : [E_FAILURE] Failed to create __pMessagePort.");
	AppLog("SampleServiceApp : __pMessagePort is created.");

	r = __pMessagePort->Construct(LOCAL_MESSAGE_PORT_NAME);
	TryReturn(IsFailed(r) != true, r,
			"SampleServiceApp : [%s] Failed to construct __pMessagePort", GetErrorMessage(r));
	AppLog("SampleServiceApp : __pMessagePort is constructed.");

	return true;
}

Thanks Alex!

Nope. I haven't solved the problem yet.

Sure. Will share the code snippet. (I referred MultiProcAppUi example available in the SDK)

I have two applications -

1. ServiceApp1 (Service Application that runs in the background and listens for data)

2.UniDirectionalSender (the app which sends data)

When ServiceApp runs in the debug mode, I open the other app and click on a button called "Send" which sends sample data.

Until this points everything works fine.

Later the sent msg has to reach the OnMessageReceivedN of ServiceApp which doesn't happen.

Kindly have a look at the code.

Thanks,

Priya

 

 

 

 

Alex Ashirov

Hi,

I am taking a look at your code. Is LOCAL_MESSAGE_PORT_NAME equal to L"PortA"? Also, could you please share logs output from the both applications.

Sathya Priya R

Hi Alex,

Yes.

static const wchar_t* LOCAL_MESSAGE_PORT_NAME = L"PortA";

Below are the Logs :

07-08 18:15:58.769 : INFO / ServiceApp1 ( 2533 : 2533 ) : int OspMain(int, char **)(20) > Application started.
07-08 18:16:04.719 : INFO / ServiceApp1 ( 2533 : 2533 ) : virtual bool ServiceApp1App::OnAppInitializing(Tizen::App::AppRegistry &)(37) > SampleServiceApp::OnAppInitializing is called.
07-08 18:16:04.719 : INFO / ServiceApp1 ( 2533 : 2533 ) : virtual bool ServiceApp1App::OnAppInitializing(Tizen::App::AppRegistry &)(42) > SampleServiceApp : __pMessagePort is created.
07-08 18:16:04.729 : INFO / ServiceApp1 ( 2533 : 2533 ) : result SampleMessagePort::Construct(const Tizen::Base::String &)(30) > SampleServiceApp : LocalMessagePort is ready.
07-08 18:16:04.739 : INFO / ServiceApp1 ( 2533 : 2533 ) : virtual bool ServiceApp1App::OnAppInitializing(Tizen::App::AppRegistry &)(47) > SampleServiceApp : __pMessagePort is constructed.
07-08 18:16:11.259 : INFO / UniDirCommSender ( 2534 : 2534 ) : int OspMain(int, char **)(21) > Application started.
07-08 18:16:14.739 : INFO / UniDirCommSender ( 2534 : 2534 ) : virtual void UniDirCommSenderMainForm::OnActionPerformed(const Tizen::Ui::Control &, int)(92) > Send Button is clicked!
07-08 18:16:14.769 : INFO / UniDirCommSender ( 2534 : 2534 ) : void MsgPortCommSend::SetPorts()(22) > Hi E_SUCCESS RemotePort address 0x97d89e8
07-08 18:16:14.769 : INFO / UniDirCommSender ( 2534 : 2534 ) : void MsgPortCommSend::SetPorts()(23) > At address 0x97d89e8
07-08 18:16:14.779 : INFO / UniDirCommSender ( 2534 : 2534 ) : void MsgPortCommSend::SendPortMsg()(27) > SendPortMsg Start
07-08 18:16:14.789 : INFO / UniDirCommSender ( 2534 : 2534 ) : void MsgPortCommSend::SendPortMsg()(41) > SendMessage E_SUCCESS

I expect another statement "Received Messages!" to also get printed. But that doesn't happen and hence my problem.

Thanks,

Priya

Alex Ashirov

Hi,

Your source code and logs seems to be ok. I can only suggest you to move

msgPort->SetPorts();

from the UniDirCommSenderMainForm::OnActionPerformed() to UniDirCommSenderMainForm::OnInitializing ()

Also, I hope that your service app name is exactly “ServiceApp1” with AppId “thJsXeoO2C”.

Sathya Priya R

Thanks Alex.

Sure. Will try the same and let you know the result.

And Yes, you are right on the AppId and app name.

Thanks,

Priya

Alex Ashirov

Hi,

Have you solved the problem?

Sathya Priya R

Hi Alex,

No. I tried all possible ways as I could and still Uni-direction way of port communication didn't work.

But I was able to get Bi-directional message port commuication working as expected.

So implemented and used it.

Thanks.

 

 

 

Alex Ashirov

Hi,

Good news! It’s good that everything works now, but I have just taken a look at your code once again and it seems that I figured out what was wrong. As far as I understand you had to use

void  OnMessageReceivedN (Tizen::Base::Collection::IMap *pMessage)

for unidirectional communication instead of

Void OnMessageReceivedN (RemoteMessagePort *pRemoteMessagePort, Tizen::Base::Collection::IMap *pMessage)

which is intended for bidirectional communication. The second one will never be called for the unidirectional communication.

Sathya Priya R

Hi Alex,

Thank u!

I tried changing the callback as you had mentioned.

Even then it is not working!

Zoltan Puski

Tizen -> Samples -> MultiProcServiceApp
 

Sathya Priya R

Hi Zoltan Puski,

Thanks for the comment.

I had already referred MultiProcServiceApp and MultiProcUiApp sample.

I was not able to import the project in the Tizen IDE as such and build them to see the output.

Hence referred the code of required files and implemented my app.

As mentionred already, sending data thorugh the port works fine.

But receiving this data by the class implementing IMessagePortListener doesn't happen.

Thanks,

Priya