4 struct aura_export_table *aura_etable_create(
struct aura_node *owner,
int n)
8 slog(4, SLOG_DEBUG,
"etable: Creating etable for %d elements, %d hash entries", n, nel);
9 struct aura_export_table *tbl = calloc(1,
10 sizeof(
struct aura_export_table) +
11 n *
sizeof(
struct aura_object));
15 hcreate_r(nel, &tbl->index);
24 void aura_etable_add(
struct aura_export_table *tbl,
33 struct aura_object *target;
35 if (tbl->next >= tbl->size)
36 BUG(tbl->owner,
"Internal BUG: Insufficient export table storage");
38 target = aura_etable_find(tbl, name);
40 BUG(tbl->owner,
"Internal BUG: Duplicate export table entry: %s", name);
42 target = &tbl->objects[tbl->next];
43 target->id = tbl->next++;
45 BUG(tbl->owner,
"Internal BUG: object name can't be nil");
47 target->name = strdup(name);
51 target->arg_fmt = strdup(argfmt);
53 target->ret_fmt = strdup(retfmt);
55 if ((argfmt && !target->arg_fmt) ||
56 (retfmt && !target->ret_fmt))
57 BUG(tbl->owner,
"Internal allocation error");
60 target->arg_pprinted = aura_fmt_pretty_print(argfmt, &arg_valid, &target->num_args);
63 target->ret_pprinted = aura_fmt_pretty_print(retfmt, &ret_valid, &target->num_rets);
65 target->valid = arg_valid && ret_valid;
67 slog(0, SLOG_WARN,
"Object %d (%s) has corrupt export table",
68 target->id, target->name);
71 target->arglen = aura_fmt_len(tbl->owner, argfmt);
72 target->retlen = aura_fmt_len(tbl->owner, retfmt);
76 e.data = (
char *) target;
77 ret = hsearch_r(e, ENTER, &ep, &tbl->index);
79 BUG(tbl->owner,
"Internal BUG: Error adding entry to hash table");
83 struct aura_object *aura_etable_find(
struct aura_export_table *tbl,
88 struct aura_object *target = NULL;
93 e.key = (
char *) name;
95 ret = hsearch_r(e, FIND, &ep, &tbl->index);
97 target = (
struct aura_object *) ep->data;
101 struct aura_object *aura_etable_find_id(
struct aura_export_table *tbl,
106 return &tbl->objects[id];
109 #define format_matches(one, two) \
111 (one && two && strcmp(one, two)))
113 static int object_is_equal(
struct aura_object *one,
struct aura_object *two)
118 if (strcmp(one->name, two->name) != 0)
122 if (!format_matches(one->arg_fmt, two->arg_fmt))
126 if (!format_matches(one->ret_fmt, two->ret_fmt))
132 static int migrate_object(
struct aura_object *src,
struct aura_object *dst)
137 if (object_is_equal(src, dst)) {
138 dst->calldonecb = src->calldonecb;
140 slog(4, SLOG_DEBUG,
"etable: Successful migration of obj %d->%d (%s)",src->id, dst->id, dst->name);
145 static void etable_migrate(
struct aura_export_table *old,
struct aura_export_table *
new)
148 struct aura_node *node;
152 if (old->owner != new->owner)
153 BUG(old->owner,
"BUG during export table migration: etable owners are not equal!");
169 for(i=0; i < old->next; i++) {
170 struct aura_object *src = &old->objects[i];
171 struct aura_object *dst = &
new->objects[i];
174 if (migrate_object(src, dst))
178 dst = aura_etable_find(
new, src->name);
179 if (migrate_object(src, dst))
182 if (src->calldonecb) {
186 if (node->object_migration_failed_cb)
187 node->object_migration_failed_cb(node, src,
188 node->object_migration_failed_arg);
191 "Migration of callbacks for object %s failed\n", src->name);
193 "Set aura_object_migration_failed_cb() callback to disable this warning\n");
199 void aura_etable_activate(
struct aura_export_table *tbl)
201 struct aura_node *node = tbl->owner;
204 slog(0, SLOG_FATAL,
"Internal BUG: Attemped to change export table when transport is online");
208 if (node->is_opening)
209 BUG(node,
"Transport BUG: Do not call aura_etable_activate in open()");
211 if (node->etable_changed_cb)
212 node->etable_changed_cb(node, node->tbl, tbl, node->etable_changed_arg);
215 etable_migrate(node->tbl, tbl);
216 aura_etable_destroy(node->tbl);
223 void aura_etable_destroy(
struct aura_export_table *tbl)
228 for (i=0; i < tbl->next; i++) {
229 struct aura_object *tmp;
230 tmp=&tbl->objects[i];
236 if (tmp->arg_pprinted)
237 free(tmp->arg_pprinted);
238 if (tmp->ret_pprinted)
239 free(tmp->ret_pprinted);
242 hdestroy_r(&tbl->index);
static int aura_get_status(struct aura_node *node)