Skip to content

Commit

Permalink
[ssusysinfo] Add variant device handling. Fixes JB#40307
Browse files Browse the repository at this point in the history
Unless explicitly defined, variant device designation, manufacturer
and pretty name are shown as UNKNOWN.

Implement similar fallback to resolving with base model name as what
ssu itself uses.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 3, 2017
1 parent 837b763 commit 50250f1
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 15 deletions.
87 changes: 72 additions & 15 deletions lib/ssusysinfo.c
Expand Up @@ -267,25 +267,52 @@ ssusysinfo_device_model_from_hw_release(ssusysinfo_t *self)
* @param self ssusysinfo object pointer
* @param key key name used in board config ini files
*
* @return c-string, or NULL in case value is not specified
* @return c-string
*/
static const char *
ssusysinfo_device_attr(ssusysinfo_t *self, const char *key)
{
const char *res = 0;
const char *model = 0;
const char *cached = 0;
const char *probed = 0;
const char *model = 0;
const char *base = 0;

if( !self || !self->cfg_ini )
goto EXIT;

if( !(model = ssusysinfo_device_model(self)) )
/* Check if this attr has already been resolved */
if( (cached = inifile_get(self->cfg_ini, "cached-attrs", key, 0)) )
goto EXIT;

res = inifile_get(self->cfg_ini, model, key, 0);
/* Attempt to resolve based on model name */
if( (model = ssusysinfo_device_model(self)) ) {
if( (probed = inifile_get(self->cfg_ini, model, key, 0)) )
goto CACHE;
}

/* In case of variant, attempt to resolve based on base model name */
if( (base = ssusysinfo_device_base_model(self)) ) {
if( (probed = inifile_get(self->cfg_ini, base, key, 0)) )
goto CACHE;
}

/* Use model name as fallback for some attrs */
if( !strcmp(key, "deviceDesignation") || !strcmp(key, "prettyModel") )
probed = model;

/* And as an ultimate fallback select unknown */
if( !probed )
probed = ssusysinfo_unknown;

CACHE:
/* Update the cache so that we do not need to repeat the above
* heuristics the next time */
inifile_set(self->cfg_ini, "cached-attrs", key, (cached = probed));

EXIT:
/* Return valid c-string or NULL on failure */
return res;

/* Always return valid c-string */
return cached ?: ssusysinfo_unknown;
}

/* ------------------------------------------------------------------------- *
Expand Down Expand Up @@ -330,6 +357,38 @@ ssusysinfo_reload(ssusysinfo_t *self)
ssusysinfo_load(self);
}

const char *
ssusysinfo_device_base_model(ssusysinfo_t *self)
{
const char *cached = 0;
const char *probed = 0;

if( !self || !self->cfg_ini )
goto EXIT;

if( (cached = inifile_get(self->cfg_ini, "cached-values", "base_model", 0)) )
goto EXIT;

/* Get model name, which is potentially a variant */
const char *model = ssusysinfo_device_model(self);

/* Lookup base model from [variants] */
if( (probed = inifile_get(self->cfg_ini, "variants", model, 0)) )
goto CACHE;

/* We have data, but were unable to determine base model */
probed = ssusysinfo_unknown;

CACHE:
/* Update the cache so that we do not need to repeat the above
* heuristics the next time */
inifile_set(self->cfg_ini, "cached-values", "base_model", (cached = probed));

EXIT:
/* Always return valid c-string */
return cached ?: ssusysinfo_unknown;
}

const char *
ssusysinfo_device_model(ssusysinfo_t *self)
{
Expand Down Expand Up @@ -372,22 +431,20 @@ ssusysinfo_device_model(ssusysinfo_t *self)
const char *
ssusysinfo_device_designation(ssusysinfo_t *self)
{
/* Always return valid c-string */
return ssusysinfo_device_attr(self,
"deviceDesignation") ?: ssusysinfo_unknown;
/* Always returns valid c-string */
return ssusysinfo_device_attr(self, "deviceDesignation");
}

const char *
ssusysinfo_device_manufacturer(ssusysinfo_t *self)
{
/* Always return valid c-string */
return ssusysinfo_device_attr(self,
"deviceManufacturer") ?: ssusysinfo_unknown;
/* Always returns valid c-string */
return ssusysinfo_device_attr(self, "deviceManufacturer");
}

const char *
ssusysinfo_device_pretty_name(ssusysinfo_t *self)
{
/* Always return valid c-string */
return ssusysinfo_device_attr(self, "prettyModel") ?: ssusysinfo_unknown;
/* Always returns valid c-string */
return ssusysinfo_device_attr(self, "prettyModel");
}
22 changes: 22 additions & 0 deletions lib/ssusysinfo.h
Expand Up @@ -101,6 +101,28 @@ void ssusysinfo_reload (ssusysinfo_t *self);
*/
const char *ssusysinfo_device_model (ssusysinfo_t *self);

/** Query device base model
*
* For variant devices #ssusysinfo_device_model() returns the
* variant name. The name of the base model can be queried
* with this function.
*
* Lookup is done from [variants] section defined in board mappings
*
* Should be functionally equivalent with:
* SsuDeviceInfo::deviceVariant(false)
*
* If the device is not an variant and there is no base model,
* returns "UNKNOWN" - otherwise return values are similar as
* what can be expected from #ssusysinfo_device_model().
*
* @param self ssusysinfo object pointer
*
* @return always returns non-null c-string
*/

const char *ssusysinfo_device_base_model (ssusysinfo_t *self);

/** Query device designation
*
* Type designation, like NCC-1701.
Expand Down

0 comments on commit 50250f1

Please sign in to comment.