}
EXPORT
-int pass_resource_monitor_get_value_string(int id, int resource_id, u_int64_t attr_id, char *value)
+int pass_resource_monitor_get_value_string(int id, int resource_id, u_int64_t attr_id, char **value)
{
char buffer[GENERIC_BUFF_MAX + 1];
+ char value_string[BUFF_MAX];
int buffer_len;
int response_req;
int ret;
+ if (!value)
+ return -EINVAL;
+
buffer_len = sprintf(buffer, "%d$%d$%"PRIu64,
REQUEST_GET_VALUE_STRING, resource_id, attr_id);
if (send(id, buffer, buffer_len, 0) < 0) {
}
buffer[buffer_len] = '\0';
- if (sscanf(buffer, "%d$%[^$]$%d", &response_req, value, &ret) < 3)
+ if (sscanf(buffer, "%d$%[^$]$%d", &response_req, value_string, &ret) < 3)
return -EINVAL;
if (response_req != REQUEST_GET_VALUE_STRING) {
return -EINVAL;
}
+ *value = g_strdup(value_string);
+
return ret;
}
int pass_resource_monitor_get_value_uint(int id, int resource_id, u_int64_t attr, u_int32_t *value);
int pass_resource_monitor_get_value_uint64(int id, int resource_id, u_int64_t attr, u_int64_t *value);
int pass_resource_monitor_get_value_double(int id, int resource_id, u_int64_t attr, double *value);
-int pass_resource_monitor_get_value_string(int id, int resource_id, u_int64_t attr, char *value);
+int pass_resource_monitor_get_value_string(int id, int resource_id, u_int64_t attr, char **value);
/**
* @brief Get [int/int64/uint/uint64/double/string] array of resource attribute
EXPECT_EQ(ret, 0);
break;
case DATA_TYPE_STRING:
- char value_str[BUFF_MAX];
+ {
+ char *value_str = NULL;
ret = pass_resource_monitor_get_value_string(mon_id, res_id,
- attrs[i].attr_id, value_str);
+ attrs[i].attr_id, &value_str);
+ g_free(value_str);
EXPECT_EQ(ret, 0);
break;
+ }
case DATA_TYPE_ARRAY:
int length;
* limitations under the License.
*/
+#include <glib.h>
+
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int32_t value_int32;
int64_t value_int64;
double value_double;
- char value_string[BUFF_MAX];
+ char *value_string;
};
static struct resource_attr_data cpu_attrs[] = {
ret = pass_resource_monitor_get_value_string(
res->mon_id, res->res_id,
res->attrs[i].id,
- res->attrs[i].value_string);
+ &res->attrs[i].value_string);
if (ret < 0) break;
printf("%40s | %-5s | %s",
res->attrs[i].value_string,
res->attrs[i].unit, res->attrs[i].desc);
+ g_free(res->attrs[i].value_string);
break;
case DATA_TYPE_ARRAY:
ret = get_resource_attr_array_value(res, i);