static bool
_manager_set_system_state(void *data, const void *value)
{
    struct ctx *ctx = data;
    const char *str = value;
    bool changed;
    enum sol_platform_state state;
    static const struct sol_str_table table[] = {
        /* systemd differentiates these 2, we don't */
        SOL_STR_TABLE_ITEM("initializing", SOL_PLATFORM_STATE_INITIALIZING),
        SOL_STR_TABLE_ITEM("starting",     SOL_PLATFORM_STATE_INITIALIZING),

        SOL_STR_TABLE_ITEM("running",      SOL_PLATFORM_STATE_RUNNING),
        SOL_STR_TABLE_ITEM("degraded",     SOL_PLATFORM_STATE_DEGRADED),
        SOL_STR_TABLE_ITEM("maintenance",  SOL_PLATFORM_STATE_MAINTENANCE),
        SOL_STR_TABLE_ITEM("stopping",     SOL_PLATFORM_STATE_STOPPING),
        { }
    };

    state = sol_str_table_lookup_fallback(table, sol_str_slice_from_str(str),
        SOL_PLATFORM_SERVICE_STATE_UNKNOWN);
    changed = state != ctx->properties.system_state;
    ctx->properties.system_state = state;

    return changed;
}
示例#2
0
SOL_API enum sol_memdesc_type
sol_memdesc_type_from_str(const char *str)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("uint8_t", SOL_MEMDESC_TYPE_UINT8),
        SOL_STR_TABLE_ITEM("uint16_t", SOL_MEMDESC_TYPE_UINT16),
        SOL_STR_TABLE_ITEM("uint32_t", SOL_MEMDESC_TYPE_UINT32),
        SOL_STR_TABLE_ITEM("uint64_t", SOL_MEMDESC_TYPE_UINT64),
        SOL_STR_TABLE_ITEM("unsigned long", SOL_MEMDESC_TYPE_ULONG),
        SOL_STR_TABLE_ITEM("size_t", SOL_MEMDESC_TYPE_SIZE),
        SOL_STR_TABLE_ITEM("int8_t", SOL_MEMDESC_TYPE_INT8),
        SOL_STR_TABLE_ITEM("int16_t", SOL_MEMDESC_TYPE_INT16),
        SOL_STR_TABLE_ITEM("int32_t", SOL_MEMDESC_TYPE_INT32),
        SOL_STR_TABLE_ITEM("int64_t", SOL_MEMDESC_TYPE_INT64),
        SOL_STR_TABLE_ITEM("long", SOL_MEMDESC_TYPE_LONG),
        SOL_STR_TABLE_ITEM("ssize_t", SOL_MEMDESC_TYPE_SSIZE),
        SOL_STR_TABLE_ITEM("boolean", SOL_MEMDESC_TYPE_BOOLEAN),
        SOL_STR_TABLE_ITEM("double", SOL_MEMDESC_TYPE_DOUBLE),
        SOL_STR_TABLE_ITEM("string", SOL_MEMDESC_TYPE_STRING),
        SOL_STR_TABLE_ITEM("const string", SOL_MEMDESC_TYPE_CONST_STRING),
        SOL_STR_TABLE_ITEM("enumeration", SOL_MEMDESC_TYPE_ENUMERATION),
        SOL_STR_TABLE_ITEM("pointer", SOL_MEMDESC_TYPE_PTR),
        SOL_STR_TABLE_ITEM("structure", SOL_MEMDESC_TYPE_STRUCTURE),
        SOL_STR_TABLE_ITEM("array", SOL_MEMDESC_TYPE_ARRAY),
        { }
    };

    SOL_NULL_CHECK(str, SOL_MEMDESC_TYPE_UNKNOWN);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(str), SOL_MEMDESC_TYPE_UNKNOWN);
}
示例#3
0
/* TODO: Change type description to use the enum and remove this
 * function. */
