Esempio n. 1
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);
}
Esempio n. 2
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);
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
Esempio n. 5
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);
}
Esempio n. 6
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);
}
Esempio n. 7
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);
}
Esempio n. 8
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);
}
Esempio n. 9
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);
}
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;
}
Esempio n. 11
0
static bool
_level_str_parse(const char *buf, size_t buflen, uint8_t *storage)
{
    int16_t found;
    static const struct sol_str_table table[] = {
        SOL_STR_TABLE_ITEM("CRI",      SOL_LOG_LEVEL_CRITICAL),
        SOL_STR_TABLE_ITEM("CRIT",     SOL_LOG_LEVEL_CRITICAL),
        SOL_STR_TABLE_ITEM("CRITICAL", SOL_LOG_LEVEL_CRITICAL),
        SOL_STR_TABLE_ITEM("DBG",      SOL_LOG_LEVEL_DEBUG),
        SOL_STR_TABLE_ITEM("DEBUG",    SOL_LOG_LEVEL_DEBUG),
        SOL_STR_TABLE_ITEM("ERR",      SOL_LOG_LEVEL_ERROR),
        SOL_STR_TABLE_ITEM("ERROR",    SOL_LOG_LEVEL_ERROR),
        SOL_STR_TABLE_ITEM("INF",      SOL_LOG_LEVEL_INFO),
        SOL_STR_TABLE_ITEM("INFO",     SOL_LOG_LEVEL_INFO),
        SOL_STR_TABLE_ITEM("WARN",     SOL_LOG_LEVEL_WARNING),
        SOL_STR_TABLE_ITEM("WARNING",  SOL_LOG_LEVEL_WARNING),
        SOL_STR_TABLE_ITEM("WRN",      SOL_LOG_LEVEL_WARNING),
        { }
    };

    if (!sol_str_table_lookup(table, SOL_STR_SLICE_STR(buf, buflen), &found))
        return false;
    *storage = found;
    return true;
}
Esempio n. 12
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);
}
Esempio n. 13
0
#include <systemd/sd-bus.h>

#include <sol-log.h>
#include <sol-bus.h>
#include <sol-bluetooth.h>
#include <sol-network.h>
#include <sol-util.h>
#include <sol-mainloop.h>
#include <sol-str-table.h>

#include <sol-gatt.h>

#include "sol-bluetooth-impl-bluez.h"

static const struct sol_str_table sol_gatt_chr_flags_table[] =  {
    SOL_STR_TABLE_ITEM("broadcast", SOL_GATT_CHR_FLAGS_BROADCAST),
    SOL_STR_TABLE_ITEM("read", SOL_GATT_CHR_FLAGS_READ),
    SOL_STR_TABLE_ITEM("write-without-response", SOL_GATT_CHR_FLAGS_WRITE_WITHOUT_RESPONSE),
    SOL_STR_TABLE_ITEM("write", SOL_GATT_CHR_FLAGS_WRITE),
    SOL_STR_TABLE_ITEM("notify", SOL_GATT_CHR_FLAGS_NOTIFY),
    SOL_STR_TABLE_ITEM("indicate", SOL_GATT_CHR_FLAGS_INDICATE),
    SOL_STR_TABLE_ITEM("authenticated-signed-writes", SOL_GATT_CHR_FLAGS_AUTHENTICATED_SIGNED_WRITES),
    SOL_STR_TABLE_ITEM("reliable-write", SOL_GATT_CHR_FLAGS_RELIABLE_WRITE),
    SOL_STR_TABLE_ITEM("writable-auxiliaries", SOL_GATT_CHR_FLAGS_WRITABLE_AUXILIARIES),
    SOL_STR_TABLE_ITEM("encrypt-read", SOL_GATT_CHR_FLAGS_ENCRYPT_WRITE),
    SOL_STR_TABLE_ITEM("encrypt-write", SOL_GATT_CHR_FLAGS_ENCRYPT_AUTHENTICATED_READ),
    SOL_STR_TABLE_ITEM("encrypt-authenticated-read", SOL_GATT_CHR_FLAGS_ENCRYPT_AUTHENTICATED_WRITE),
    SOL_STR_TABLE_ITEM("encrypt-authenticated-write", SOL_GATT_CHR_FLAGS_ENCRYPT_AUTHENTICATED_WRITE),
    { },
};
Esempio n. 14
0
    case SOL_FLOW_NODE_OPTIONS_MEMBER_DIRECTION_VECTOR:
        *(struct sol_direction_vector *)mem = m->direction_vector;
        break;
    case SOL_FLOW_NODE_OPTIONS_MEMBER_STRING:
        s = mem;
        free(*s);
        *s = strdup(m->string);
    default:
        /* Not reached. */
        /* TODO: Create ASSERT_NOT_REACHED() macro.*/
        break;
    }
}

static const struct sol_str_table member_str_to_type[] = {
    SOL_STR_TABLE_ITEM("boolean", SOL_FLOW_NODE_OPTIONS_MEMBER_BOOLEAN),
    SOL_STR_TABLE_ITEM("byte", SOL_FLOW_NODE_OPTIONS_MEMBER_BYTE),
    SOL_STR_TABLE_ITEM("direction-vector", SOL_FLOW_NODE_OPTIONS_MEMBER_DIRECTION_VECTOR),
    SOL_STR_TABLE_ITEM("drange-spec", SOL_FLOW_NODE_OPTIONS_MEMBER_DRANGE_SPEC),
    SOL_STR_TABLE_ITEM("float", SOL_FLOW_NODE_OPTIONS_MEMBER_FLOAT),
    SOL_STR_TABLE_ITEM("int", SOL_FLOW_NODE_OPTIONS_MEMBER_INT),
    SOL_STR_TABLE_ITEM("irange-spec", SOL_FLOW_NODE_OPTIONS_MEMBER_IRANGE_SPEC),
    SOL_STR_TABLE_ITEM("rgb", SOL_FLOW_NODE_OPTIONS_MEMBER_RGB),
    SOL_STR_TABLE_ITEM("string", SOL_FLOW_NODE_OPTIONS_MEMBER_STRING),
    {}
};

/* 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)
Esempio n. 15
0
    ITER_ERROR
};

struct piezo_speaker_data {
    struct sol_pwm *pwm;
    struct sol_timeout *timer;
    uint32_t *periods_us, *delays_us, num_entries, tempo_ms, curr_idx;
    enum tune_iteration_state curr_state;
    bool loop : 1;
};

//FIXME: consider changing the tune syntax to
//http://en.wikipedia.org/wiki/Music_Macro_Language#Modern_MML

static const struct sol_str_table note_to_period_table[] = {
    SOL_STR_TABLE_ITEM("C", SPEAKER_NOTE_DO_HIGH),
    SOL_STR_TABLE_ITEM("a", SPEAKER_NOTE_LA),
    SOL_STR_TABLE_ITEM("b", SPEAKER_NOTE_SI),
    SOL_STR_TABLE_ITEM("c", SPEAKER_NOTE_DO),
    SOL_STR_TABLE_ITEM("d", SPEAKER_NOTE_RE),
    SOL_STR_TABLE_ITEM("e", SPEAKER_NOTE_MI),
    SOL_STR_TABLE_ITEM("f", SPEAKER_NOTE_FA),
    SOL_STR_TABLE_ITEM("g", SPEAKER_NOTE_SOL),
    { }
};

static int
byte_to_note_period_us(const char value)
{
    struct sol_str_slice note;
    int period;