Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make state enum to state name helper functions globally available
In many cases the helpers were created at the module that is primarily
responsive for maintaining the datapipe content and datapipe listeners
do debug logging using the numeric states - which requires effort to
decode.

Move state enum to string helper functions to datapipe.c and list
prototypes in mce.h next to enum type declaration.
  • Loading branch information
spiiroin committed Feb 3, 2015
1 parent f7522c7 commit 67d966c
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 200 deletions.
4 changes: 2 additions & 2 deletions .depend
Expand Up @@ -23,12 +23,14 @@ builtin-gconf.pic.o:\
datapipe.o:\
datapipe.c\
datapipe.h\
mce-lib.h\
mce-log.h\
mce.h\

datapipe.pic.o:\
datapipe.c\
datapipe.h\
mce-lib.h\
mce-log.h\
mce.h\

Expand Down Expand Up @@ -443,7 +445,6 @@ modules/callstate.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce.h\

Expand All @@ -452,7 +453,6 @@ modules/callstate.pic.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce.h\

Expand Down
170 changes: 169 additions & 1 deletion datapipe.c
Expand Up @@ -22,6 +22,9 @@

#include "mce.h"
#include "mce-log.h"
#include "mce-lib.h"

#include <mce/mode-names.h>

#include <linux/input.h>

Expand Down Expand Up @@ -843,7 +846,7 @@ void mce_datapipe_init(void)
setup_datapipe(&ambient_light_sensor_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(400));
setup_datapipe(&orientation_sensor_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(0));
0, GINT_TO_POINTER(MCE_ORIENTATION_UNDEFINED));
setup_datapipe(&tk_lock_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(LOCK_UNDEF));
setup_datapipe(&charger_state_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -1059,6 +1062,171 @@ const char *battery_status_repr(battery_status_t state)
return res;
}

/** Convert alarm_ui_state_t enum to human readable string
*
* @param state alarm_ui_state_t enumeration value
*
* @return human readable representation of state
*/
const char *alarm_state_repr(alarm_ui_state_t state)
{
const char *res = "UNKNOWN";

switch( state ) {
case MCE_ALARM_UI_INVALID_INT32: res = "INVALID"; break;
case MCE_ALARM_UI_OFF_INT32: res = "OFF"; break;
case MCE_ALARM_UI_RINGING_INT32: res = "RINGING"; break;
case MCE_ALARM_UI_VISIBLE_INT32: res = "VISIBLE"; break;
default: break;
}

return res;
}

/** Mapping of call state integer <-> call state string */
static const mce_translation_t call_state_translation[] =
{
{
.number = CALL_STATE_NONE,
.string = MCE_CALL_STATE_NONE
},
{
.number = CALL_STATE_RINGING,
.string = MCE_CALL_STATE_RINGING,
},
{
.number = CALL_STATE_ACTIVE,
.string = MCE_CALL_STATE_ACTIVE,
},
{
.number = CALL_STATE_SERVICE,
.string = MCE_CALL_STATE_SERVICE
},
{ /* MCE_INVALID_TRANSLATION marks the end of this array */
.number = MCE_INVALID_TRANSLATION,
.string = MCE_CALL_STATE_NONE
}
};

/** MCE call state number to string
*/
const char *call_state_repr(call_state_t state)
{
return mce_translate_int_to_string(call_state_translation, state);
}

/** String to MCE call state number */
call_state_t call_state_parse(const char *name)
{
return mce_translate_string_to_int(call_state_translation, name);
}

/** Mapping of call type integer <-> call type string */
static const mce_translation_t call_type_translation[] =
{
{
.number = NORMAL_CALL,
.string = MCE_NORMAL_CALL
},
{
.number = EMERGENCY_CALL,
.string = MCE_EMERGENCY_CALL
},
{ /* MCE_INVALID_TRANSLATION marks the end of this array */
.number = MCE_INVALID_TRANSLATION,
.string = MCE_NORMAL_CALL
}
};

/** MCE call type number to string
*/
const char *call_type_repr(call_type_t type)
{
return mce_translate_int_to_string(call_type_translation, type);
}

/** String to MCE call type number
*/
call_type_t call_type_parse(const char *name)
{
return mce_translate_string_to_int(call_type_translation, name);
}

/** Helper for getting cover_state_t in human readable form
*
* @param state cover state enum value
*
* @return enum name without "COVER_" prefix
*/
const char *cover_state_repr(cover_state_t state)
{
const char *res = "UNKNOWN";
switch( state ) {
case COVER_UNDEF: res = "UNDEF"; break;
case COVER_CLOSED: res = "CLOSED"; break;
case COVER_OPEN: res = "OPEN"; break;
default: break;
}
return res;
}

