Skip to content

Commit 06835a4

Browse files
committed
More revision of map instance origin block/allow scopes; improvements to mpr_tbl
1 parent 827e5a9 commit 06835a4

21 files changed

Lines changed: 673 additions & 563 deletions

File tree

bindings/csharp/Libmapper.NET/Map.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,30 @@ public int GetSignalIndex(Signal signal, Location location)
206206
}
207207

208208
[DllImport("mapper", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
209-
private static extern int mpr_map_allow_instance_origin(IntPtr map, IntPtr dev);
209+
private static extern int mpr_map_allow_origin(IntPtr map, IntPtr dev);
210210

211211
/// <summary>
212212
/// Add an instance origin scope to this map.
213213
/// </summary>
214214
/// <param name="device">The device to add as an instance origin scope for this map</param>
215215
/// <returns>The same map instance to allow for chaining</returns>
216-
public Map AllowInstanceOrigin(Device device)
216+
public Map AllowOrigin(Device device)
217217
{
218-
mpr_map_allow_instance_origin(NativePtr, device.NativePtr);
218+
mpr_map_allow_origin(NativePtr, device.NativePtr);
219219
return this;
220220
}
221221

222222
[DllImport("mapper", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
223-
private static extern int mpr_map_block_instance_origin(IntPtr map, IntPtr dev);
223+
private static extern int mpr_map_block_origin(IntPtr map, IntPtr dev);
224224

225225
/// <summary>
226226
/// Remove a signal instance origin scope from this map.
227227
/// </summary>
228228
/// <param name="device">The device to remove as a signal instance origin scope from this map</param>
229229
/// <returns>The same map instance to allow for chaining</returns>
230-
public Map BlockInstanceOrigin(Device device)
230+
public Map BlockOrigin(Device device)
231231
{
232-
mpr_map_block_instance_origin(NativePtr, device.NativePtr);
232+
mpr_map_block_origin(NativePtr, device.NativePtr);
233233
return this;
234234
}
235235
}

bindings/java/mapper/Map.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public Map(mapper.Signal _source, mapper.Signal _destination) {
3434
public native Map refresh();
3535

3636
/* property: instance origin scopes */
37-
public native Map allowInstanceOrigin(mapper.Device dev);
38-
public native Map blockInstanceOrigin(mapper.Device dev);
37+
public native Map allowOrigin(mapper.Device dev);
38+
public native Map blockOrigin(mapper.Device dev);
3939

4040
/* property: ready */
4141
public native boolean ready();

bindings/java/mapperjni.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,26 +1778,26 @@ JNIEXPORT jobject JNICALL Java_mapper_Map_refresh
17781778
return obj;
17791779
}
17801780

1781-
JNIEXPORT jobject JNICALL Java_mapper_Map_allowInstanceOrigin
1781+
JNIEXPORT jobject JNICALL Java_mapper_Map_allowOrigin
17821782
(JNIEnv *env, jobject obj, jobject jdev)
17831783
{
17841784
mpr_map map = (mpr_map)get_mpr_obj_from_jobject(env, obj);
17851785
if (map) {
17861786
mpr_dev dev = (mpr_dev)get_mpr_obj_from_jobject(env, jdev);
17871787
if (dev)
1788-
mpr_map_allow_instance_origin(map, dev);
1788+
mpr_map_allow_origin(map, dev);
17891789
}
17901790
return obj;
17911791
}
17921792

1793-
JNIEXPORT jobject JNICALL Java_mapper_Map_blockInstanceOrigin
1793+
JNIEXPORT jobject JNICALL Java_mapper_Map_blockOrigin
17941794
(JNIEnv *env, jobject obj, jobject jdev)
17951795
{
17961796
mpr_map map = (mpr_map)get_mpr_obj_from_jobject(env, obj);
17971797
if (map) {
17981798
mpr_dev dev = (mpr_dev)get_mpr_obj_from_jobject(env, jdev);
17991799
if (dev)
1800-
mpr_map_block_instance_origin(map, dev);
1800+
mpr_map_block_origin(map, dev);
18011801
}
18021802
return obj;
18031803
}

bindings/python/libmapper/mapper.py.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ class Map(Object):
17171717
return 0 != mpr.mpr_map_get_is_ready(self._obj)
17181718
ready = property(get_is_ready)
17191719

1720-
def allow_instance_origin(self, device):
1720+
def allow_origin(self, device):
17211721
"""
17221722
Add a map instance origin scope
17231723

@@ -1735,12 +1735,12 @@ class Map(Object):
17351735
"""
17361736

17371737
if isinstance(device, Device):
1738-
mpr.mpr_map_allow_instance_origin.argtypes = [c_void_p, c_void_p]
1739-
mpr.mpr_map_allow_instance_origin.restype = None
1740-
mpr.mpr_map_allow_instance_origin(self._obj, device._obj)
1738+
mpr.mpr_map_allow_origin.argtypes = [c_void_p, c_void_p]
1739+
mpr.mpr_map_allow_origin.restype = None
1740+
mpr.mpr_map_allow_origin(self._obj, device._obj)
17411741
return self
17421742

1743-
def block_instance_origin(self, device):
1743+
def block_origin(self, device):
17441744
"""
17451745
Block a map instance origin scope
17461746

@@ -1758,9 +1758,9 @@ class Map(Object):
17581758
"""
17591759

17601760
if isinstance(device, Device):
1761-
mpr.mpr_map_block_instance_origin.argtypes = [c_void_p, c_void_p]
1762-
mpr.mpr_map_block_instance_origin.restype = None
1763-
mpr.mpr_map_block_instance_origin(self._obj, device._obj)
1761+
mpr.mpr_map_block_origin.argtypes = [c_void_p, c_void_p]
1762+
mpr.mpr_map_block_origin.restype = None
1763+
mpr.mpr_map_block_origin(self._obj, device._obj)
17641764
return self
17651765

17661766
class Graph(Object):

include/mapper/mapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void mpr_map_refresh(mpr_map map);
551551
* \param device Device to allow as a scope for this map. After taking effect, this setting
552552
* will allow instance updates originating at this device to be propagated
553553
* across the map. */
554-
void mpr_map_allow_instance_origin(mpr_map map, mpr_dev device);
554+
void mpr_map_allow_origin(mpr_map map, mpr_dev device);
555555

556556
/*! Remove an instance origin scope from this map. Map instance origin scope configures the
557557
* propagation of signal instance updates across the map. Changes to remote maps will not take
@@ -560,7 +560,7 @@ void mpr_map_allow_instance_origin(mpr_map map, mpr_dev device);
560560
* \param device Device to block as an instance origin scope for this map. After taking
561561
* effect, this setting will cause instance updates originating at this device
562562
* to be blocked from propagating across the map. */
563-
void mpr_map_block_instance_origin(mpr_map map, mpr_dev device);
563+
void mpr_map_block_origin(mpr_map map, mpr_dev device);
564564

565565
/** @} */ /* end of group Maps */
566566

include/mapper/mapper_cpp.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ namespace mapper {
840840
* setting will allow instance updates originating at this device to be
841841
* propagated across the Map.
842842
* \return Self. */
843-
inline Map& allow_instance_origin(const Device& dev);
843+
inline Map& allow_origin(const Device& dev);
844844

845845
/*! Remove an instance origin scope from this Map. Map instance origin scope configures the
846846
* propagation of signal instance updates across the map. Changes to remote maps will not
@@ -849,7 +849,7 @@ namespace mapper {
849849
* effect, this setting will cause instance updates originating at this
850850
* device to be blocked from propagating across the Map.
851851
* \return Self. */
852-
inline Map& block_instance_origin(const Device& dev);
852+
inline Map& block_origin(const Device& dev);
853853

854854
/*! Get the index of the Map endpoint matching a specific Signal.
855855
* \param sig The Signal to look for.
@@ -2641,11 +2641,11 @@ namespace mapper {
26412641
inline signal_type::signal_type(const Signal& sig)
26422642
{ _sig = (mpr_sig)sig; }
26432643

2644-
inline Map& Map::allow_instance_origin(const Device& dev)
2645-
{ mpr_map_allow_instance_origin(_obj, mpr_dev(dev)); RETURN_SELF }
2644+
inline Map& Map::allow_origin(const Device& dev)
2645+
{ mpr_map_allow_origin(_obj, mpr_dev(dev)); RETURN_SELF }
26462646

2647-
inline Map& Map::block_instance_origin(const Device& dev)
2648-
{ mpr_map_block_instance_origin(_obj, mpr_dev(dev)); RETURN_SELF }
2647+
inline Map& Map::block_origin(const Device& dev)
2648+
{ mpr_map_block_origin(_obj, mpr_dev(dev)); RETURN_SELF }
26492649

26502650
inline Device Signal::device() const
26512651
{ return Device(mpr_sig_get_dev(_obj)); }

src/device.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,32 @@ void mpr_dev_init(mpr_dev dev, int is_local, const char *name, mpr_id id)
143143

144144
/* these properties need to be added in alphabetical order */
145145
#define link(PROP, TYPE, DATA, FLAGS) \
146-
mpr_tbl_link_value(tbl, MPR_PROP_##PROP, 1, TYPE, DATA, FLAGS | PROP_SET);
147-
link(DATA, MPR_PTR, &dev->obj.data, MOD_LOCAL | INDIRECT | LOCAL_ACCESS);
148-
link(ID, MPR_INT64, &dev->obj.id, MOD_NONE);
146+
mpr_tbl_link_value(tbl, MPR_PROP_##PROP, 1, TYPE, DATA, FLAGS | MPR_TBL_SET);
147+
link(DATA, MPR_PTR, &dev->obj.data, MPR_TBL_MOD_LOC | MPR_TBL_INDIRECT | MPR_TBL_ACC_LOC);
148+
link(ID, MPR_INT64, &dev->obj.id, MPR_TBL_MOD_NONE);
149149
qry = mpr_graph_new_query(dev->obj.graph, 0, MPR_DEV, (void*)cmp_qry_linked, "v", &dev);
150-
link(LINKED, MPR_LIST, qry, MOD_NONE | PROP_OWNED);
151-
link(NAME, MPR_STR, &dev->name, MOD_NONE | INDIRECT | LOCAL_ACCESS);
152-
link(NUM_MAPS_IN, MPR_INT32, &dev->num_maps_in, MOD_NONE);
153-
link(NUM_MAPS_OUT, MPR_INT32, &dev->num_maps_out, MOD_NONE);
154-
link(NUM_SIGS_IN, MPR_INT32, &dev->num_inputs, MOD_NONE);
155-
link(NUM_SIGS_OUT, MPR_INT32, &dev->num_outputs, MOD_NONE);
156-
link(ORDINAL, MPR_INT32, &dev->ordinal, MOD_NONE);
150+
link(LINKED, MPR_LIST, qry, MPR_TBL_MOD_NONE | MPR_TBL_OWNED);
151+
link(NAME, MPR_STR, &dev->name, MPR_TBL_MOD_NONE | MPR_TBL_INDIRECT
152+
| MPR_TBL_ACC_LOC | MPR_TBL_OWNED);
153+
link(NUM_MAPS_IN, MPR_INT32, &dev->num_maps_in, MPR_TBL_MOD_NONE);
154+
link(NUM_MAPS_OUT, MPR_INT32, &dev->num_maps_out, MPR_TBL_MOD_NONE);
155+
link(NUM_SIGS_IN, MPR_INT32, &dev->num_inputs, MPR_TBL_MOD_NONE);
156+
link(NUM_SIGS_OUT, MPR_INT32, &dev->num_outputs, MPR_TBL_MOD_NONE);
157+
link(ORDINAL, MPR_INT32, &dev->ordinal, MPR_TBL_MOD_NONE);
157158
if (!is_local) {
159+
// why only local devs??
158160
qry = mpr_graph_new_query(dev->obj.graph, 0, MPR_SIG, (void*)cmp_qry_sigs,
159161
"hi", dev->obj.id, MPR_DIR_ANY);
160-
link(SIG, MPR_LIST, qry, MOD_NONE | PROP_OWNED);
162+
link(SIG, MPR_LIST, qry, MPR_TBL_MOD_NONE | MPR_TBL_OWNED);
161163
}
162-
link(STATUS, MPR_INT32, &dev->obj.status, MOD_NONE | LOCAL_ACCESS);
163-
link(SYNCED, MPR_TIME, &dev->synced, MOD_NONE | LOCAL_ACCESS);
164-
link(VERSION, MPR_INT32, &dev->obj.version, MOD_NONE);
164+
link(STATUS, MPR_INT32, &dev->obj.status, MPR_TBL_MOD_NONE | MPR_TBL_ACC_LOC);
165+
link(SYNCED, MPR_TIME, &dev->synced, MPR_TBL_MOD_NONE | MPR_TBL_ACC_LOC);
166+
link(VERSION, MPR_INT32, &dev->obj.version, MPR_TBL_MOD_NONE);
165167
#undef link
166168

167169
if (is_local)
168-
mpr_tbl_add_record(tbl, MPR_PROP_LIBVER, NULL, 1, MPR_STR, PACKAGE_VERSION, MOD_NONE);
169-
mpr_tbl_add_record(tbl, MPR_PROP_IS_LOCAL, NULL, 1, MPR_BOOL, &is_local, LOCAL_ACCESS | MOD_NONE);
170+
mpr_tbl_add_record(tbl, MPR_PROP_LIBVER, NULL, 1, MPR_STR, PACKAGE_VERSION, MPR_TBL_MOD_NONE);
171+
mpr_tbl_add_record(tbl, MPR_PROP_IS_LOCAL, NULL, 1, MPR_BOOL, &is_local, MPR_TBL_ACC_LOC | MPR_TBL_MOD_NONE);
170172
}
171173

172174
/*! Allocate and initialize a device. This function is called to create a new
@@ -180,6 +182,8 @@ mpr_dev mpr_dev_new(const char *name_prefix, mpr_graph graph)
180182
++name_prefix;
181183
TRACE_RETURN_UNLESS(!strchr(name_prefix, '/'), NULL, "error: character '/' "
182184
"is not permitted in device name.\n");
185+
TRACE_RETURN_UNLESS(!strchr(name_prefix, ' '), NULL, "error: character ' ' "
186+
"is not permitted in device name.\n");
183187
if (graph) {
184188
g = graph;
185189
}
@@ -299,7 +303,6 @@ void mpr_dev_free(mpr_dev dev)
299303
void mpr_dev_free_mem(mpr_dev dev)
300304
{
301305
FUNC_IF(free, dev->linked);
302-
FUNC_IF(free, dev->name);
303306
}
304307

305308
static void on_registered(mpr_local_dev dev)
@@ -319,11 +322,13 @@ static void on_registered(mpr_local_dev dev)
319322
qry = mpr_graph_new_query(dev->obj.graph, 0, MPR_SIG, (void*)cmp_qry_sigs,
320323
"hi", dev->obj.id, MPR_DIR_ANY);
321324
mpr_tbl_add_record(dev->obj.props.synced, MPR_PROP_SIG, NULL,
322-
1, MPR_LIST, qry, MOD_NONE | PROP_OWNED);
325+
1, MPR_LIST, qry, MPR_TBL_MOD_NONE | MPR_TBL_OWNED);
326+
/* the table makes a copy so we can free this query */
327+
mpr_list_free(qry);
323328
dev->registered = 1;
324329
dev->ordinal = dev->ordinal_allocator.val;
325330

326-
snprintf(dev->name + dev->prefix_len + 1, dev->prefix_len + 6, "%d", dev->ordinal);
331+
snprintf(dev->name + dev->prefix_len + 1, 5, "%d", dev->ordinal);
327332
name = strdup(dev->name);
328333
free(dev->name);
329334
dev->name = name;
@@ -1069,7 +1074,8 @@ int mpr_dev_set_from_msg(mpr_dev dev, mpr_msg msg)
10691074
break;
10701075
}
10711076
default:
1072-
updated += mpr_tbl_add_record_from_msg_atom(dev->obj.props.synced, atom, MOD_REMOTE);
1077+
updated += mpr_tbl_add_record_from_msg_atom(dev->obj.props.synced, atom,
1078+
MPR_TBL_MOD_REM);
10731079
break;
10741080
}
10751081
}

src/graph.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ mpr_graph mpr_graph_new(int subscribe_flags)
281281
/* TODO: consider whether graph objects should sync properties over the network. */
282282
tbl = g->obj.props.synced = mpr_tbl_new();
283283
mpr_tbl_link_value(tbl, MPR_PROP_DATA, 1, MPR_PTR, &g->obj.data,
284-
MOD_LOCAL | INDIRECT | LOCAL_ACCESS | PROP_SET);
285-
mpr_tbl_add_record(tbl, MPR_PROP_LIBVER, NULL, 1, MPR_STR, PACKAGE_VERSION, MOD_NONE);
284+
MPR_TBL_MOD_LOC | MPR_TBL_INDIRECT | MPR_TBL_ACC_LOC | MPR_TBL_SET);
285+
mpr_tbl_add_record(tbl, MPR_PROP_LIBVER, NULL, 1, MPR_STR, PACKAGE_VERSION, MPR_TBL_MOD_NONE);
286286
/* TODO: add object queries as properties. */
287287

288288
g->expr_eval_buff = mpr_expr_new_eval_buffer(NULL);
@@ -607,8 +607,6 @@ mpr_dev mpr_graph_get_dev_by_name(mpr_graph g, const char *name)
607607
mpr_sig mpr_graph_add_sig(mpr_graph g, const char *name, const char *dev_name, mpr_msg msg)
608608
{
609609
mpr_sig sig = 0;
610-
int rc = 0, updated = 0;
611-
612610
mpr_dev dev = mpr_graph_get_dev_by_name(g, dev_name);
613611
if (dev) {
614612
sig = mpr_dev_get_sig_by_name(dev, name);
@@ -618,31 +616,27 @@ mpr_sig mpr_graph_add_sig(mpr_graph g, const char *name, const char *dev_name, m
618616
else
619617
dev = mpr_graph_add_dev(g, dev_name, NULL, NULL, 1);
620618

621-
if (!sig) {
619+
if (sig) {
620+
int updated = mpr_sig_set_from_msg(sig, msg);
621+
#ifdef DEBUG
622+
trace_graph(g, "updated %d props for signal ", updated);
623+
mpr_prop_print(1, MPR_SIG, sig);
624+
printf("\n");
625+
#endif
626+
if (updated)
627+
mpr_graph_call_cbs(g, (mpr_obj)sig, MPR_SIG, MPR_STATUS_MODIFIED);
628+
}
629+
else if ((sig = (mpr_sig)mpr_list_add_item((void**)&g->sigs, mpr_sig_get_struct_size(0), 0))) {
622630
int num_inst = 1;
623-
sig = (mpr_sig)mpr_list_add_item((void**)&g->sigs, mpr_sig_get_struct_size(0), 0);
624631
mpr_obj_init((mpr_obj)sig, g, MPR_SIG);
625632
mpr_sig_init(sig, dev, 0, MPR_DIR_UNDEFINED, name, 0, 0, 0, 0, 0, &num_inst);
626-
rc = 1;
633+
mpr_sig_set_from_msg(sig, msg);
627634
#ifdef DEBUG
628635
trace_graph(g, "added signal ");
629636
mpr_prop_print(1, MPR_SIG, sig);
630637
printf("\n");
631638
#endif
632-
}
633-
634-
if (sig) {
635-
updated = mpr_sig_set_from_msg(sig, msg);
636-
#ifdef DEBUG
637-
if (!rc) {
638-
trace_graph(g, "updated %d props for signal ", updated);
639-
mpr_prop_print(1, MPR_SIG, sig);
640-
printf("\n");
641-
}
642-
#endif
643-
644-
if (rc || updated)
645-
mpr_graph_call_cbs(g, (mpr_obj)sig, MPR_SIG, rc ? MPR_STATUS_NEW : MPR_STATUS_MODIFIED);
639+
mpr_graph_call_cbs(g, (mpr_obj)sig, MPR_SIG, MPR_STATUS_NEW);
646640
}
647641
return sig;
648642
}

0 commit comments

Comments
 (0)