struct resource *res;
int resource_type;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_CREATE_RESOURCE args:
resource_type = atoi(args);
res = create_resource(resource_type);
- if (!res)
+ if (!res) {
+ _E("failed to create resource, res:type(%d)\n", resource_type);
return -EINVAL;
+ }
register_resource_to_client(client, res);
{
int resource_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_DELETE_RESOURCE args:
{
struct resource *res;
int resource_id;
+ int ret;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_UPDATE_RESOURCE args:
resource_id = atoi(args);
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, res:id(%d)\n", resource_id);
return -EINVAL;
+ }
+
+ ret = update_resource_attrs(res);
+ if (ret < 0) {
+ _E("failed to update resource attributes, res:name(%s)id(%d)\n",
+ get_resource_name(res), resource_id);
+ return ret;
+ }
- return update_resource_attrs(res);
+ return 0;
}
static int handle_request_get_resource_count(struct request_client *client, char *args)
{
int resource_type;
+ int ret;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_RESOURCE_COUNT args:
*/
resource_type = atoi(args);
- return get_resource_device_count(resource_type);
+ ret = get_resource_device_count(resource_type);
+ if (ret < 0) {
+ _E("failed to get resource device count, res:type(%d)\n", resource_type);
+ return ret;
+ }
+
+ return ret;
}
static int handle_request_update_resource_all(struct request_client *client, char *args)
{
- if (!client)
+ if (!client) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_UPDATE_RESOURCE args:
int resource_id, ret;
u_int64_t interest_masks;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_SET_RESOURCE_ATTR and REQUEST_UNSET_RESOURCE_ATTR args:
* - <RESOURCE_ID:INTEREST_MASK>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &interest_masks) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &interest_masks) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:name(%s)id(%d)\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id);
return -EINVAL;
+ }
switch (request_type) {
case REQUEST_SET_RESOURCE_ATTR:
ret = set_resource_attr_interest(res, interest_masks);
+ if (ret < 0)
+ _E("failed to set attribute interest, client(%d) | res:name(%s)id(%d)\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id);
break;
case REQUEST_UNSET_RESOURCE_ATTR:
ret = unset_resource_attr_interest(res, interest_masks);
+ if (ret < 0)
+ _E("failed to unset attribute interest, client(%d) | res:name(%s)id(%d)\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id);
break;
default:
return -EINVAL;
int resource_id;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_IS_RESOURCE_ATTR_SUPPORTED args:
* - <RESOURCE_ID:RESOURCE_ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64"", &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64"", &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
return (int)is_resource_attr_supported(res, attr_id);
}
static int handle_request_set_resource_ctrl(struct request_client *client, char *args)
{
struct resource *res;
- int resource_id, value;
+ int resource_id, value, ret;
u_int64_t ctrl_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_SET_RESOURCE_CTRL args:
* - <RESOURCE_ID:CONTROL_ID:CONTROL_VALUE>
*/
- if (sscanf(args, "%d$%"PRIu64"$%d", &resource_id, &ctrl_id, &value) < 3)
+ if (sscanf(args, "%d$%"PRIu64"$%d", &resource_id, &ctrl_id, &value) < 3) {
+ _E("failed to get resource and control id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
+
+ ret = set_resource_control(res, ctrl_id, (void *)(intptr_t)value);
+ if (ret < 0) {
+ _E("failed to set resource control, client(%d) | res:name(%s)id(%d) | ctrl:name(%s)id(%"PRId64")val(%d)\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_control_name(res, ctrl_id), ctrl_id, value);
+ return ret;
+ }
- return set_resource_control(res, ctrl_id, (void *)(intptr_t)value);
+ return 0;
}
static int
u_int64_t attr_id;
int resource_id;
- if (!client)
+ if (!client) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_RESOURCE_JSON args:
}
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, res:id(%d)\n", resource_id);
return -EINVAL;
+ }
skip_res:
switch (request_type) {
static int handle_request_get_value_int(struct request_client *client, char *args, int32_t *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_INT args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
+
+ ret = get_resource_attr_int(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get int value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
- return get_resource_attr_int(res, attr_id, value);
+ return 0;
}
static int handle_request_get_value_int64(struct request_client *client, char *args, int64_t *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_INT64 args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
+
+ ret = get_resource_attr_int64(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get int64 value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
- return get_resource_attr_int64(res, attr_id, value);
+ return 0;
}
static int
handle_request_get_value_uint(struct request_client *client, char *args, u_int32_t *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_UINT args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
- return get_resource_attr_uint(res, attr_id, value);
+ ret = get_resource_attr_uint(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get uint value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
+
+ return 0;
}
static int
handle_request_get_value_uint64(struct request_client *client, char *args, u_int64_t *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_UINT64 args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
+
+ ret = get_resource_attr_uint64(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get uint64 value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
- return get_resource_attr_uint64(res, attr_id, value);
+ return 0;
}
static int handle_request_get_value_double(struct request_client *client, char *args, double *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_DOUBLE args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
- return get_resource_attr_double(res, attr_id, value);
+ ret = get_resource_attr_double(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get double value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
+
+ return 0;
}
static int handle_request_get_value_string(struct request_client *client, char *args, char *value)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_INT args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
+
+ ret = get_resource_attr_string(res, attr_id, value);
+ if (ret < 0) {
+ _E("failed to get string value, client(%d) | res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
- return get_resource_attr_string(res, attr_id, value);
+ return 0;
}
static int
handle_request_get_value_array(struct request_client *client, char *args, struct array_value **arr)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
u_int64_t attr_id;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_VALUE_ARRAY args:
* - <RESOURCE_ID:ATTR_ID>
*/
- if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2)
+ if (sscanf(args, "%d$%"PRIu64, &resource_id, &attr_id) < 2) {
+ _E("failed to get resource and attribute id, client(%d)\n",
+ client->socket_fd);
return -EINVAL;
+ }
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
- return get_resource_attr_array(res, attr_id, arr);
+ ret = get_resource_attr_array(res, attr_id, arr);
+ if (ret < 0) {
+ _E("failed to get array value, client(%d) | (res:name(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id,
+ get_resource_attr_name(res, attr_id), attr_id);
+ return ret;
+ }
+
+ return 0;
}
static int
int64_t *start, int64_t *end)
{
struct resource *res;
- int resource_id;
+ int resource_id, ret;
- if (!client || !args)
+ if (!client || !args) {
+ _E("Invalid parameter\n");
return -ENOENT;
+ }
/**
* Format of REQUEST_GET_RESOURCE_TS args:
resource_id = atoi(args);
res = get_resource_by_id(client, resource_id);
- if (!res)
+ if (!res) {
+ _E("failed to get resource, client(%d) | res:id(%d)\n",
+ client->socket_fd, resource_id);
return -EINVAL;
+ }
- get_resource_ts(res, start, end);
+ ret = get_resource_ts(res, start, end);
+ if (ret < 0) {
+ _E("failed to get timestamp value, client(%d) | res:name(%s)id(%d)\n",
+ client->socket_fd,
+ get_resource_name(res), resource_id);
+ return ret;
+ }
return 0;
}
switch (request_type) {
case REQUEST_CREATE_RESOURCE:
ret = handle_request_create_resource(client, args);
- if (ret < 0)
- _D("failed to create resource");
break;
case REQUEST_DELETE_RESOURCE:
ret = handle_request_delete_resource(client, args);
- if (ret < 0)
- _E("failed to delete resource");
break;
case REQUEST_UPDATE_RESOURCE:
ret = handle_request_update_resource(client, args);
- if (ret < 0)
- _D("failed to update resource");
break;
case REQUEST_GET_RESOURCE_COUNT:
ret = handle_request_get_resource_count(client, args);
- if (ret < 0)
- _E("failed to get resource count");
break;
case REQUEST_UPDATE_RESOURCE_ALL:
ret = handle_request_update_resource_all(client, args);
- if (ret < 0)
- _E("failed to update all resources");
break;
case REQUEST_SET_RESOURCE_CTRL:
ret = handle_request_set_resource_ctrl(client, args);
- if (ret < 0)
- _D("failed to set resource control");
break;
case REQUEST_SET_RESOURCE_ATTR:
case REQUEST_UNSET_RESOURCE_ATTR:
ret = handle_request_set_resource_attr(client, args, request_type);
- if (ret < 0)
- _E("failed to %s attr interest",
- request_type == REQUEST_SET_RESOURCE_ATTR
- ? "set" : "unset");
break;
case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
ret = handle_request_is_resource_attr_supported(client, args);
- if (ret < 0)
- _E("failed to check whether attr is supported or not");
break;
case REQUEST_GET_RESOURCE_JSON:
case REQUEST_GET_VALUE_JSON:
char *json_string;
ret = handle_request_get_json(client, args, request_type, &json_string);
- if (ret < 0)
- _E("failed to get resource JSON string");
ADD_RESPONSE(response, buffer_len, "%s$", json_string);
int32_t value;
ret = handle_request_get_value_int(client, args, &value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%d$", value);
}
int64_t value;
ret = handle_request_get_value_int64(client, args, &value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%"PRId64"$", value);
}
u_int32_t value;
ret = handle_request_get_value_uint(client, args, &value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%u$", value);
}
u_int64_t value;
ret = handle_request_get_value_uint64(client, args, &value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%"PRIu64"$", value);
}
double value;
ret = handle_request_get_value_double(client, args, &value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%lf$", value);
}
char value[BUFF_MAX];
ret = handle_request_get_value_string(client, args, value);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%s$", value);
}
int i;
ret = handle_request_get_value_array(client, args, &array);
- if (ret < 0)
- _D("failed to get value");
if (array->length == 0) {
ADD_RESPONSE(response, buffer_len, "%d|%d|$",
int64_t start, end;
ret = handle_request_get_resource_ts(client, args, &start, &end);
- if (ret < 0)
- _D("failed to get value");
ADD_RESPONSE(response, buffer_len, "%"PRId64"$%"PRId64"$", start, end);
}
int len, ret;
char err_buf[BUFF_MAX];
- _D("Start worker thread for client-%d", client->socket_fd);
+ _D("Client-%d is connected", client->socket_fd);
while (1) {
len = recv(client->socket_fd, request, GENERIC_BUFF_MAX, 0);