/** Proximity state enum to human readable string
*
* @param state Cover state enumeration value
*
* @return cover state as human readable proximity state name
*/
const char *proximity_state_repr(cover_state_t state)
{
const char *repr = "unknown";
switch( state ) {
case COVER_UNDEF: repr = "undefined"; break;
case COVER_CLOSED: repr = "covered"; break;
case COVER_OPEN: repr = "not covered"; break;
default:
break;
}
return repr;
}

/** Display state to human readable string
*/
const char *display_state_repr(display_state_t state)
{
const char *repr = "UNKNOWN";

switch( state ) {
case MCE_DISPLAY_UNDEF: repr = "UNDEF"; break;
case MCE_DISPLAY_OFF: repr = "OFF"; break;
case MCE_DISPLAY_LPM_OFF: repr = "LPM_OFF"; break;
case MCE_DISPLAY_LPM_ON: repr = "LPM_ON"; break;
case MCE_DISPLAY_DIM: repr = "DIM"; break;
case MCE_DISPLAY_ON: repr = "ON"; break;
case MCE_DISPLAY_POWER_UP: repr = "POWER_UP"; break;
case MCE_DISPLAY_POWER_DOWN: repr = "POWER_DOWN"; break;
default: break;
}

return repr;
}

/** Translate orientation state to human readable form */
const char *orientation_state_repr(orientation_state_t state)
{
const char *name = "UNKNOWN";
switch( state ) {
case MCE_ORIENTATION_UNDEFINED: name = "UNDEFINED"; break;
case MCE_ORIENTATION_LEFT_UP: name = "LEFT_UP"; break;
case MCE_ORIENTATION_RIGHT_UP: name = "RIGHT_UP"; break;
case MCE_ORIENTATION_BOTTOM_UP: name = "BOTTOM_UP"; break;
case MCE_ORIENTATION_BOTTOM_DOWN: name = "BOTTOM_DOWN"; break;
case MCE_ORIENTATION_FACE_DOWN: name = "FACE_DOWN"; break;
case MCE_ORIENTATION_FACE_UP: name = "FACE_UP"; break;
default: break;
}
return name;
}

void datapipe_handlers_install(datapipe_handler_t *bindings)
{
if( !bindings )
Expand Down
32 changes: 0 additions & 32 deletions event-input.c
Expand Up @@ -89,12 +89,6 @@
* DATA TYPES AND FUNCTION PROTOTYPES
* ========================================================================= */

/* ------------------------------------------------------------------------- *
* MISC_UTIL
* ------------------------------------------------------------------------- */

static const char *proximity_state_repr (cover_state_t state);

/* ------------------------------------------------------------------------- *
* GPIO_KEYS -- N900 camera focus key enable/disable policy
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -422,32 +416,6 @@ static void evin_kp_grab_wanted_cb (gconstpointer d
gboolean mce_input_init (void);
void mce_input_exit (void);

/* ========================================================================= *
* MISC_UTIL
* ========================================================================= */

/** Proximity state enum to human readable string
*
* @param state Cover state enumeration value
*
* @return cover state as human readable proximity state name
*/
static const char *
proximity_state_repr(cover_state_t state)
{
// FIXME: this function should be somewhere else

const char *repr = "unknown";
switch( state ) {
case COVER_UNDEF: repr = "undefined"; break;
case COVER_CLOSED: repr = "covered"; break;
case COVER_OPEN: repr = "not covered"; break;
default:
break;
}
return repr;
}

/* ========================================================================= *
* GPIO_KEYS
* ========================================================================= */
Expand Down
22 changes: 2 additions & 20 deletions mce-sensorfw.c
Expand Up @@ -3094,24 +3094,6 @@ static void (*sfw_notify_als_cb)(unsigned lux) = 0;
/** Orientation change callback used for notifying upper level logic */
static void (*sfw_notify_orient_cb)(int state) = 0;

/** Translate orientation state to human readable form */
static const char *
orientation_state_name(orientation_state_t state)
{
const char *name = "UNKNOWN";
switch( state ) {
case MCE_ORIENTATION_UNDEFINED: name = "UNDEFINED"; break;
case MCE_ORIENTATION_LEFT_UP: name = "LEFT_UP"; break;
case MCE_ORIENTATION_RIGHT_UP: name = "RIGHT_UP"; break;
case MCE_ORIENTATION_BOTTOM_UP: name = "BOTTOM_UP"; break;
case MCE_ORIENTATION_BOTTOM_DOWN: name = "BOTTOM_DOWN"; break;
case MCE_ORIENTATION_FACE_DOWN: name = "FACE_DOWN"; break;
case MCE_ORIENTATION_FACE_UP: name = "FACE_UP"; break;
default: break;
}
return name;
}

/** Translate notification type to human readable form
*/
static const char *
Expand Down Expand Up @@ -3278,8 +3260,8 @@ sfw_notify_orient(sfw_notify_t type, int input_value)

mce_log(LL_DEBUG, "%s: input %s -> notify %s",
sfw_notify_name(type),
orientation_state_name(input_value),
orientation_state_name(output_value));
orientation_state_repr(input_value),
orientation_state_repr(output_value));

