Skip to content

Commit

Permalink
[datapipe] Make submode_repr() functions generally available
Browse files Browse the repository at this point in the history
Debugging bitmapped submode changes is made more difficult than
what it needs to be due to bitmap-to-human-readable-string
helper functions being available in modetransition module only.

Move the helper functionality to datapipe module and make it
available for all mce modules.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Oct 6, 2017
1 parent 8aec640 commit fa90d2e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 50 deletions.
69 changes: 69 additions & 0 deletions datapipe.c
Expand Up @@ -939,6 +939,75 @@ void mce_datapipe_quit(void)
free_datapipe(&proximity_blank_pipe);
}

/** Convert submode_t bitmap changes to human readable string
*
* @param prev submode_t bitmap changed from
* @param curr submode_t bitmap changed to
*
* @return human readable representation of submode
*/
const char *submode_change_repr(submode_t prev, submode_t curr)
{
static const struct {
submode_t bit; const char *name;
} lut[] = {
{ MCE_INVALID_SUBMODE, "INVALID" },
{ MCE_TKLOCK_SUBMODE, "TKLOCK" },
{ MCE_EVEATER_SUBMODE, "EVEATER" },
{ MCE_BOOTUP_SUBMODE, "BOOTUP" },
{ MCE_TRANSITION_SUBMODE, "TRANSITION" },
{ MCE_AUTORELOCK_SUBMODE, "AUTORELOCK" },
{ MCE_VISUAL_TKLOCK_SUBMODE, "VISUAL_TKLOCK" },
{ MCE_POCKET_SUBMODE, "POCKET" },
{ MCE_PROXIMITY_TKLOCK_SUBMODE, "PROXIMITY_TKLOCK" },
{ MCE_MALF_SUBMODE, "MALF" },
{ 0,0 }
};

static char buff[128];
char *pos = buff;
char *end = buff + sizeof buff - 1;

auto inline void add(const char *str)
{
while( pos < end && *str )
*pos++ = *str++;
}

for( int i = 0; lut[i].name; ++i ) {
const char *tag = 0;

if( curr & lut[i].bit ) {
tag = (prev & lut[i].bit) ? "" : "+";
}
else if( prev & lut[i].bit ) {
tag = "-";
}

if( tag ) {
if( pos> buff ) add(" ");
add(tag);
add(lut[i].name);
}
}
if( pos == buff ) {
add("NONE");
}
*pos = 0;
return buff;
}

/** Convert submode_t bitmap to human readable string
*
* @param submode submode_t bitmap
*
* @return human readable representation of submode
*/
const char *submode_repr(submode_t submode)
{
return submode_change_repr(submode, submode);
}

/** Convert system_state_t enum to human readable string
*
* @param state system_state_t enumeration value
Expand Down
3 changes: 3 additions & 0 deletions mce.h
Expand Up @@ -170,6 +170,9 @@ const char *alarm_state_repr(alarm_ui_state_t state);
/** System sub-modes; several of these can be active at once */
typedef gint submode_t;

const char *submode_change_repr(submode_t prev, submode_t curr);
const char *submode_repr(submode_t submode);

/** Submode invalid */
#define MCE_INVALID_SUBMODE (1 << 31)

Expand Down
52 changes: 2 additions & 50 deletions modetransition.c
Expand Up @@ -33,51 +33,6 @@

#include <glib/gstdio.h>

/** Submode change in human readable form
*/
static char *mce_submode_change(const submode_t prev, const submode_t curr)
{
static const struct {
submode_t bit; const char *name;
} lut[] = {
{ MCE_INVALID_SUBMODE, "INVALID" },
{ MCE_TKLOCK_SUBMODE, "TKLOCK" },
{ MCE_EVEATER_SUBMODE, "EVEATER" },
{ MCE_BOOTUP_SUBMODE, "BOOTUP" },
{ MCE_TRANSITION_SUBMODE, "TRANSITION" },
{ MCE_AUTORELOCK_SUBMODE, "AUTORELOCK" },
{ MCE_VISUAL_TKLOCK_SUBMODE, "VISUAL_TKLOCK" },
{ MCE_POCKET_SUBMODE, "POCKET" },
{ MCE_PROXIMITY_TKLOCK_SUBMODE, "PROXIMITY_TKLOCK" },
{ MCE_MALF_SUBMODE, "MALF" },
{ 0,0 }
};

char temp[256], *pos = temp;

*pos = 0;
for( int i = 0; lut[i].name; ++i ) {
const char *tag = 0;

if( curr & lut[i].bit ) {
tag = (prev & lut[i].bit) ? "" : "+";
}
else if( prev & lut[i].bit ) {
tag = "-";
}
if( tag ) {
if( pos > temp ) *pos++ = ' ';
pos = stpcpy(pos, tag);
pos = stpcpy(pos, lut[i].name);
}
}
if( pos == temp ) {
pos = stpcpy(pos, "NORMAL");
}
*pos = 0;
return strdup(temp);
}

/**
* Set the MCE submode flags
*
Expand All @@ -91,11 +46,8 @@ static gboolean mce_set_submode_int32(const submode_t submode)
if (old_submode == submode)
goto EXIT;

if( mce_log_p(LL_NOTICE) ) {
char *delta = mce_submode_change(old_submode, submode);
mce_log(LL_NOTICE, "submode change: %s", delta ?: "???");
free(delta);
}
mce_log(LL_NOTICE, "submode change: %s",
submode_change_repr(old_submode, submode));

execute_datapipe(&submode_pipe, GINT_TO_POINTER(submode),
USE_INDATA, CACHE_INDATA);
Expand Down

0 comments on commit fa90d2e

Please sign in to comment.