Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
/src/samples/network/netctl.c
/*
* This file is part of the Soletta (TM) Project
*
* Copyright (C) 2015 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdbool.h>
#include <inttypes.h>
#include <stdio.h>
#include <errno.h>
#include "soletta.h"
#include "sol-netctl.h"
#include "sol-util.h"
#include "sol-log.h"
#define CONN_AP "Guest"
#define INPUT "12345678"
static void
manager_cb(void *data)
{
enum sol_netctl_state g_state;
bool offline;
g_state = sol_netctl_get_state();
printf("manager_cb system state = %d\n", g_state);
printf("manager_cb system offline = %d\n", offline);
}
static void
service_cb(void *data, const struct sol_netctl_service *service)
{
const char *str;
int r;
state = sol_netctl_service_get_state(service);
printf("service_cb service state = %d\n", state);
if (str)
printf("service_cb service type = %s\n", str);
else
printf("service_cb service type = NULL\n");
printf("service_cb strength = %d\n", r);
if (str)
printf("service_cb service name = %s\n", str);
else
printf("service_cb service name = NULL\n");
if (str && strcmp(str, CONN_AP) == 0) {
printf("connect AP\n");
} else if (state == SOL_NETCTL_SERVICE_STATE_READY) {
printf("Disconnect AP\n");
}
}
}
static void
error_cb(void *data, const struct sol_netctl_service *service,
unsigned int error)
{
const char *str;
if (str)
printf("error_cb service name = %s\n", str);
else
printf("error_cb service name = NULL\n");
printf("error_cb error is %d\n", error);
}
static void
report_error(void *data, const struct sol_netctl_service *service,
const char *error)
{
int r;
printf("The agent action error is %s\n", error);
false);
printf("The agent request retry return value is %d\n", r);
}
static void
request_input(void *data, const struct sol_netctl_service *service,
const struct sol_ptr_vector *vector)
{
int r;
uint16_t i;
char *value;
struct sol_ptr_vector input_vector;
printf("The agent action is input\n");
sol_ptr_vector_init(&input_vector);
SOL_PTR_VECTOR_FOREACH_IDX (vector, value, i) {
printf("The agent input type is %s\n", value);
input = calloc(1, sizeof(struct sol_netctl_agent_input));
if (!input) {
printf("No Memory for the agent input\n");
goto fail;
}
r = sol_ptr_vector_append(&input_vector, input);
if (r < 0) {
printf("append the agent input error\n");
free(input);
goto fail;
}
input->type = strdup(value);
if (!input->type) {
printf("No Memory for the agent input\n");
goto fail;
}
input->input = strdup(INPUT);
if (!input->input) {
printf("No Memory for the agent input\n");
goto fail;
}
}
&input_vector);
printf("The agent report input return value is %d\n", r);
fail:
SOL_PTR_VECTOR_FOREACH_IDX (&input_vector, input, i) {
if (input->input)
free(input->input);
if (input->type)
free(input->type);
free(input);
}
sol_ptr_vector_clear(&input_vector);
}
static void
cancel(void *data)
{
printf("The agent action is cancelled\n");
}
static void
release(void *data)
{
printf("The agent action is release\n");
}
static void
shutdown(void)
{
int r;
printf("unregister agent return value r = %d\n", r);
}
static void
startup(void)
{
int r;
printf("register agent return value r = %d\n", r);
printf("scan devices return value r = %d\n", r);
}