コード例 #1
0
ファイル: oic-client.c プロジェクト: lgywata/soletta
int
main(int argc, char *argv[])
{
    struct sol_oic_client client;
    struct sol_network_link_addr cliaddr = { .family = AF_INET, .port = 5683 };
    const char *resource_type;

    sol_init();

    if (inet_pton(cliaddr.family, "224.0.1.187", &cliaddr.addr) < 0) {
        printf("could not convert multicast ip address to sockaddr_in\n");
        return 1;
    }

    client.server = sol_coap_server_new(0);

    if (argc < 2) {
        printf("No rt filter specified, assuming everything\n");
        resource_type = NULL;
    } else {
        printf("Finding resources with resource type %s\n", argv[1]);
        resource_type = argv[1];
    }

    sol_oic_client_find_resource(&client, &cliaddr, resource_type, found_resource, NULL);

    sol_run();

    return 0;
}
コード例 #2
0
ファイル: platform-simple.c プロジェクト: Learn-iot/soletta
int
main(int argc, char *argv[])
{
    int r = 0;

    if (sol_init() < 0)
        return EXIT_FAILURE;

    printf("Initial platform state: %d\n", sol_platform_get_state());
    sol_platform_add_state_monitor(on_state_change, NULL);

    if (argc > 2) {
        cmds = argv + 1;
        n_cmds = argc - 1;
        timeout_handle = sol_timeout_add(CMD_TICK, on_timeout_cmd, NULL);
    }

    sol_run();

    if (timeout_handle)
        sol_timeout_del(timeout_handle);

    sol_platform_del_state_monitor(on_state_change, NULL);

    sol_shutdown();

    return r;
}
コード例 #3
0
ファイル: mqtt-subscribe.c プロジェクト: anselmolsm/soletta
int
main(int argc, char *argv[])
{
    struct sol_mqtt *mqtt;
    int port;

    sol_init();

    if (argc < 4) {
        SOL_INF("Usage: %s <ip> <port> <topic>", argv[0]);
        return 0;
    }

    port = atoi(argv[2]);
    topic = argv[3];

    mqtt = sol_mqtt_connect(argv[1], port, &config, NULL);
    if (!mqtt) {
        SOL_WRN("Unable to create MQTT session");
        return -1;
    }

    sol_run();

    sol_mqtt_disconnect(mqtt);

    sol_shutdown();

    return 0;
}
コード例 #4
0
ファイル: test-mainloop.c プロジェクト: Achint08/soletta
int
TEST_MAINLOOP_MAIN_FN(int argc, char *argv[])
{
    int err, i;
    struct sol_timeout *timeout_to_del;
    struct sol_idle *idler_to_del;

    err = sol_init();
    ASSERT(!err);

    timeout_to_del = sol_timeout_add(100, timeout_never_called, NULL);
    sol_timeout_add(20, on_timeout_del_and_new, timeout_to_del);

    sol_timeout_add(1, on_timeout_renew_twice, NULL);
    sol_idle_add(on_idler_renew_twice, NULL);

    for (i = 0; i < 5; i++)
        sol_idle_add(on_idler, (void *)(intptr_t)i);

    sol_idle_add(on_idler_del_another, &idler_to_del);
    idler_to_del = sol_idle_add(on_idler_never_called, NULL);

    sol_run();
    ASSERT_INT_EQ(timeout_called, 3);
    ASSERT_INT_EQ(timeout_renewed, 2);
    ASSERT_INT_EQ(idler_renewed, 2);

    for (i = 0; i < 10; i++)
        ASSERT_INT_EQ(idler_sequence[i], i);

    sol_shutdown();

    return 0;
}
コード例 #5
0
int
main(int argc, char *argv[])
{
    int err;

    err = sol_init();
    ASSERT(!err);

    sol_idle_add(perform_tests, NULL);

    sol_run();

    sol_shutdown();

    return 0;
}
コード例 #6
0
ファイル: simple-server.c プロジェクト: Achint08/soletta
int
main(int argc, char *argv[])
{
    struct light_context context = { .resource = &light };
    struct sol_coap_server *server;
    char old_led_state;
    struct sol_network_link_addr servaddr = { .family = SOL_NETWORK_FAMILY_INET6,
                                              .port = DEFAULT_UDP_PORT };

    sol_init();

    server = sol_coap_server_new(&servaddr);
    if (!server) {
        SOL_WRN("Could not create a coap server using port %d.", DEFAULT_UDP_PORT);
        return -1;
    }

    if (sol_coap_server_register_resource(server, &light, NULL) < 0) {
        SOL_WRN("Could not register light resource");
        return -1;
    }

    console_fd = open("/dev/console", O_RDWR);
    if (console_fd < 0) {
        perror("Could not open '/dev/console'");
        return -1;
    }

    if (ioctl(console_fd, KDGETLED, (char *)&old_led_state)) {
        perror("Could not get the keyboard leds state");
        return -1;
    }

    context.server = server;
    sol_timeout_add(5000, update_light, &context);

    sol_run();

    sol_coap_server_unref(server);

    if (ioctl(console_fd, KDSETLED, old_led_state)) {
        perror("Could not return the leds to the old state");
        return -1;
    }

    return 0;
}
コード例 #7
0
static void
uv_idle_callback()
{
    SOL_DBG("Entering with state %s", RESOLVE_MAINLOOP_STATE(mainloopState));
    if (mainloopState == MAINLOOP_HIJACKING_STARTED) {
        SOL_DBG("running sol_run()");
        mainloopState = MAINLOOP_HIJACKED;
        sol_run();
        SOL_DBG("sol_run() has returned. state is %s",
            RESOLVE_MAINLOOP_STATE(mainloopState));
        if (mainloopState == MAINLOOP_RELEASING_STARTED) {
            mainloopState = MAINLOOP_RELEASED;
        }
    } else if ( mainloopState == MAINLOOP_HIJACKED) {
        SOL_DBG("main loop already hijacked. Stopping idler");
        uv_idle_stop(&uv_idle);
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: kalyankondapally/soletta
int
main(int argc, char *argv[])
{
    int r;

    if (!parse_args(argc, argv)) {
        usage(argv[0]);
        return EXIT_FAILURE;
    }

    if (sol_init() < 0) {
        SOL_CRI("Cannot initialize soletta.");
        return EXIT_FAILURE;
    }

    sol_idle_add(startup, NULL);

    r = sol_run();

    shutdown();
    sol_shutdown();

    return r;
}
コード例 #9
0
ファイル: simple-client.c プロジェクト: Achint08/soletta
int
main(int argc, char *argv[])
{
    struct sol_coap_server *server;
    struct sol_str_slice *path;
    struct sol_network_link_addr cliaddr = { };
    struct sol_coap_packet *req;
    uint8_t observe = 0;
    int i, r;
    struct sol_network_link_addr servaddr = { .family = SOL_NETWORK_FAMILY_INET6,
                                              .port = 0 };

    uint8_t token[4] = { 0x41, 0x42, 0x43, 0x44 };

    sol_init();

    if (argc < 3) {
        printf("Usage: %s <address> <path> [path]\n", argv[0]);
        return 0;
    }

    server = sol_coap_server_new(&servaddr);
    if (!server) {
        SOL_WRN("Could not create a coap server.");
        return -1;
    }

    req = sol_coap_packet_request_new(SOL_COAP_METHOD_GET, SOL_COAP_TYPE_CON);
    if (!req) {
        SOL_WRN("Could not make a GET request to resource %s", argv[2]);
        return -1;
    }

    r = sol_coap_header_set_token(req, token, sizeof(token));
    if (r < 0) {
        SOL_WRN("Could not set coap header token.");
        return -1;
    }

    path = calloc(argc - 1, sizeof(*path));
    if (!path) {
        sol_coap_packet_unref(req);
        return -1;
    }

    for (i = 2; i < argc; i++) {
        path[i - 2] = sol_str_slice_from_str(argv[i]);
    }

    sol_coap_add_option(req, SOL_COAP_OPTION_OBSERVE, &observe, sizeof(observe));

    for (i = 0; path[i].data; i++)
        sol_coap_add_option(req, SOL_COAP_OPTION_URI_PATH, path[i].data, path[i].len);

    cliaddr.family = SOL_NETWORK_FAMILY_INET6;
    if (!sol_network_link_addr_from_str(&cliaddr, argv[1])) {
        SOL_WRN("%s is an invalid IPv6 address", argv[1]);
        free(path);
        sol_coap_packet_unref(req);
        return -1;
    }

    cliaddr.port = DEFAULT_UDP_PORT;

    /* Takes the ownership of 'req'. */
    sol_coap_send_packet_with_reply(server, req, &cliaddr, reply_cb, path);

    sol_run();

    sol_coap_server_unref(server);
    free(path);

    return 0;
}