resource: add definitions for binaries
authorJanos Kovacs <jankovac503@gmail.com>
Mon, 30 Sep 2013 09:43:57 +0000 (12:43 +0300)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Thu, 8 Jan 2015 16:37:11 +0000 (18:37 +0200)
Change-Id: Ia7d827f67583840528c7d970b06e9750572c39cf

src/resource/application-class.c
src/resource/client-api.h
src/resource/config-api.h
src/resource/data-types.h
src/resource/resource-set.c

index ec9a9c3..52e8b35 100644 (file)
@@ -104,6 +104,8 @@ static mqi_handle_t get_database_table(void);
 static void insert_into_application_class_table(const char *, uint32_t);
 
 
+
+
 mrp_application_class_t *mrp_application_class_create(const char *name,
                                                     uint32_t pri,
                                                     bool modal,
index 5f56dfa..2b86ef1 100644 (file)
@@ -68,6 +68,9 @@ mrp_resource_set_t *mrp_resource_set_create(mrp_resource_client_t *client,
                                             void *user_data);
 void mrp_resource_set_destroy(mrp_resource_set_t *resource_set);
 
+mrp_resource_set_definition_t *
+mrp_resource_set_get_definition_by_binary(const char *binary_name);
+
 uint32_t mrp_get_resource_set_id(mrp_resource_set_t *resource_set);
 
 mrp_resource_state_t
index 6d7f60a..6b6a8c1 100644 (file)
@@ -47,6 +47,9 @@ int mrp_application_class_print(char *buf, int len, bool with_resource_sets);
 
 int mrp_resource_owner_print(char *buf, int len);
 
+int mrp_resource_set_add_definition_for_binary(
+                                    mrp_resource_set_definition_t *definition);
+
 
 #endif  /* __MURPHY_RESOURCE_CONFIG_API_H__ */
 
index 7a347a0..d8b9c64 100644 (file)
 #define MRP_RESOURCE_MAX  (sizeof(mrp_resource_mask_t) * 8)
 #define MRP_ATTRIBUTE_MAX (sizeof(mrp_attribute_mask_t) * 8)
 
-typedef enum   mrp_resource_state_e     mrp_resource_state_t;
-typedef enum   mrp_resource_order_e     mrp_resource_order_t;
-typedef enum   mrp_resource_access_e    mrp_resource_access_t;
-typedef enum   mrp_resource_event_e     mrp_resource_event_t;
-
-typedef struct mrp_resource_client_s    mrp_resource_client_t;
-typedef union  mrp_attr_value_u         mrp_attr_value_t;
-typedef struct mrp_attr_def_s           mrp_attr_def_t;
-typedef struct mrp_attr_s               mrp_attr_t;
-typedef struct mrp_zone_def_s           mrp_zone_def_t;
-typedef struct mrp_zone_s               mrp_zone_t;
-typedef struct mrp_application_class_s  mrp_application_class_t;
-typedef struct mrp_resource_owner_s     mrp_resource_owner_t;
-typedef struct mrp_resource_set_s       mrp_resource_set_t;
-typedef struct mrp_resource_def_s       mrp_resource_def_t;
-typedef struct mrp_resource_s           mrp_resource_t;
-typedef struct mrp_resource_mgr_ftbl_s  mrp_resource_mgr_ftbl_t;
-typedef struct mrp_resource_mgr_s       mrp_resource_mgr_t;
-
-typedef struct mrp_resource_ownersref_s mrp_resource_ownersref_t;
-typedef struct mrp_resource_setref_s    mrp_resource_setref_t;
-
-typedef uint32_t                        mrp_resource_mask_t;
-typedef uint32_t                        mrp_attribute_mask_t;
-typedef uint32_t                        mrp_zone_mask_t;
+typedef enum   mrp_resource_state_e          mrp_resource_state_t;
+typedef enum   mrp_resource_order_e          mrp_resource_order_t;
+typedef enum   mrp_resource_access_e         mrp_resource_access_t;
+typedef enum   mrp_resource_event_e          mrp_resource_event_t;
+
+typedef struct mrp_resource_client_s         mrp_resource_client_t;
+typedef union  mrp_attr_value_u              mrp_attr_value_t;
+typedef struct mrp_attr_def_s                mrp_attr_def_t;
+typedef struct mrp_attr_s                    mrp_attr_t;
+typedef struct mrp_zone_def_s                mrp_zone_def_t;
+typedef struct mrp_zone_s                    mrp_zone_t;
+typedef struct mrp_application_class_s       mrp_application_class_t;
+typedef struct mrp_resource_owner_s          mrp_resource_owner_t;
+typedef struct mrp_resource_set_s            mrp_resource_set_t;
+typedef struct mrp_resource_def_s            mrp_resource_def_t;
+typedef struct mrp_resource_s                mrp_resource_t;
+typedef struct mrp_resource_mgr_ftbl_s       mrp_resource_mgr_ftbl_t;
+typedef struct mrp_resource_mgr_s            mrp_resource_mgr_t;
+
+typedef struct mrp_resource_ownersref_s      mrp_resource_ownersref_t;
+typedef struct mrp_resource_setref_s         mrp_resource_setref_t;
+
+typedef struct mrp_resource_set_definition_s mrp_resource_set_definition_t;
+
+typedef uint32_t                             mrp_resource_mask_t;
+typedef uint32_t                             mrp_attribute_mask_t;
+typedef uint32_t                             mrp_zone_mask_t;
 
 
 enum mrp_resource_state_e {
@@ -150,7 +152,13 @@ struct mrp_resource_mgr_ftbl_s  {
     mrp_manager_commit_func_t   commit;
 };
 
-
+struct mrp_resource_set_definition_s {
+    const char *binary_name;
+    const char *class_name;
+    bool        auto_release;
+    bool        dont_wait;
+    uint32_t    priority;
+};
 
 #endif  /* __MURPHY_DATA_TYPES_H__ */
 
index 12e56d7..5f9227b 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <murphy/resource/client-api.h>
 #include <murphy/resource/common-api.h>
+#include <murphy/resource/config-api.h>
 
 #include "resource-set.h"
 #include "application-class.h"
 static MRP_LIST_HOOK(resource_set_list);
 static uint32_t resource_set_count;
 static mrp_htbl_t *id_hash;
+static mrp_htbl_t *def_hash;
 
 static int add_to_id_hash(mrp_resource_set_t *);
 static void remove_from_id_hash(mrp_resource_set_t *);
 
+static int add_to_def_hash(mrp_resource_set_definition_t *);
+
 static mrp_resource_t *find_resource_by_name(mrp_resource_set_t *,const char*);
 #if 0
 static mrp_resource_t *find_resource_by_id(mrp_resource_set_t *, uint32_t);
@@ -75,6 +79,31 @@ uint32_t mrp_get_resource_set_count(void)
     return resource_set_count;
 }
 
+int
+mrp_resource_set_add_definition_for_binary(mrp_resource_set_definition_t *def)
+{
+    MRP_ASSERT(def, "invalid argument");
+
+    if (add_to_def_hash(def) < 0) {
+        mrp_log_error("attempt to add multiple resource definition for '%s'",
+                      def->binary_name);
+        return -1;
+    }
+
+    return 0;
+}
+
+mrp_resource_set_definition_t *
+mrp_resource_set_get_definition_by_binary(const char *binary_name)
+{
+    mrp_resource_set_definition_t *def;
+
+    MRP_ASSERT(binary_name, "invalid_argument");
+
+    return def_hash ? mrp_htbl_lookup(def_hash, binary_name) : NULL;
+}
+
+
 mrp_resource_set_t *mrp_resource_set_create(mrp_resource_client_t *client,
                                             bool auto_release,
                                             bool dont_wait,
@@ -588,6 +617,46 @@ static void remove_from_id_hash(mrp_resource_set_t *rset)
     }
 }
 
