Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
boot225
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook
My Carrier: Rogers

Invocation data memory space

Hi there,

 

I am developing a pair of apps, such as app1 sends an invocation to app2:

 

<code>

const char* message = "The message payload";

navigator_invoke_invocation_t *request = 0;
navigator_invoke_invocation_create(&request);
navigator_invoke_invocation_set_action(request, "bb.action.OPEN");
navigator_invoke_invocation_set_target(request, target);
navigator_invoke_invocation_set_type(request, "text/plain");
navigator_invoke_invocation_set_uri(request, "data&colon;//local");
navigator_invoke_invocation_set_data(request, message, strlen(message)+1);
navigator_invoke_invocation_send(request);
navigator_invoke_invocation_destroy(request);

</code>

 

Q1: Is it save to send a pointer like that to another application's memory space?

Q2: Do i have to malloc/free the data?

Q3: Is the data going to be mem-copied, or is it in a shared memory block?

 

Thanks!

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Invocation data memory space

The invocation data is passed to the other app through various serialization mechanisms provides by the system. There's no need to worry about pointers, memory allocation, etc, as far as the other app goes. If you allocate the data locally, you can and should free it up after you've made the appropriate calls here, or at whatever time the documentation tells you you can (if it says anything on the matter).

The apps do not have any shared memory space either, and don't run in the same process.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
BBSJdev
Posts: 5,948
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: Invocation data memory space

[ Edited ]

boot225,

 

Definitely, definitely not!

 

Now I don't know a lot about how the QNX OS has been implemented but I do know a lot about how modern OSs are implemented on ARM chips.  The days of a memory access actually accessing a real location are long gone, each app will be running in its own virtual memory map, so an identical memory address in two different apps will not be mapped to the same location on the memory chip.  You are not actually passing the pointer between apps though with this function.

 

To pass data between apps you must use the invocation framework of passing the data in the data attribute (under 16K) of the invocation request or passing the location of the data, i.e. a file location, web page address, etc., this definitely does not mean memory locations.

 

Read this to understand how to pass data safely between apps...

 

http://developer.blackberry.com/native/documentation/bb10/data_transfer.html#in-band_transfer

 

[edit] took me so long to write that Peter got his in first :smileyhappy:


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Contributor
boot225
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook
My Carrier: Rogers

Re: Invocation data memory space

[ Edited ]

Thanks Peter, BBSJdev 

That is initially what I thought, however my test fails and that is why I think something might be wrong in relation to memory space. Here is what I am doing:

 

app1 continuously sending messages "test1", "test2", "test3" ... on button click.

app2 receiving and returning the same message back to app1 (aka echo "service")

app1 receiving those messages from app2 is displaying them for debugging.

 

Now, the result is _weird_. I always see the first message received back, then usually starting from the second attempt, the message is delivered but not returned!

 

app2 is using the data pointer for retrieving and re-sending the information:

const char* data = (const char*)navigator_invoke_invocation_get_data(invoke);

...

navigator_invoke_invocation_set_data(reply, data, strlen(data)+1);

 

Basically, I have the same helper method used to send invocation in both app's and it definately works.

 

 

 

Please use plain text.
Contributor
boot225
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook
My Carrier: Rogers

Re: Invocation data memory space

[ Edited ]

The sending helper:

 

void sendInvocationMessageTo(const char* target, const char* message) {
navigator_invoke_invocation_t *request = 0;
navigator_invoke_invocation_create(&request);
navigator_invoke_invocation_set_action(request, "bb.action.OPEN");
navigator_invoke_invocation_set_target(request, target);
navigator_invoke_invocation_set_type(request, "text/plain");
navigator_invoke_invocation_set_uri(request, "data&colon;//local");
navigator_invoke_invocation_set_data(request, message, strlen(message)+1);
navigator_invoke_invocation_send(request);
navigator_invoke_invocation_destroy(request);
}

Please use plain text.
Contributor
boot225
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook
My Carrier: Rogers

Re: Invocation data memory space

One last detail -- if i close app2 after each iteration, i always receive the next message. So it seems invocation mechanism kind of expects the recipient to do its work and then close?

 

I am puzzled :smileyhappy:

Please use plain text.
Developer
BBSJdev
Posts: 5,948
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: Invocation data memory space

[ Edited ]

I can only speak from the cascades side unfortunately but what you write is kind of true.

 

The invocation framework expects to send the invoke request to an app, start it up then have the invoked app closed down and control returned to the invoker.

 

If the app is already running then you need to look for the invoked signal coming in and act accordingly then return the invoked app to the point where it got interrupted but then return control to the invoker.

 

Could it be a case of you not looking for the signal while the app is actually running?

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Contributor
boot225
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook
My Carrier: Rogers

Re: Invocation data memory space

I think i got it:

 

Quite simply, when the app is not in FOREGROUND, it will be unable to send the invocation (at least using the function above).

 

With that, I think I've finished my options for implementing interprocess communication in Blackberry 10 OS.

 

Thanks!

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Invocation data memory space

Try using simple sockets for IPC.

Please use plain text.