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,
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
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__ */
#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 {
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__ */
#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);
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,
}
}
+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)
{