{
JsonGenerator *gen = json_generator_new();
if (!gen) {
- g_object_unref(builder); \
+ g_object_unref(builder);
return NULL;
}
- JsonNode *root = json_builder_get_root(builder); \
+ JsonNode *root = json_builder_get_root(builder);
json_generator_set_root(gen, root);
char *str = json_generator_to_data(gen, NULL);
g_object_unref(gen);
return ret; \
}
+#define IMPLEMENT_ARRAY_SERIALIZER_FUNC(func_name, param_type, serializer) \
+char* \
+func_name(param_type **reports) \
+{\
+ JsonBuilder *builder = json_builder_new(); \
+ if (!builder) return NULL; \
+ serializer(builder, reports); \
+ char *ret = _serialize(builder); \
+ g_object_unref(builder); \
+ return ret; \
+}
+
static void system_load_average_report_to_json_object(JsonBuilder *builder, struct system_load_average_report *report)
{
json_builder_begin_object(builder);
json_builder_end_object(builder);
}
+static void top_cpu_usage_reports_to_json_object(JsonBuilder *builder, struct app_cpu_usage_report **reports)
+{
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_TYPE);
+ json_builder_add_string_value(builder, SCHEMA_TYPE_PROCESS);
+
+ json_builder_set_member_name(builder, SCHEMA_TARGET);
+ json_builder_add_string_value(builder, SCHEMA_TARGET_CPU);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_TOP);
+ json_builder_begin_array(builder);
+
+ int i = 0;
+ while(reports[i])
+ {
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_ID);
+ json_builder_add_string_value(builder, reports[i]->app_id);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_PID);
+ json_builder_add_double_value(builder, reports[i]->process_report.pid);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT);
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_TIME);
+ json_builder_add_double_value(builder, reports[i]->process_report.time);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE);
+ json_builder_add_double_value(builder, reports[i]->process_report.usage);
+
+ json_builder_end_object(builder);
+
+ json_builder_end_object(builder);
+ i++;
+ }
+
+ json_builder_end_array(builder);
+ json_builder_end_object(builder);
+}
+
+static void top_memory_usage_reports_to_json_object(JsonBuilder *builder, struct app_memory_usage_report **reports)
+{
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_TYPE);
+ json_builder_add_string_value(builder, SCHEMA_TYPE_PROCESS);
+
+ json_builder_set_member_name(builder, SCHEMA_TARGET);
+ json_builder_add_string_value(builder, SCHEMA_TARGET_MEMORY);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_TOP);
+ json_builder_begin_array(builder);
+
+ int i = 0;
+ while(reports[i])
+ {
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_ID);
+ json_builder_add_string_value(builder, reports[i]->app_id);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_PID);
+ json_builder_add_double_value(builder, reports[i]->process_report.pid);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT);
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_TIME);
+ json_builder_add_double_value(builder, reports[i]->process_report.time);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE);
+ json_builder_add_double_value(builder, reports[i]->process_report.usage);
+
+ json_builder_end_object(builder);
+
+ json_builder_end_object(builder);
+ i++;
+ }
+
+ json_builder_end_array(builder);
+ json_builder_end_object(builder);
+}
+
static void apps_cpu_usage_report_to_json_object(JsonBuilder *builder, struct app_cpu_usage_report *report)
{
- //TODO
- //implement after report API changes
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_TYPE);
+ json_builder_add_string_value(builder, SCHEMA_TYPE_PROCESS);
+
+ json_builder_set_member_name(builder, SCHEMA_TARGET);
+ json_builder_add_string_value(builder, SCHEMA_TARGET_CPU);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_PROCESS);
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_ID);
+ json_builder_add_string_value(builder, report->app_id);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_PID);
+ json_builder_add_double_value(builder, report->process_report.pid);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT);
+ json_builder_begin_object(builder);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_TIME);
+ json_builder_add_double_value(builder, report->process_report.time);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE);
+ json_builder_add_double_value(builder, report->process_report.usage);
+
+ json_builder_end_object(builder);
+ json_builder_end_object(builder);
+ json_builder_end_object(builder);
}
static void apps_memory_usage_report_to_json_object(JsonBuilder *builder, struct app_memory_usage_report *report)
{
- //TODO
- //implement after report API changes
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_TYPE);
+ json_builder_add_string_value(builder, SCHEMA_TYPE_PROCESS);
+
+ json_builder_set_member_name(builder, SCHEMA_TARGET);
+ json_builder_add_string_value(builder, SCHEMA_TARGET_MEMORY);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_DATA_PROCESS);
+ json_builder_begin_object(builder);
+
+ json_builder_set_member_name(builder, SCHEMA_ID);
+ json_builder_add_string_value(builder, report->app_id);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_PID);
+ json_builder_add_double_value(builder, report->process_report.pid);
+
+ json_builder_set_member_name(builder, SCHEMA_RESULT_RESULT);
+ json_builder_begin_object(builder);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_TIME);
+ json_builder_add_double_value(builder, report->process_report.time);
+ json_builder_set_member_name(builder, SCHEMA_RESULT_USAGE);
+ json_builder_add_double_value(builder, report->process_report.usage);
+
+ json_builder_end_object(builder);
+ json_builder_end_object(builder);
+ json_builder_end_object(builder);
}
IMPLEMENT_SERIALIZER_FUNC(
struct app_memory_usage_report,
apps_memory_usage_report_to_json_object)
+IMPLEMENT_ARRAY_SERIALIZER_FUNC(
+ report_json_serializer_serialize_top_cpu_usage_reports,
+ struct app_cpu_usage_report,
+ top_cpu_usage_reports_to_json_object)
+
+IMPLEMENT_ARRAY_SERIALIZER_FUNC(
+ report_json_serializer_serialize_top_memory_usage_reports,
+ struct app_memory_usage_report,
+ top_memory_usage_reports_to_json_object)
+
* limitations under the License.
*/
-
#ifndef __REPORT_JSON_SERIALIZER_H_
#define __REPORT_JSON_SERIALIZER_H_
/**
* @brief Serializes system_load_average_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes system_memory_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes system_cpus_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes system_cpus_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes process_memory_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes process_memory_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes app_system_cpu_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
/**
* @brief Serializes app_memory_usage_report to json string
+ *
+ * @param[in] report Report structure with usage data.
+ *
* @return dynamically allocated string on NULL on error.
* @remark returned value should be released with @free
*/
char *report_json_serializer_serialize_apps_memory_usage_report(struct app_memory_usage_report *report);
+/**
+ * @brief Serializes app_system_cpu_usage_reports to json string
+ *
+ * @param[in] report NULL-terminated array of report structures with usage data.
+ *
+ * @return dynamically allocated string on NULL on error.
+ * @remark returned value should be released with @free
+ */
+char *report_json_serializer_serialize_top_cpu_usage_reports(struct app_cpu_usage_report **reports);
+
+/**
+ * @brief Serializes app_memory_usage_reports to json string
+ *
+ * @param[in] report NULL-terminated array of report structures with usage data.
+ *
+ * @return dynamically allocated string on NULL on error.
+ * @remark returned value should be released with @free
+ */
+char *report_json_serializer_serialize_top_memory_usage_reports(struct app_memory_usage_report **reports);
+
#endif