Skip to content
Browse files

Moved instance id map to device, compiles and tests ok.

  • Loading branch information...
1 parent 22b501d commit 846a9274b3a617e2e459f09e6944ef02099ed060 @malloch committed May 27, 2012
Showing with 115 additions and 112 deletions.
  1. +66 −2 src/device.c
  2. +10 −12 src/mapper_internal.h
  3. +3 −65 src/router.c
  4. +24 −23 src/signal.c
  5. +12 −10 src/types_internal.h
View
68 src/device.c
@@ -55,6 +55,7 @@ mapper_device mdev_new(const char *name_prefix, int initial_port,
md->admin->port.on_lock = mdev_on_port_and_ordinal;
md->admin->ordinal.on_lock = mdev_on_port_and_ordinal;
md->routers = 0;
+ md->instance_map = 0;
md->extra = table_new();
return md;
}
@@ -74,6 +75,19 @@ void mdev_free(mapper_device md)
msig_free(md->outputs[i]);
if (md->outputs)
free(md->outputs);
+ if (md->routers) {
+ while (md->routers) {
+ mdev_remove_router(md, md->routers);
+ }
+ }
+ if (md->instance_map) {
+ mapper_instance_map map = md->instance_map;
+ while (map) {
+ mapper_instance_map tmp = map->next;
+ free(map);
+ map = tmp;
+ }
+ }
if (md->extra)
table_free(md->extra, 1);
free(md);
@@ -147,7 +161,6 @@ static int handler_signal_instance(const char *path, const char *types,
lo_arg **argv, int argc, lo_message msg,
void *user_data)
{
- printf("handler_signal_instance\n");
mapper_signal sig = (mapper_signal) user_data;
mapper_device md = sig->device;
@@ -604,6 +617,57 @@ void mdev_remove_router(mapper_device md, mapper_router rt)
}
}
+void mdev_set_instance_map(mapper_device device, int local_id,
+ mapper_router router, int remote_id)
+{
+ mapper_instance_map map = device->instance_map;
+ while (map) {
+ if (map->local_id == local_id) {
+ map->router = router;
+ map->remote_id = remote_id;
+ return;
+ }
+ map = map->next;
+ }
+
+ // map not found, create it
+ map = (mapper_instance_map)calloc(1, sizeof(struct _mapper_instance_map));
+ map->local_id = local_id;
+ map->router = router;
+ map->remote_id = remote_id;
+ map->next = device->instance_map;
+ device->instance_map = map;
+}
+
+int mdev_get_local_instance_map(mapper_device device, int local_id,
+ mapper_router router, int *remote_id)
+{
+ mapper_instance_map map = device->instance_map;
+ while (map) {
+ if (map->local_id == local_id) {
+ router = map->router;
+ *remote_id = map->remote_id;
+ return 0;
+ }
+ map = map->next;
+ }
+ return 1;
+}
+
+int mdev_get_remote_instance_map(mapper_device device, mapper_router router,
+ int remote_id, int *local_id)
+{
+ mapper_instance_map map = device->instance_map;
+ while (map) {
+ if ((map->router == router) && (map->remote_id == remote_id)) {
+ *local_id = map->local_id;
+ return 0;
+ }
+ map = map->next;
+ }
+ return 1;
+}
+
/*! Called when once when the port is allocated and again when the
* ordinal is allocated, or vice-versa. Must start server when both
* have been allocated. (No point starting it earlier since we won't
@@ -665,7 +729,7 @@ static void unlock_liblo_error_mutex()
void mdev_start_server(mapper_device md)
{
- if (md->n_inputs > 0 && md->admin->port.locked && !md->server) {
+ if (md->admin->port.locked && !md->server) {
int i;
char port[16], *type_string = 0, *signal_get = 0;
View
22 src/mapper_internal.h
@@ -150,6 +150,16 @@ void mdev_start_server(mapper_device mdev);
void mdev_on_port_and_ordinal(mapper_device md,
mapper_admin_allocated_t *resource);
+
+void mdev_set_instance_map(mapper_device device, int local_id,
+ mapper_router router, int remote_id);
+
+int mdev_get_local_instance_map(mapper_device device, int local_id,
+ mapper_router router, int *remote_id);
+
+int mdev_get_remote_instance_map(mapper_device device, mapper_router router,
+ int remote, int *local);
+
const char *mdev_name(mapper_device md);
/***** Router *****/
@@ -173,18 +183,6 @@ mapper_connection mapper_router_add_connection(mapper_router router,
int mapper_router_remove_connection(mapper_router router,
mapper_connection connection);
-void mapper_router_set_id_map(mapper_router router,
- int local,
- int remote);
-
-int mapper_router_get_local_id_map(mapper_router router,
- int local,
- int *remote);
-
-int mapper_router_get_remote_id_map(mapper_router router,
- int remote,
- int *local);
-
/*! Find a router by remote address in a linked list of routers. */
mapper_router mapper_router_find_by_remote_address(mapper_router routers,
lo_address address);
View
68 src/router.c
@@ -20,7 +20,6 @@ mapper_router mapper_router_new(mapper_device device, const char *host,
router->device = device;
router->outgoing = 0;
router->remap_instances = remap_instances;
- router->instance_map = 0;
if (!router->remote_addr) {
mapper_router_free(router);
@@ -55,21 +54,12 @@ void mapper_router_free(mapper_router router)
sc = tmp;
}
}
- if (router->instance_map) {
- mapper_instance_map map = router->instance_map;
- while (map) {
- mapper_instance_map tmp = map->next;
- free(map);
- map = tmp;
- }
- }
free(router);
}
}
void mapper_router_send_signal(mapper_connection_instance ci, int id)
{
- printf("mapper_router_send_signal\n");
int i;
lo_message m;
if (!ci->connection->router->remote_addr)
@@ -265,68 +255,16 @@ int mapper_router_remove_connection(mapper_router router,
return 1;
}
-void mapper_router_set_id_map(mapper_router router, int local, int remote)
-{
- mapper_instance_map map = router->instance_map;
- while (map) {
- if (map->local == local) {
- map->remote = remote;
- return;
- }
- map = map->next;
- }
-
- // map not found, create it
- printf("writing id map: %i -> %i\n", remote, local);
- map = (mapper_instance_map)calloc(1, sizeof(mapper_instance_map));
- map->local = local;
- map->remote = remote;
- map->next = router->instance_map;
- router->instance_map = map;
- printf(" ID MAP:\n");
- map = router->instance_map;
- while (map) {
- printf(" %i -> %i\n", map->remote, map->local);
- map = map->next;
- }
-}
-
-int mapper_router_get_local_id_map(mapper_router router, int local, int *remote)
-{
- mapper_instance_map map = router->instance_map;
- while (map) {
- if (map->local == local) {
- *remote = map->remote;
- return 0;
- }
- map = map->next;
- }
- return 1;
-}
-
-int mapper_router_get_remote_id_map(mapper_router router, int remote, int *local)
-{
- mapper_instance_map map = router->instance_map;
- while (map) {
- if (map->remote == remote) {
- *local = map->local;
- return 0;
- }
- map = map->next;
- }
- return 1;
-}
-
mapper_router mapper_router_find_by_remote_address(mapper_router router,
lo_address address)
{
- const char *host = lo_address_get_hostname(router->remote_addr);
- const char *port = lo_address_get_port(router->remote_addr);
const char *host_to_match = lo_address_get_hostname(address);
const char *port_to_match = lo_address_get_port(address);
while (router) {
- if (strcmp(host, host_to_match)==0 && strcmp(port, port_to_match)==0)
+ const char *host = lo_address_get_hostname(router->remote_addr);
+ const char *port = lo_address_get_port(router->remote_addr);
+ if ((strcmp(host, host_to_match)==0) && (strcmp(port, port_to_match)==0))
return router;
router = router->next;
}
View
47 src/signal.c
@@ -244,7 +244,8 @@ mapper_signal_instance msig_find_instance_with_map(mapper_signal sig,
// Next find instance id mapping
int local_id;
- if (!mapper_router_get_remote_id_map(router, remote_id, &local_id))
+ if (mdev_get_remote_instance_map(sig->device, router,
+ remote_id, &local_id))
return 0;
// Use local id to find instance pointer
@@ -461,7 +462,7 @@ void msig_resume_instance(mapper_signal_instance si)
void msig_set_instance_allocation_mode(mapper_signal sig,
mapper_instance_allocation_type mode)
{
- if (sig && mode >= 0 && mode < N_MAPPER_INSTANCE_ALLOCATION_TYPES)
+ if (sig && (mode >= 0) && (mode < N_MAPPER_INSTANCE_ALLOCATION_TYPES))
sig->instance_allocation_type = mode;
}
@@ -543,7 +544,6 @@ mapper_signal_instance msig_get_instance_with_map(mapper_signal sig,
lo_address address,
int remote_id)
{
- printf("msig_get_instance_with_map\n");
if (!sig || !address)
return 0;
@@ -555,10 +555,10 @@ mapper_signal_instance msig_get_instance_with_map(mapper_signal sig,
return 0;
int local_id;
- if (!mapper_router_get_remote_id_map(router, remote_id, &local_id)) {
+ if (!mdev_get_remote_instance_map(sig->device, router,
+ remote_id, &local_id)) {
si = msig_find_instance_with_id(sig, local_id);
if (si) {
- printf("found existing instance\n");
return si;
}
}
@@ -575,10 +575,9 @@ mapper_signal_instance msig_get_instance_with_map(mapper_signal sig,
// If we got something, prepare it.
if (si) {
- printf("found reserve instance\n");
si->is_active = 1;
// TODO: could use instance mapping at sender-side also rather than rewriting native instance id???
- mapper_router_set_id_map(router, si->id, remote_id);
+ mdev_set_instance_map(sig->device, si->id, router, remote_id);
msig_instance_init(si, si->id);
return si;
}
@@ -615,14 +614,13 @@ mapper_signal_instance msig_get_instance_with_map(mapper_signal sig,
return 0;
stole:
- printf("found stolen instance\n");
/* value = NULL signifies release of the instance */
if (sig->handler)
sig->handler(
sig, stolen->id, &sig->props,
&stolen->history.timetag[stolen->history.position],
NULL);
- mapper_router_set_id_map(router, stolen->id, remote_id);
+ mdev_set_instance_map(sig->device, stolen->id, router, remote_id);
msig_instance_init(stolen, stolen->id);
return stolen;
}
@@ -808,7 +806,6 @@ void msig_update_instance(mapper_signal sig,
static
void msig_update_instance_internal(mapper_signal_instance si, void *value)
{
- printf("msig_update_instance_internal\n");
if (!si) return;
if (!si->signal) return;
if (!si->is_active) return;
@@ -868,31 +865,35 @@ void msig_free_connection_instance(mapper_connection_instance ci)
void msig_send_instance(mapper_signal_instance si)
{
- printf("msig_send_instance\n");
// for each connection, construct a mapped signal and send it
- int remote_id;
+ int remote_id, status;
+ mapper_router router = 0;
mapper_connection_instance ci = si->connections;
if (si->history.position == -1) {
while (ci) {
ci->history.position = -1;
if (!ci->connection->router->remap_instances)
- mapper_router_send_signal(ci, ci->parent->id);
- else if (!mapper_router_get_local_id_map(ci->connection->router,
- ci->parent->id,
- &remote_id))
- mapper_router_send_signal(ci, remote_id);
+ mapper_router_send_signal(ci, si->id);
+ else {
+ status = mdev_get_local_instance_map(si->signal->device, si->id,
+ router, &remote_id);
+ if (!status && (router == ci->connection->router))
+ mapper_router_send_signal(ci, remote_id);
+ }
ci = ci->next;
}
return;
}
while (ci) {
if (!ci->connection->router->remap_instances)
- remote_id = ci->parent->id;
- else if (mapper_router_get_local_id_map(ci->connection->router,
- ci->parent->id,
- &remote_id)) {
- ci = ci->next;
- continue;
+ remote_id = si->id;
+ else {
+ status = mdev_get_local_instance_map(si->signal->device, si->id,
+ router, &remote_id);
+ if (status || (router != ci->connection->router)) {
+ ci = ci->next;
+ continue;
+ }
}
if (mapper_connection_perform(ci->connection, &si->history, &ci->history))
if (mapper_clipping_perform(ci->connection, &ci->history))
View
22 src/types_internal.h
@@ -31,6 +31,7 @@ typedef struct _mapper_expr *mapper_expr;
struct _mapper_admin_allocated_t;
struct _mapper_device;
+struct _mapper_instance_map;
/**** String tables ****/
@@ -149,14 +150,6 @@ typedef struct _mapper_signal_connection {
* in the list. */
} *mapper_signal_connection;
-/*! The instance map is a linked list of int32 instance ids for coordinating
- * remote and local instances. */
-typedef struct _mapper_instance_map {
- int local; //!< Local instance id to map.
- int remote; //!< Remote instance id to map.
- struct _mapper_instance_map *next; //!< The next id map in the list.
-} *mapper_instance_map;
-
/*! The router structure is a linked list of routers each associated
* with a destination address that belong to a controller device. */
typedef struct _mapper_router {
@@ -170,8 +163,6 @@ typedef struct _mapper_router {
int remap_instances; /*!< 1 if the router should match
* instance ids with remote
* device, 0 otherwise. */
- mapper_instance_map instance_map; /*!< The list of instance id/context
- * mappings. */
} *mapper_router;
/**** Device ****/
@@ -201,6 +192,8 @@ typedef struct _mapper_device {
int flags; /*!< Bitflags indicating if information has already been
* sent in a given polling step. */
mapper_router routers;
+ struct _mapper_instance_map *instance_map; /*!< The list of instance context
+ * and id mappings. */
/*! Server used to handle incoming messages. NULL until at least
* one input has been registered and the incoming port has been
@@ -211,6 +204,15 @@ typedef struct _mapper_device {
struct _mapper_string_table *extra;
} *mapper_device;
+/*! The instance map is a linked list of int32 instance ids for coordinating
+ * remote and local instances. */
+typedef struct _mapper_instance_map {
+ int local_id; //!< Local instance id to map.
+ mapper_router router; //!< Pointer to router for remote device.
+ int remote_id; //!< Remote instance id to map.
+ struct _mapper_instance_map *next; //!< The next id map in the list.
+} *mapper_instance_map;
+
/*! Bit flags indicating if information has already been
* sent in a given polling step. */
#define FLAGS_WHO 0x01

0 comments on commit 846a927

Please sign in to comment.
Something went wrong with that request. Please try again.