summaryrefslogtreecommitdiff
path: root/src/irmd/registry.h
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-05 17:10:42 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-07-05 17:10:42 +0200
commitdb96f7d488681be47abfeec6c636fd4159a37660 (patch)
treeca4c17706164fbfe772a613225d87df22e6f35e0 /src/irmd/registry.h
parent51ccc34e0fe15aaf711f30fa8b63de1e1881029f (diff)
parent72469bafa9d81a5578f53ec40175001f4c77cff6 (diff)
downloadouroboros-db96f7d488681be47abfeec6c636fd4159a37660.tar.gz
ouroboros-db96f7d488681be47abfeec6c636fd4159a37660.zip
Merged in dstaesse/ouroboros/irmd-refactor (pull request #156)
irmd: Move registry to its own sources
Diffstat (limited to 'src/irmd/registry.h')
-rw-r--r--src/irmd/registry.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/irmd/registry.h b/src/irmd/registry.h
new file mode 100644
index 00000000..36b68dcd
--- /dev/null
+++ b/src/irmd/registry.h
@@ -0,0 +1,148 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * The IPC Resource Manager - Registry
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef OUROBOROS_IRMD_REGISTRY_H
+#define OUROBOROS_IRMD_REGISTRY_H
+
+#include <ouroboros/list.h>
+
+#include <stdint.h>
+#include <pthread.h>
+#include <sys/types.h>
+
+#define reg_entry_has_api(e, id) (reg_entry_get_reg_instance(e, id) != NULL)
+#define reg_entry_has_ap_name(e, name) (reg_entry_get_ap_name(e, name) != NULL)
+#define reg_entry_has_ap_auto(e, name) (reg_entry_get_reg_auto(e, name) != NULL)
+
+enum reg_name_state {
+ REG_NAME_NULL = 0,
+ REG_NAME_IDLE,
+ REG_NAME_AUTO_ACCEPT,
+ REG_NAME_AUTO_EXEC,
+ REG_NAME_FLOW_ACCEPT,
+ REG_NAME_FLOW_ARRIVED
+};
+
+enum reg_i_state {
+ REG_I_NULL = 0,
+ REG_I_SLEEP,
+ REG_I_WAKE
+};
+
+struct reg_instance {
+ struct list_head next;
+ pid_t api;
+
+ /* the api will block on this */
+ enum reg_i_state state;
+ pthread_cond_t wakeup;
+ pthread_mutex_t mutex;
+};
+
+/* an entry in the registry */
+struct reg_entry {
+ struct list_head next;
+
+ /* generic name */
+ char * name;
+
+ /* names of the aps that can listen to this name */
+ struct list_head ap_names;
+
+ enum reg_name_state state;
+
+ uint32_t flags;
+
+ /* auto execution info */
+ struct list_head auto_ap_info;
+
+ /* known instances */
+ struct list_head ap_instances;
+
+ char * req_ae_name;
+ int response;
+
+ pthread_cond_t acc_signal;
+ pthread_mutex_t state_lock;
+};
+
+struct reg_auto {
+ struct list_head next;
+ char * ap_name;
+ char ** argv;
+};
+
+struct reg_ap_name {
+ struct list_head next;
+ char * ap_name;
+};
+
+struct reg_instance * reg_instance_create(pid_t api);
+void reg_instance_destroy(struct reg_instance * i);
+
+void reg_instance_sleep(struct reg_instance * i);
+void reg_instance_wake(struct reg_instance * i);
+
+struct reg_entry * reg_entry_create();
+struct reg_entry * reg_entry_init(struct reg_entry * e,
+ char * name,
+ char * ap_name,
+ uint32_t flags);
+void reg_entry_destroy(struct reg_entry * e);
+
+struct reg_ap_name * reg_entry_get_ap_name(struct reg_entry * e,
+ char * ap_name);
+struct reg_instance * reg_entry_get_reg_instance(struct reg_entry * e,
+ pid_t api);
+
+struct reg_auto * reg_entry_get_reg_auto(struct reg_entry * e,
+ char * ap_name);
+pid_t reg_entry_resolve_api(struct reg_entry * e);
+char ** reg_entry_resolve_auto(struct reg_entry * e);
+
+int registry_add_entry(struct list_head * registry,
+ char * name,
+ char * ap_name,
+ uint16_t flags);
+int registry_add_ap_auto(struct list_head * registry,
+ char * name,
+ char * ap_name,
+ char ** argv);
+int registry_remove_ap_auto(struct list_head * registry,
+ char * name,
+ char * ap_name);
+struct reg_instance * registry_add_ap_instance(struct list_head * registry,
+ char * name,
+ pid_t api);
+int registry_remove_ap_instance(struct list_head * registry,
+ char * name,
+ pid_t api);
+struct reg_entry * registry_get_entry_by_name(struct list_head * registry,
+ char * name);
+struct reg_entry * registry_get_entry_by_ap_name(struct list_head * registry,
+ char * ap_name);
+struct reg_entry * registry_get_entry_by_ap_id(struct list_head * registry,
+ pid_t api);
+void registry_del_name(struct list_head * registry,
+ char * name);
+
+#endif