+static void init_def_hash(void)
+{
+    mrp_htbl_config_t cfg;
+
+    if (!def_hash) {
+        cfg.nentry  = 32;
+        cfg.comp    = mrp_string_comp;
+        cfg.hash    = mrp_string_hash;
+        cfg.free    = NULL;
+        cfg.nbucket = cfg.nentry;
+
+        def_hash = mrp_htbl_create(&cfg);
+
+        MRP_ASSERT(id_hash, "failed to make def_hash for binaries");
+    }
+}
+
+static int add_to_def_hash(mrp_resource_set_definition_t *def)
+{
+    mrp_resource_set_definition_t *copy;
+
+    MRP_ASSERT(def, "invalid argument");
+    MRP_ASSERT(def->binary_name && def->class_name, "inavlid definition");
+
+    init_def_hash();
+
+    copy = mrp_allocz(sizeof(mrp_resource_set_definition_t));
+    MRP_ASSERT(copy, "can't allocate memory");
+
+    copy->binary_name  = mrp_strdup(def->binary_name);
+    copy->class_name   = mrp_strdup(def->binary_name);
+    copy->auto_release = def->auto_release;
+    copy->dont_wait    = def->dont_wait;
+
+    if (!mrp_htbl_insert(def_hash, copy->binary_name, copy))
+        return -1;
+
+    return 0;
+}
+
 static mrp_resource_t *find_resource_by_name(mrp_resource_set_t *rset,
                                              const char *name)
 {