Esempio n. 1
0
void
service_list_cb(void *data, const struct sol_netctl_service *service)
{
    struct sol_flow_node *node = data;
    const char *name;
    int r;

    name = sol_netctl_service_get_name(service);

    if (sol_netctl_service_get_state(service) ==
        SOL_NETCTL_SERVICE_STATE_REMOVE) {
        r = sol_flow_send_string_packet(node,
            SOL_FLOW_NODE_TYPE_NETCTL_LIST_SERVICES__OUT__REMOVED,
            name);
        if (r < 0)
            SOL_WRN("Failed to send removed service name: %s", name);
        return;
    }

    r = sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_NETCTL_LIST_SERVICES__OUT__ADDED,
        name);
    if (r < 0)
        SOL_WRN("Failed to send added service name: %s", name);
}
Esempio n. 2
0
static void
thingspeak_execute_poll_finished(void *data,
    const struct sol_http_client_connection *connection,
    struct sol_http_response *response)
{
    struct thingspeak_execute_data *mdata = data;
    char *body;

    RESPONSE_CHECK_API(response, mdata);

    if (!response->content.used) {
        /* Empty response means no talkback commands */
        return;
    }

    if (response->response_code != SOL_HTTP_STATUS_OK) {
        sol_flow_send_error_packet(mdata->node, EINVAL,
            "Thingspeak returned an unknown response code: %d",
            response->response_code);
        return;
    }

    body = strndup(response->content.data, response->content.used);
    SOL_NULL_CHECK(body);

    sol_flow_send_string_packet(mdata->node,
        SOL_FLOW_NODE_TYPE_THINGSPEAK_TALKBACK_EXECUTE__OUT__OUT, body);
    free(body);
}
Esempio n. 3
0
static void
check_cb(void *data, int status, const struct sol_update_info *response)
{
    struct sol_flow_node *node = data;
    struct update_data *mdata = sol_flow_node_get_private_data(node);

    if (status < 0) {
        sol_flow_send_error_packet(node, -status,
            "Error while checking for updates: %s", sol_util_strerrora(-status));
        goto end;
    }

#ifndef SOL_NO_API_VERSION
    if (SOL_UNLIKELY(response->api_version != SOL_UPDATE_INFO_API_VERSION)) {
        SOL_WRN("Update info config version '%u' is unexpected, expected '%u'",
            response->api_version, SOL_UPDATE_INFO_API_VERSION);
        return;
    }
#endif

    sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_UPDATE_CHECK__OUT__VERSION, response->version);
    sol_flow_send_irange_value_packet(node,
        SOL_FLOW_NODE_TYPE_UPDATE_CHECK__OUT__SIZE, response->size);
    sol_flow_send_bool_packet(node,
        SOL_FLOW_NODE_TYPE_UPDATE_CHECK__OUT__NEED_UPDATE, response->need_update);

