config-deserializer: fixed config to meet new requirements 42/182242/3
authorMichal Kolodziejski <m.kolodziejs@samsung.com>
Thu, 21 Jun 2018 13:22:31 +0000 (15:22 +0200)
committerMichal Kolodziejski <m.kolodziejs@samsung.com>
Fri, 22 Jun 2018 10:25:38 +0000 (12:25 +0200)
Change-Id: I10df6a9aa39194e509de9ae8c0eb8928583bc14e
Signed-off-by: Michal Kolodziejski <m.kolodziejs@samsung.com>
src/CMakeLists.txt
src/config.h
src/task_factory.c

index 91c34be..b8eff64 100644 (file)
@@ -2,6 +2,7 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(APP_PKGS REQUIRED
        glib-2.0
        dlog
+       json-glib-1.0
 )
 
 FOREACH (flag ${APP_PKGS_CFLAGS})
index e90df06..55514b7 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __CONFIG_H_
 #define __CONFIG_H_
 
+#define APP_ID_REGEX_MAX_LEN 255
+
 /**
  * @brief Config scope options.
  */
@@ -33,9 +35,14 @@ typedef enum config_scope
     APPS,
 
     /**
-     * @brief Observe one ore more CPU core usage.
+     * @brief Observe top usage of memory or cpu.
      */
-    CORES
+    TOP,
+
+    /**
+     * @brief Observe load average of the system.
+     */
+    LOAD_AVG,
 } config_scope_e;
 
 /**
@@ -55,38 +62,75 @@ typedef enum config_options
 } config_options_e;
 
 /**
- * @brief Config structure.
- * @remarks
- *     If scope is set to system field config_data is ignored.
- *     If scope is set to apps or cores, config_data must contains list of apps or core numbers accordingly.
+ * @brief Config app data structure.
  */
-typedef struct config
+typedef struct config_data_app
 {
     /**
-     * @brief Config scope.
+     * @brief Config options.
      */
-    config_scope_e scope;
+    config_options_e options;
+
+    /**
+     * @brief String containing regular expression with app id.
+     */
+    char app_id[APP_ID_REGEX_MAX_LEN+1];
+} config_data_app_t;
 
+/**
+ * @brief Config top data structure.
+ */
+typedef struct config_data_top
+{
     /**
-     * @brief Null-terminated array of strings with config data.
-     * @remarks It can contain list of applications or cores number.
+     * @brief Config options.
      */
-    char **config_data;
+    config_options_e options;
 
     /**
-     *  @brief Size of config_data array.
+     * @brief Length of top.
      */
-    size_t config_data_size;
+    long top;
+} config_data_top_t;
 
+/**
+ * @brief Config system data structure.
+ */
+typedef struct config_data_system
+{
     /**
      * @brief Config options.
      */
     config_options_e options;
+} config_data_system_t;
+
+/**
+ * @brief Config structure.
+ * @remarks
+ *     If scope is set to system field config_data is ignored.
+ *     If scope is set to apps or cores, config_data must contains list of apps or core numbers accordingly.
+ */
+typedef struct config
+{
+    /**
+     * @brief Config scope.
+     */
+    config_scope_e scope;
 
     /**
      * @brief Task frequency in seconds.
      */
-    int frequency;
+    long frequency;
+
+    /**
+     * Config data.
+     */
+    union _data
+    {
+        config_data_app_t apps;
+        config_data_top_t top;
+        config_data_system_t system;
+    } data;
 } config_t;
 
 #endif
\ No newline at end of file
index 61ce91c..efa536e 100644 (file)
@@ -35,9 +35,10 @@ task_t *task_factory_create_single(const config_t *config)
     switch(config->scope)
     {
         case SYSTEM:
-            return create_system_report_task(config->options, config->frequency);
+            return create_system_report_task(config->data.system.options, config->frequency);
         case APPS:
-        case CORES:
+        case TOP:
+        case LOAD_AVG:
         default:
             return NULL;
     }