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
Developer
helex
Posts: 276
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

recommended way to check if HEADLESS module is running?

Hello Everybody!

 

I wonder what may be the best way to check if my own (long running) headless module is currently running or not.

 


Any Ideas for a safe and resource friendly solution?

 

It should ensure to make my app working the "old way" in case the headless permission was deactivated or the headless module crashed somehow. A "fallback" mechanism.

 

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: recommended way to check if HEADLESS module is running?

Hi

 

there are probably lots of ways you could do this but one would be to use QLocalSocket in the GUI and QLocalServer in the service to create a simple communication pipe between the two parts (GUI and headless service). You can then send an "are you there" message down the pipe and if you get a reply you know the service is running.

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Developer
BBSJdev
Posts: 6,089
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: recommended way to check if HEADLESS module is running?

QSettings is used in the example and that's not too resource intensive.

 

Just out of interest what do you intend to do if it crashed, restart and check again then issue a warning if still not 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.
Developer
helex
Posts: 276
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: recommended way to check if HEADLESS module is running?

I used the QLocalSocket approach at my first try. But it crashed sometimes the headless modul and I had no idea why. Apart from that my headless module needed 4.4 MB of RAM instead of 1.6 MB at the Device Monitor sompared to my current approach.

 


BBSJdev wrote:

QSettings is used in the example and that's not too resource intensive.


 

I were aware of this example, but in my opinion it is not save enough. It only checks if the headless module was running at some point but not if it is currently actively running. Or am I missing something?

 

My current approach is a mixture of invocation and the example with QSettings. But I just use a "IsHeadlessAlive.txt" file.

 

I assume at the startup of my UI part that the headless module is not running and set this to a boolean value. I write a 0 value to this textfile and store the mSecSinceEpoch timestamp locally in a qint64. I invoke my Headless module with a additional filter value I've created. In case it was successfull it writes into this text file itself the current mSecSinceEpoch value which is later or at least the same like in the variable of my UI.

 

I listen to file changes at my UI module after I've written the zero in the file. So it will notice if the file was changed. If the value is >= than at my qint64 I know the headless module is active and working and I store this state at my boolean value. If it is < a second instance of my app (got invoked as a Card) has written a zero value to the file and my app will not act.

 

In case my headless module got somehow stopped it starts this way also itself up and it is working again.

 

What do you think about this method?

 

 


BBSJdev wrote:

Just out of interest what do you intend to do if it crashed, restart and check again then issue a warning if still not running?


 

I would like to make this way a fallback mechanism. In case the headless module is running the data management does the headless module all the time. If it is not running (because it crashed, the user has stopped it or it has eben not the permission to run) my app should take again itself the control of the data management and act like at 10.2.0 firmwares and earlier.
Please use plain text.
Developer
BBSJdev
Posts: 6,089
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: recommended way to check if HEADLESS module is running?

Sorry my friend, I've only just got the long running permission myself a few days ago and haven't really had time to play with it yet.

 

However I thought it does check as on startup it is displaying attached, but as I said I'm still at the stage of working through the example code and template code.


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.
Developer
helex
Posts: 276
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: recommended way to check if HEADLESS module is running?


BBSJdev wrote:

Sorry my friend, I've only just got the long running permission myself a few days ago and haven't really had time to play with it yet.


I'm playing with it since christmas and it is though in the beginning but it is getting slowly better. I've published in the meantime sucsessfully two long running headless apps and I'm waiting currently for the third one to get the approval.

 

Are you able at the moment how long you have waited to get the approval? I applied with my third app at the mid of december.

 


However I thought it does check as on startup it is displaying attached, but as I said I'm still at the stage of working through the example code and template code.


Yeah, the example basically works but I were just unsure if it will work under all contingencies, at example if a second instance of my application was started via card invocation.
Or if the headless module was never running because the user denied the permission. In this case the settings file wouldn't exist. So I can't watch for changes.

If I write something from my UI part in it it will exist but also get informed about changes each time and will find the property for a running headless module. Even if it was canceled 5 minutes ago in the Device Monitor.

 

Nevertheless, I guess I found a for me well working solution. Thanks a lot and good luck with your headless apps! :smileyhappy:

 

Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: recommended way to check if HEADLESS module is running?

In theory you should be able to enumerate the /proc virtual path and examine the processes that are running. You won't have access to all of them, but you should be able to access your headless process as it's running under the same account.

 

You can ls -l /proc too.

 

There are many other low-level inter-process communication methods, including shared memory and PPS objecs. Most are more efficient than writing a file to flash memory...

 

Check out the docs here: 

http://developer.blackberry.com/native/documentation/core/com.qnx.doc.neutrino.prog/topic/process_pr...

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.
BlackBerry Development Advisor (Retired)
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: recommended way to check if HEADLESS module is running?

I have to determine whether or not the GUI counterpart of a headless app is already running or not. I think the technique I'm using should work in the other scenario... with the GUI querying whether or not the headless service is running.

 

I use QProcess to allow me to run pidin -dXXXXXX where XXXXXX is the headless service process name. I then read the stdout channel contents and check to see if there's any evidence of it being in the process list. 

 

Like this:

 

bool Operations::isBlahGuiRunning() {

	qDebug() << "OOOO isBlahGuiRunning";

	QString program = "pidin";
	QStringList arguments;
	arguments << "-pBlah";
	QProcess *pidin = new QProcess(this);
	pidin->setReadChannel(QProcess::StandardOutput);
	pidin->start(program, arguments);

	if (!pidin->waitForStarted())
		return false;

	if (!pidin->waitForFinished())
		return false;

	QByteArray result = pidin->readAllStandardOutput();
	QString pidin_output(result);

	qDebug() << "OOOO pidin:";
	qDebug() << pidin_output;

	if (pidin_output.contains("Blah ")) {
		qDebug() << "OOOO GUI is running:";
		return true;
	} else {
		qDebug() << "OOOO GUI is NOT running:";
		return false;
	}


}

 Hope this works for you

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.