Get my app version in c/c++ code

Hi,

I tried this:

le_cfg_QuickGetString(“/apps/appname/version”, version, 256, “unknown”);

no luck, always unknown

Is there a better way to read app version from adef?

adef:

requires:
{
  configTree:
    {
        [r] .
    }
}

Device: FX30(WP7702)
Firmware Version: SWI9X06Y_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12
Bootloader Version: SWI9X06Y_02.16.06.00 7605a6 jenkins 2018/06/20 17:56:12
MCU Version: 002.009
PRI Revision: 001.000
Carrier PRI Name: GENERIC
Carrier PRI Revision: 001.028_002
Legato version: 18.06.1

You should use the real name of your application, not just appname, unless the name of your application is appname. So, if the name of your application is someApp the code should be something like

char version[256] ;

le_cfg_QuickGetString("/apps/someApp/version", version, sizeof(version), "unknown");

Lets imagine for a minute that i am not a complete idiot and i actually used my real app name (app name is irrelevant to the question) and it still doesn’t work.
What else should i try?

  • If your application is multithreaded, check that the thread calls le_cfg_ConnectService.
  • Check return value of this function, it may clarify the situation
  • Check logs, look for Legato-related errors.
  • Check config tree from shell: config get /apps/someApp/version

Well, most probably, you’ve already took all those steps.

  • Code being called form main thread, i presume le_cfg_ConnectService being called automatically for main thread
  • Always returns LE_OK
  • No error whatsoever in logs
  • It works, returns proper value

Try to grant your application access to the system tree.
For example, in your .adef

requires:
{
  configTree:
    {
        [r] .
        otherApp
    }
}

Tried. As mentioned in my very first post.

adef in your first post looks

requires:
{
  configTree:
    {
        [r] .
    }
}

It grants read access to your own tree, not system tree

Is it some kind of reserved name? Otherwise i don’t understand what should i put there and how it should help.
Sorry i can’t test it right now, problems with my linux machine.

Actually, there are 2 slightly different cases:

  • Sandboxed application
  • Non-sandboxed application

If your application is non-sandboxed, then your original procedure should work, afaik.
In case of sandboxed application, for each application there is its own config tree and you should grant your application access to to those trees. version information is located in system tree, so you should grant access to the system tree.

requires:
{
	configTree:
	{
		[w] .       // I need write access to my configuration data.
		[r] system    // I need read access to system configuration data.
	}
}

But that’s not all. If you’re accessing another tree, you should specify the name of this tree in path argument. So, it should look something like:

char version[256] = "unknown";
le_cfg_QuickGetString("system:/apps/helloWorld/version", version, sizeof(version), version);
1 Like

Yep, it worked!
Thank you very much for your support …and patience :slight_smile:

My pleasure.

Hurmat bilan,
Sasha.

Is there another way to do this? It’s been a while… so hoping.
The manuals specifically say to NOT grant access to system, for security reasons; but then tell us that’s the only way for an application to know its own version. It’s an important piece of trivia… so… hoping there’s a cleaner way.

do you mean this?

root@swi-mdm9x28-wp:~# app  version wifi
wifi 19.02.0.rc3
root@swi-mdm9x28-wp:~# app  version atServerIntegrationTest
atServerIntegrationTest has no version

Those are the details I’m trying to get… from inside my (sandboxed) Legato C code. I was hoping the app_info API would help, but… no.

Have you referred to the code here for “app version”?

BTW, will you consider an easier way to create an unsandboxed application to handle this “app version” and then your sandboxed application can communicate with it via IPC?

The appCtrl code uses same technique: read the system:/apps config tree. So I suppose… that’s how it’s done.
Needing to expose system: just to include a version number in help-about response text… seems there should be a better way. The appinfo API returns a HASH of the version number, but not the version number itself… unsure where that decision came from.

will you consider an easier way to create an unsandboxed application to handle this “app version” and then your sandboxed application can communicate with it via IPC?

IPC plus another application. Might be easier. Perhaps not.
Using “make”, I can achieve the goal without that.

To make the application version available to both Legato and the application itself, I did the following.

  1. I removed the version from ADEF, and put it into a one-line “app.version” file
  2. mkapp then adds it back when building (using the -a parameter)
  3. make also creates an app.version.h file… which will be compiled into the code
    OR
  4. use a -D compile option to add the #define statement using pre-processing

This way, the version number is available to both Legato and my application code. They get the information from different sources, but the answer will be consistent.

I’m a “make” newbie… but here’s my Makefile change. (Listening eagerly for a better alternative.)

$(TARGETS):
	# appVersion=`cat $@.version`; echo -n "#define APPVERSION \"${appVersion}\"" > $@.version.h

mkapp -t wp77xx \
	-i $(LEGATO_ROOT)/interfaces/modemServices \
	-C -DAPPVERSION=\\\"`cat $@.version`\\\" \
	-a `cat $@.version` \
	-a . \
	-a `date +%Y%m%d%H%M` \
	$@.adef