config: change matchers to filter 14/185514/3
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Tue, 31 Jul 2018 08:02:20 +0000 (10:02 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 2 Aug 2018 08:45:45 +0000 (10:45 +0200)
Change name from matcher to filter.
Now if no filter is defined, the PROCESS task
will return all available process info.

Change-Id: Ia26df85dbb6a7e48e4ca3557d6ff7f1e8c0b998f

schemas/config.example.json
schemas/config.schema.json
src/config-deserializer.c
src/config.h
src/json-schema-defs.h
src/task-factory.c

index 96d640e..7c7967f 100644 (file)
@@ -9,7 +9,7 @@
         {
             "type" : "PROCESS",
             "frequency" : 10,
-            "matchers" : [
+            "filters" : [
                { "app_id": "org.tizen.clock" },
                { "exe": "/usr/bin/python" }
             ]
index 8d1dfa7..2f4dbc2 100644 (file)
@@ -25,7 +25,7 @@
             "required": [ "type", "frequency" ]
         },
 
-        "matcher" : {
+        "filter" : {
             "type" : "object",
             "properties": {
                 "exe" : { "type" :"string" },
             "properties": {
                 "type" : { "const": "PROCESS" },
                 "frequency" : { "type" : "integer" },
-                "matchers" : {
+                "filters" : {
                    "type" : ["array"],
                    "items": {
-                      "$ref": "#/definitions/matcher"
+                      "$ref": "#/definitions/filter"
                    }
                 }
             },
index 906257a..4666760 100644 (file)
@@ -113,7 +113,7 @@ static void config_array_iterate_func(JsonArray *array, guint index, JsonNode *e
     {
         configs[index].scope = PROCESS;
 
-               configs[index].data.process = config_parse_process_data(json_object_get_array_member(entry, SCHEMA_REQUEST_DATA_MATCHERS));
+               configs[index].data.process = config_parse_process_data(json_object_get_array_member(entry, SCHEMA_REQUEST_DATA_FILTERS));
     }
     else if (g_strcmp0(type, SCHEMA_TYPE_LOAD_AVG) == 0)
     {
@@ -128,11 +128,11 @@ static const char *json_object_safe_get_string_member(JsonObject *obj, const cha
        return NULL;
 }
 
-static void _process_foreach_matcher(JsonArray *array, guint index,
+static void _process_foreach_filter(JsonArray *array, guint index,
                JsonNode *node, gpointer user_data)
 {
        config_data_process_t *ret = user_data;
-       struct matcher match;
+       struct filter filter;
 
        JsonObject *elem = json_node_get_object(node);
        if (!elem) return;
@@ -140,10 +140,10 @@ static void _process_foreach_matcher(JsonArray *array, guint index,
        const char *appid = json_object_safe_get_string_member(elem, SCHEMA_RESULT_APP_ID);
        const char *exe = json_object_safe_get_string_member(elem, SCHEMA_RESULT_EXE);
 
-       match.app_id = appid ? strdup(appid) : NULL;
-       match.exe = exe ? strdup(exe) : NULL;
+       filter.app_id = appid ? strdup(appid) : NULL;
+       filter.exe = exe ? strdup(exe) : NULL;
 
-       ret->matchers[ret->n_matchers++] = match;
+       ret->filters[ret->n_filters++] = filter;
 }
 
 static config_data_process_t config_parse_process_data(JsonArray *array)
@@ -153,10 +153,10 @@ static config_data_process_t config_parse_process_data(JsonArray *array)
        int len = json_array_get_length(array);
        if (len == 0) return ret;
 
-       ret.matchers = calloc(len, sizeof(struct matcher));
-       ret.n_matchers = 0;
+       ret.filters = calloc(len, sizeof(struct filter));
+       ret.n_filters = 0;
 
-       json_array_foreach_element(array, _process_foreach_matcher, &ret);
+       json_array_foreach_element(array, _process_foreach_filter, &ret);
 
        return ret;
 }
@@ -185,7 +185,7 @@ void free_configs(config_t *configs, int len)
        for (int i=0; i < len; ++i) {
                switch (configs[i].scope) {
                        case PROCESS:
-                               free(configs[i].data.process.matchers);
+                               free(configs[i].data.process.filters);
                                break;
                        default:
                                break;
index 4181ce0..e633677 100644 (file)
@@ -46,9 +46,9 @@ typedef enum config_scope
 } config_scope_e;
 
 /**
- * @brief Matcher data
+ * @brief Filter data
  */
-struct matcher {
+struct filter {
        const char *app_id;
        const char *exe;
 };
@@ -58,8 +58,8 @@ struct matcher {
  */
 typedef struct config_data_process
 {
-       struct matcher *matchers;
-       int n_matchers;
+       struct filter *filters;
+       int n_filters;
 } config_data_process_t;
 
 typedef enum config_top_subject {
index 3f21885..74b1389 100644 (file)
@@ -38,7 +38,7 @@
 #define SCHEMA_TOP "top"
 #define SCHEMA_ID "id"
 
-#define SCHEMA_REQUEST_DATA_MATCHERS "matchers"
+#define SCHEMA_REQUEST_DATA_FILTERS "filters"
 
 #define SCHEMA_RESULT_DATA_SYSTEM "system_data"
 #define SCHEMA_RESULT_DATA_LOAD_AVG "load_avg_data"
index d03202a..2e011d3 100644 (file)
@@ -133,14 +133,18 @@ static bool _report_generator_process_filter_cb(struct process *proc, void *user
 {
        config_data_process_t *data = user_data;
 
-       for (int i = 0; i < data->n_matchers; ++i) {
-               struct matcher *match = &data->matchers[i];
-               if (match->app_id && process_get_appid(proc)) {
-                       if (strcmp(match->app_id, process_get_appid(proc)) == 0)
+       if (data->n_filters == 0) {
+               return true;
+       }
+
+       for (int i = 0; i < data->n_filters; ++i) {
+               struct filter *filter = &data->filters[i];
+               if (filter->app_id && process_get_appid(proc)) {
+                       if (strcmp(filter->app_id, process_get_appid(proc)) == 0)
                                return true;
                }
-               if (match->exe && process_get_exe(proc)) {
-                       if (strcmp(match->exe, process_get_exe(proc)) == 0)
+               if (filter->exe && process_get_exe(proc)) {
+                       if (strcmp(filter->exe, process_get_exe(proc)) == 0)
                                return true;
                }
        }