Skip to content

Commit

Permalink
[mce] Make tristate_t type generally available. JB#22475
Browse files Browse the repository at this point in the history
Generic "extended boolean" type supporting als "unknown" in
addition to "true" and "false" is useful for dealing with
state data where neither true nor false is suitable for
use as initial value. There already is tristate_t type
that fits the requirement, but it is internal to the
buttonbacklight plugin.

Move tristate_t from plugin to mce core modules so that
it can be utilized anywhere within mce.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Mar 16, 2018
1 parent fe7de61 commit 9aa28fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
14 changes: 14 additions & 0 deletions datapipe.c
Expand Up @@ -1533,6 +1533,7 @@ const char *orientation_state_repr(orientation_state_t state)
return name;
}

/** Translate key state to human readable form */
const char *key_state_repr(key_state_t state)
{
const char *repr = "UNKNOWN";
Expand All @@ -1545,6 +1546,19 @@ const char *key_state_repr(key_state_t state)
return repr;
}

/** Translate tristate to human readable form */
const char *tristate_repr(tristate_t state)
{
const char *repr = "invalid";
switch( state ) {
case TRISTATE_UNKNOWN: repr = "unknown"; break;
case TRISTATE_FALSE: repr = "false"; break;
case TRISTATE_TRUE: repr = "true"; break;
default: break;
}
return repr;
}

/** Lookup table for fpstate_t <--> string */
static const mce_translation_t fpstate_lut[] =
{
Expand Down
10 changes: 10 additions & 0 deletions mce.h
Expand Up @@ -404,6 +404,16 @@ typedef enum {

const char *key_state_repr(key_state_t state);

/** Generic "extended boolean" type */
typedef enum
{
TRISTATE_UNKNOWN = -1,
TRISTATE_FALSE = 0,
TRISTATE_TRUE = 1,
} tristate_t;

const char *tristate_repr(tristate_t state);

/** Fingerprint daemon state */
typedef enum fpstate_t
{
Expand Down
39 changes: 0 additions & 39 deletions modules/buttonbacklight.c
Expand Up @@ -44,31 +44,10 @@
/** Maximum number of concurrent button backlight enabler clients */
#define BBL_MAX_CLIENTS 15

/* ========================================================================= *
* TYPES
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* TRISTATE
* ------------------------------------------------------------------------- */

typedef enum
{
TRISTATE_UNKNOWN = -1,
TRISTATE_FALSE = 0,
TRISTATE_TRUE = 1,
} tristate_t;

/* ========================================================================= *
* PROTOTYPES
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* TRISTATE
* ------------------------------------------------------------------------- */

static const char *tristate_repr (tristate_t state);

/* ------------------------------------------------------------------------- *
* GENRIC_UTILS
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -182,24 +161,6 @@ bbl_write_sysfs(const char *path, const char *data)
TEMP_FAILURE_RETRY(close(fd));
}

/* ========================================================================= *
* TRISTATE
* ========================================================================= */

static const char *
tristate_repr(tristate_t state)
{
const char *repr = "invalid";

switch( state ) {
case TRISTATE_UNKNOWN: repr = "unknown"; break;
case TRISTATE_FALSE: repr = "false"; break;
case TRISTATE_TRUE: repr = "true"; break;
default: break;
}
return repr;
}

/* ========================================================================= *
* BACKLIGHT_STATE
* ========================================================================= */
Expand Down

0 comments on commit 9aa28fd

Please sign in to comment.