SOL_API enum sol_flow_node_options_member_type
sol_flow_node_options_member_type_from_string(const char *data_type)
{
    if (!data_type)
        return SOL_FLOW_NODE_OPTIONS_MEMBER_UNKNOWN;
    return sol_str_table_lookup_fallback(member_str_to_type,
    sol_str_slice_from_str(data_type), SOL_FLOW_NODE_OPTIONS_MEMBER_UNKNOWN);
}
示例#4
0
enum sol_bt_transport
sol_bt_transport_from_str(const char *str)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("all", SOL_BT_TRANSPORT_ALL),
        SOL_STR_TABLE_ITEM("le", SOL_BT_TRANSPORT_LE),
        SOL_STR_TABLE_ITEM("bredr", SOL_BT_TRANSPORT_BREDR),
        { },
    };

    return sol_str_table_lookup_fallback(table, sol_str_slice_from_str(str),
        SOL_BT_TRANSPORT_ALL);
}
示例#5
0
SOL_API enum sol_uart_stop_bits
sol_uart_stop_bits_from_str(const char *stop_bits)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("stopbits-1", SOL_UART_STOP_BITS_ONE),
        SOL_STR_TABLE_ITEM("stopbits-2", SOL_UART_STOP_BITS_TWO),
        { }
    };

    SOL_NULL_CHECK(stop_bits, SOL_UART_STOP_BITS_ONE);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(stop_bits), SOL_UART_STOP_BITS_ONE);
}
示例#6
0
SOL_API enum sol_gpio_direction
sol_gpio_direction_from_str(const char *direction)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("out", SOL_GPIO_DIR_OUT),
        SOL_STR_TABLE_ITEM("in", SOL_GPIO_DIR_IN),
        { }
    };

    SOL_NULL_CHECK(direction, SOL_GPIO_DIR_OUT);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(direction), SOL_GPIO_DIR_OUT);
}
示例#7
0
SOL_API enum sol_uart_parity
sol_uart_parity_from_str(const char *parity)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("none", SOL_UART_PARITY_NONE),
        SOL_STR_TABLE_ITEM("even", SOL_UART_PARITY_EVEN),
        SOL_STR_TABLE_ITEM("odd", SOL_UART_PARITY_ODD),
        { }
    };

    SOL_NULL_CHECK(parity, SOL_UART_PARITY_NONE);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(parity), SOL_UART_PARITY_NONE);
}
示例#8
0
SOL_API enum sol_gpio_drive
sol_gpio_drive_from_str(const char *drive)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("none", SOL_GPIO_DRIVE_NONE),
        SOL_STR_TABLE_ITEM("up", SOL_GPIO_DRIVE_PULL_UP),
        SOL_STR_TABLE_ITEM("down", SOL_GPIO_DRIVE_PULL_DOWN),
        { }
    };

    SOL_NULL_CHECK(drive, SOL_GPIO_DRIVE_NONE);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(drive), SOL_GPIO_DRIVE_NONE);
}
示例#9
0
SOL_API enum sol_uart_data_bits
sol_uart_data_bits_from_str(const char *data_bits)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("databits-8", SOL_UART_DATA_BITS_8),
        SOL_STR_TABLE_ITEM("databits-7", SOL_UART_DATA_BITS_7),
        SOL_STR_TABLE_ITEM("databits-6", SOL_UART_DATA_BITS_6),
        SOL_STR_TABLE_ITEM("databits-5", SOL_UART_DATA_BITS_5),
        { }
    };

    SOL_NULL_CHECK(data_bits, SOL_UART_DATA_BITS_8);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(data_bits), SOL_UART_DATA_BITS_8);
}
示例#10
0
SOL_API enum sol_gpio_edge
sol_gpio_edge_from_str(const char *edge)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("none", SOL_GPIO_EDGE_NONE),
        SOL_STR_TABLE_ITEM("rising", SOL_GPIO_EDGE_RISING),
        SOL_STR_TABLE_ITEM("falling", SOL_GPIO_EDGE_FALLING),
        SOL_STR_TABLE_ITEM("any", SOL_GPIO_EDGE_BOTH),
        { }
    };

    SOL_NULL_CHECK(edge, SOL_GPIO_EDGE_NONE);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(edge), SOL_GPIO_EDGE_NONE);
}
示例#11
0
SOL_API enum sol_spi_mode
sol_spi_mode_from_str(const char *spi_mode)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("mode0", SOL_SPI_MODE_0),
        SOL_STR_TABLE_ITEM("mode1", SOL_SPI_MODE_1),
        SOL_STR_TABLE_ITEM("mode2", SOL_SPI_MODE_2),
        SOL_STR_TABLE_ITEM("mode3", SOL_SPI_MODE_3),
        { }
    };

    SOL_NULL_CHECK(spi_mode, SOL_SPI_MODE_0);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(spi_mode), SOL_SPI_MODE_0);
}
示例#12
0
SOL_API enum sol_uart_baud_rate
sol_uart_baud_rate_from_str(const char *baud_rate)
{
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("baud-9600", SOL_UART_BAUD_RATE_9600),
        SOL_STR_TABLE_ITEM("baud-19200", SOL_UART_BAUD_RATE_19200),
        SOL_STR_TABLE_ITEM("baud-38400", SOL_UART_BAUD_RATE_38400),
        SOL_STR_TABLE_ITEM("baud-57600", SOL_UART_BAUD_RATE_57600),
        SOL_STR_TABLE_ITEM("baud-115200", SOL_UART_BAUD_RATE_115200),
        { }
    };

    SOL_NULL_CHECK(baud_rate, SOL_UART_BAUD_RATE_115200);

    return sol_str_table_lookup_fallback(table,
        sol_str_slice_from_str(baud_rate), SOL_UART_BAUD_RATE_115200);
}
示例#13
0
static int
byte_to_note_period_us(const char value)
{
    struct sol_str_slice note;
    int period;

    note.data = &value;
    note.len = 1;
    period = sol_str_table_lookup_fallback(note_to_period_table, note,
        SPEAKER_NOTE_SENTINEL);

    if (period == SPEAKER_NOTE_SENTINEL) {
        SOL_WRN("unhandled note '%c'\n", value);
        return -EINVAL;
    }

    return period;
}