const struct resource_attribute *get_resource_attr(struct resource *resource, u_int64_t attr_id);
struct resource_attribute_value *
get_resource_attr_value(struct resource *resource, u_int64_t attr_id);
-bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id);
+int is_resource_attr_supported(struct resource *resource, u_int64_t attr_id, bool *supported);
static inline bool
resource_attr_supported_always(struct resource *resource,
ret = TIZEN_ERROR_INVALID_PARAMETER;
break;
case REQUEST_GET_VALUE_UINT:
+ case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
if (sscanf(buffer, "%d$%u$%d", &response_req,
&data->value_uint32, &response_ret) < 3)
ret = TIZEN_ERROR_INVALID_PARAMETER;
case REQUEST_DELETE_RESOURCE:
case REQUEST_CREATE_RESOURCE:
case REQUEST_SET_RESOURCE_CTRL:
- case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
case REQUEST_SET_RESOURCE_ATTR:
case REQUEST_UNSET_RESOURCE_ATTR:
case REQUEST_IS_RESOURCE_ATTR_SET:
}
EXPORT
-bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id)
+int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported)
{
struct request_data request = {
.request = REQUEST_IS_RESOURCE_ATTR_SUPPORTED,
int ret;
ret = handle_request(&request);
- return (ret < 0) ? false : (bool)ret;
+ if (ret < 0)
+ return ret;
+
+ *supported = (bool)request.value_uint32;
+ return TIZEN_ERROR_NONE;
}
EXPORT
* @param[in] Resource monitor id
* @param[in] Resource id
* @param[in] Resource attribute id
- * @return @c true on success, otherwise false
+ * @param[out] Resource attribute is either supported or not
+ * @return @c 0 on success, otherwise false
*/
-bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id);
+int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported);
/**
* @brief Update value of the interested attributes for all created resource
return ret;
}
-static int handle_request_is_resource_attr_supported(struct request_client *client, char *args)
+static int handle_request_is_resource_attr_supported(struct request_client *client, char *args, bool *supported)
{
struct resource *res;
int resource_id;
return -EINVAL;
}
- return (int)is_resource_attr_supported(res, attr_id);
+ return is_resource_attr_supported(res, attr_id, supported);
}
static int handle_request_set_resource_ctrl(struct request_client *client, char *args)
ret = handle_request_set_resource_attr(client, args, request_type);
break;
case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
- ret = handle_request_is_resource_attr_supported(client, args);
+ {
+ bool supported;
+
+ ret = handle_request_is_resource_attr_supported(client, args, &supported);
+
+ ADD_RESPONSE(response, buffer_len, "%u$", (u_int32_t)supported);
+ }
break;
case REQUEST_GET_RESOURCE_JSON:
case REQUEST_GET_VALUE_JSON:
return &resource->attrs_value[attr_index];
}
-bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id)
+int is_resource_attr_supported(struct resource *resource, u_int64_t attr_id, bool *supported)
{
const struct resource_attribute *attr = NULL;
int attr_index = RESOURCE_ATTR_INDEX(attr_id);
if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
_E("Invalid parameter\n");
- return false;
+ return -EINVAL;
}
attr = &resource->attrs[attr_index];
if (attr->id & resource->attr_supported) {
- return true;
+ is_supported = true;
} else if (attr->ops.is_supported) {
is_supported = attr->ops.is_supported(resource, attr);
} else if (attr->ops.get) {
if (is_supported)
resource->attr_supported |= attr->id;
- return is_supported;
+ *supported = is_supported;
+
+ return 0;
}
static bool check_attr_validate(struct resource *resource, u_int64_t attr_id, int type)
{
struct resource_attribute_value *attr_value;
int i, ret;
+ bool supported;
if (!resource)
return -EINVAL;
if (!(resource->attrs[i].id & interest_mask))
continue;
- if (!is_resource_attr_supported(resource, resource->attrs[i].id)) {
- ret = -EINVAL;
+ ret = is_resource_attr_supported(resource, resource->attrs[i].id,
+ &supported);
+ if (ret < 0) {
+ goto err;
+ } else if (!supported){
+ ret = -ENOTSUP;
goto err;
}
EXPECT_EQ(ret, 0);
for (j = 0; j < (int)ARRAY_SIZE(res_attr_ids); j++) {
- bool supported = pass_resource_monitor_is_resource_attr_supported(
+ bool supported;
+
+ ret = pass_resource_monitor_is_resource_attr_supported(
id, res_id,
- res_attr_ids[j]);
+ res_attr_ids[j],
+ &supported);
+ EXPECT_EQ(ret, 0);
EXPECT_EQ(supported, false);
- supported = pass_resource_monitor_is_resource_attr_supported(
+ ret = pass_resource_monitor_is_resource_attr_supported(
UNKNOWN_ID, res_id,
- res_attr_ids[j]);
+ res_attr_ids[j],
+ &supported);
+ EXPECT_EQ(ret, 0);
EXPECT_EQ(supported, false);
- supported = pass_resource_monitor_is_resource_attr_supported(
+ ret = pass_resource_monitor_is_resource_attr_supported(
id, UNKNOWN_ID,
- res_attr_ids[j]);
+ res_attr_ids[j],
+ &supported);
+ EXPECT_EQ(ret, 0);
EXPECT_EQ(supported, false);
}
u_int64_t mask = 0;
for (i = 0; i < num_attrs; i++) {
- bool supported = pass_resource_monitor_is_resource_attr_supported(
- mon_id, res_id, attrs[i].attr_id);
+ bool supported;
+
+ ret = pass_resource_monitor_is_resource_attr_supported(
+ mon_id, res_id,
+ attrs[i].attr_id,
+ &supported);
+ EXPECT_EQ(ret, 0);
+
if (supported)
mask |= attrs[i].attr_id;
}
u_int64_t mask = 0;
for (i = 0; i < num_attrs; i++) {
- bool supported = pass_resource_monitor_is_resource_attr_supported(
- mon_id, res_id, attrs[i].attr_id);
+ bool supported;
+
+ ret = pass_resource_monitor_is_resource_attr_supported(
+ mon_id, res_id,
+ attrs[i].attr_id,
+ &supported);
+ EXPECT_EQ(ret, 0);
+
if (supported)
mask |= attrs[i].attr_id;
}
u_int64_t mask = 0;
for (i = 0; i < num_attrs; i++) {
- bool supported = pass_resource_monitor_is_resource_attr_supported(
- mon_id, res_id, attrs[i].attr_id);
+ bool supported;
+
+ ret = pass_resource_monitor_is_resource_attr_supported(
+ mon_id, res_id,
+ attrs[i].attr_id,
+ &supported);
+ EXPECT_EQ(ret, 0);
+
if (supported)
mask |= attrs[i].attr_id;
}
int i, ret, err_count = 0;
for (i = 0; i < num_attrs; i++) {
- bool supported = pass_resource_monitor_is_resource_attr_supported(
- mon_id, res_id, attrs[i].attr_id);
+ bool supported;
+
+ ret = pass_resource_monitor_is_resource_attr_supported(
+ mon_id, res_id,
+ attrs[i].attr_id,
+ &supported);
if (!supported)
continue;
static inline void create_resource_and_set_attrs(struct resource_data *res, int ctrl_val)
{
- int i;
+ int i, ret;
+ bool supported;
if (!res)
return;
res->mon_id, res->res_id, res->ctrl_id, ctrl_val);
for (i = 0; i < res->num_attrs; i++) {
- if (pass_resource_monitor_is_resource_attr_supported(
- res->mon_id, res->res_id, res->attrs[i].id))
+ ret = pass_resource_monitor_is_resource_attr_supported(
+ res->mon_id, res->res_id, res->attrs[i].id,
+ &supported);
+ if (ret < 0)
+ continue;
+
+ if (supported)
res->mask |= res->attrs[i].id;
}
bool supported;
int ret = 0;
- supported = pass_resource_monitor_is_resource_attr_supported(
+ ret = pass_resource_monitor_is_resource_attr_supported(
res->mon_id, res->res_id,
- res->attrs[i].id);
+ res->attrs[i].id,
+ &supported);
+ if(ret < 0) {
+ printf("%40s | %-5s | %s", "Not Implemented",
+ res->attrs[i].unit, res->attrs[i].desc);
+ return;
+ }
+
if (!supported) {
printf("%40s | %-5s | %s", "Not Supported",
res->attrs[i].unit, res->attrs[i].desc);