sfw_notify_orient_cb(output_value);

Expand Down
12 changes: 0 additions & 12 deletions mce-sensorfw.h
Expand Up @@ -25,18 +25,6 @@ void mce_sensorfw_ps_set_notify(void (*cb)(bool covered));
void mce_sensorfw_ps_enable(void);
void mce_sensorfw_ps_disable(void);

/** These must match with what sensorfw uses */
typedef enum
{
MCE_ORIENTATION_UNDEFINED = 0, /**< Orientation is unknown. */
MCE_ORIENTATION_LEFT_UP = 1, /**< Device left side is up */
MCE_ORIENTATION_RIGHT_UP = 2, /**< Device right side is up */
MCE_ORIENTATION_BOTTOM_UP = 3, /**< Device bottom is up */
MCE_ORIENTATION_BOTTOM_DOWN = 4, /**< Device bottom is down */
MCE_ORIENTATION_FACE_DOWN = 5, /**< Device face is down */
MCE_ORIENTATION_FACE_UP = 6, /**< Device face is up */
} orientation_state_t;

void mce_sensorfw_orient_set_notify(void (*cb)(int state));
void mce_sensorfw_orient_enable(void);
void mce_sensorfw_orient_disable(void);
Expand Down
27 changes: 27 additions & 0 deletions mce.h
Expand Up @@ -118,6 +118,8 @@ typedef enum {
MCE_ALARM_UI_VISIBLE_INT32 = 2,
} alarm_ui_state_t;

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;

Expand Down Expand Up @@ -181,6 +183,9 @@ typedef enum {
CALL_STATE_SERVICE = 3
} call_state_t;

const char *call_state_repr(call_state_t state);
call_state_t call_state_parse(const char *name);

/** Call type */
typedef enum {
/** Invalid call type */
Expand All @@ -191,6 +196,9 @@ typedef enum {
EMERGENCY_CALL = 1
} call_type_t;

const char *call_type_repr(call_type_t type);
call_type_t call_type_parse(const char *name);

/** Display state */
typedef enum {
MCE_DISPLAY_UNDEF = -1, /**< Display state not set */
Expand All @@ -203,13 +211,18 @@ typedef enum {
MCE_DISPLAY_POWER_DOWN, /**< Display is suspending */
} display_state_t;

const char *display_state_repr(display_state_t state);

/** Cover state */
typedef enum {
COVER_UNDEF = -1, /**< Cover state not set */
COVER_CLOSED = 0, /**< Cover is closed */
COVER_OPEN = 1 /**< Cover is open */
} cover_state_t;

const char *cover_state_repr(cover_state_t state);
const char *proximity_state_repr(cover_state_t state);

/** Lock state */
typedef enum {
/** Lock state not set */
Expand Down Expand Up @@ -309,6 +322,20 @@ typedef enum {

const char *service_state_repr(service_state_t state);

/** These must match with what sensorfw uses */
typedef enum
{
MCE_ORIENTATION_UNDEFINED = 0, /**< Orientation is unknown. */
MCE_ORIENTATION_LEFT_UP = 1, /**< Device left side is up */
MCE_ORIENTATION_RIGHT_UP = 2, /**< Device right side is up */
MCE_ORIENTATION_BOTTOM_UP = 3, /**< Device bottom is up */
MCE_ORIENTATION_BOTTOM_DOWN = 4, /**< Device bottom is down */
MCE_ORIENTATION_FACE_DOWN = 5, /**< Device face is down */
MCE_ORIENTATION_FACE_UP = 6, /**< Device face is up */
} orientation_state_t;

const char *orientation_state_repr(orientation_state_t state);

/* XXX: use HAL */

/** Does the device have a flicker key? */
Expand Down

0 comments on commit 67d966c

Please sign in to comment.