end:
    mdata->handle = NULL;
}
Esempio n. 4
0
static int
open_list_services(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
{
    const struct sol_ptr_vector *service_list;
    struct sol_netctl_service *service;
    int r;
    uint16_t i;

    r = sol_netctl_add_service_monitor(service_list_cb, node);
    SOL_INT_CHECK(r, < 0, r);

    service_list = sol_netctl_get_services();
    if (!service_list)
        return NULL;

    SOL_PTR_VECTOR_FOREACH_IDX (service_list, service, i) {
        enum sol_netctl_service_state state = sol_netctl_service_get_state(service);
        const char *name;

        if (state == SOL_NETCTL_SERVICE_STATE_UNKNOWN ||
            state == SOL_NETCTL_SERVICE_STATE_REMOVE)
            continue;

        name = sol_netctl_service_get_name(service);
        r = sol_flow_send_string_packet(node,
            SOL_FLOW_NODE_TYPE_NETCTL_LIST_SERVICES__OUT__ADDED,
            name);
        if (r < 0)
            SOL_WRN("Failed to send added service name: %s", name);
    }

    return 0;
}
Esempio n. 5
0
void
service_status_cb(void *data, const struct sol_netctl_service *service)
{
    struct sol_flow_node *node = data;
    struct network_service_data *mdata = sol_flow_node_get_private_data(node);
    enum sol_netctl_service_state current_state;
    const char *name;
    int r;

    name = sol_netctl_service_get_name(service);

    if (!name || strcmp(name, mdata->service_name))
        return;

    current_state = sol_netctl_service_get_state(service);
    if (current_state == mdata->state)
        return;

    r = sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_NETCTL_SERVICE__OUT__OUT,
        sol_netctl_service_state_to_str(current_state));
    SOL_INT_CHECK_GOTO(r, < 0, error);

    if (mdata->state == SOL_NETCTL_SERVICE_STATE_ONLINE) {
        r = sol_flow_send_bool_packet(node,
            SOL_FLOW_NODE_TYPE_NETCTL_SERVICE__OUT__ONLINE,
            false);
        SOL_INT_CHECK_GOTO(r, < 0, error);
    }
Esempio n. 6
0
static void
string_receiver(void *data, uint32_t id, struct sol_blob *message)
{
    struct sol_flow_node *node = data;

    sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_IPM_STRING_READER__OUT__OUT, message->mem);
    sol_blob_unref(message);
}
Esempio n. 7
0
static int
constant_string_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
{
    const struct sol_flow_node_type_constant_string_options *opts;

    SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options,
        SOL_FLOW_NODE_TYPE_CONSTANT_STRING_OPTIONS_API_VERSION, -EINVAL);
    opts = (const struct sol_flow_node_type_constant_string_options *)options;

    return sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_CONSTANT_STRING__OUT__OUT, opts->value);
}
Esempio n. 8
0
static int
timezone_send(const void *tzone, struct sol_flow_node *node)
{
    int r;

    if (!tzone) {
        tzone = sol_platform_get_timezone();
        SOL_NULL_CHECK(tzone, -ECANCELED);
    }

    r = sol_flow_send_string_packet(node, 0, tzone);
    SOL_INT_CHECK(r, < 0, r);
    return 0;
}
Esempio n. 9
0
static int
hostname_send(const void *hostname, struct sol_flow_node *node)
{
    int r;

    if (!hostname) {
        hostname = sol_platform_get_hostname();
        SOL_NULL_CHECK(hostname, -ECANCELED);
    }

    r = sol_flow_send_string_packet(node, 0, hostname);
    SOL_INT_CHECK(r, < 0, r);
    return 0;
}
Esempio n. 10
0
static int
locale_send(struct sol_flow_node *node, enum sol_platform_locale_category category, const char *locale)
{
    if (category == SOL_PLATFORM_LOCALE_UNKNOWN && !locale) {
        locale_monitor_unregister(node);
        return sol_flow_send_error_packet(node, ECANCELED,
            "Something wrong happened with the locale monitor,"
            "stoping to monitor locale changes");
    }

    if (!locale) {
        locale = sol_platform_get_locale(category);
        SOL_NULL_CHECK(locale, -EINVAL);
    }
    return sol_flow_send_string_packet(node, (int)category, locale);
}
Esempio n. 11
0
static int
platform_machine_id_open(struct sol_flow_node *node,
    void *data,
    const struct sol_flow_node_options *options)
{
    const char *id;

    id = sol_platform_get_machine_id();
    if (!id) {
        sol_flow_send_error_packet(node, ENOSYS,
            "Fail on retrieving machine id -- not available");
        return 0; /* do not fail to create node */
    }

    return sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_PLATFORM_MACHINE_ID__OUT__OUT, id);
}
Esempio n. 12
0
int
string_uuid_gen(struct sol_flow_node *node,
    void *data,
    uint16_t port,
    uint16_t conn_id,
    const struct sol_flow_packet *packet)
{
    int r;
    char id[37] = { 0 };
    struct string_uuid_data *mdata = data;

    r = sol_util_uuid_gen(mdata->upcase, mdata->with_hyphens, id);
    SOL_INT_CHECK(r, < 0, r);

    return sol_flow_send_string_packet(node,
        SOL_FLOW_NODE_TYPE_STRING_UUID__OUT__OUT, id);
}
Esempio n. 13
0
static bool
on_timeout(void *data)
{
    struct sol_flow_node *node = data;
    struct mytype_context *ctx = sol_flow_node_get_private_data(node);
    uint16_t port_idx;
    char buf[256];

    printf("mytype tick... send packet. ctx=%p someint=%d, somebool=%d\n",
        ctx, ctx->someint, ctx->somebool);

    snprintf(buf, sizeof(buf), "%d/%s",
        ctx->someint,
        ctx->somebool ? "true" : "false");

    /* this is to demo the discovery from name, but one could/should use the
     * port index for efficiency matters.
     */
    port_idx = sol_flow_simplectype_get_port_out_index(mytype, "STRING");
    sol_flow_send_string_packet(node, port_idx, buf);

    return true;
}