diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2012-04-16 14:52:39 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-19 10:45:43 (GMT) |
commit | 64a31c6a33854ff4d2a5f3844cfaed39cba78ee2 (patch) | |
tree | eb691d39878c6b7d742f72cae71f9c4650d1d5a0 /src/com | |
parent | bae6e6298a617b801a15cbdba13d6759d8b44f31 (diff) | |
download | stroke-64a31c6a33854ff4d2a5f3844cfaed39cba78ee2.zip stroke-64a31c6a33854ff4d2a5f3844cfaed39cba78ee2.tar.bz2 |
Add Signal and Slot classes with 3 parameters
MUC Admin requires Signals and Slots with 3 parameters so this patch adds
Signal/Slot classes which cater to 3 parameter values
Test-information:
tested with Work In Progress MUC Admin code
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/isode/stroke/signals/Signal3.java | 60 | ||||
-rw-r--r-- | src/com/isode/stroke/signals/Slot3.java | 22 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/com/isode/stroke/signals/Signal3.java b/src/com/isode/stroke/signals/Signal3.java new file mode 100644 index 0000000..b9151dc --- /dev/null +++ b/src/com/isode/stroke/signals/Signal3.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.signals; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * An approximation of the boost::signals system with 3 parameters + * @param <T1> Type 1 + * @param <T2> Type 2 + * @param <T3> Type 3 + */ +public class Signal3<T1, T2, T3> { + private final Map<SignalConnection, Slot3<T1, T2,T3> > binds_ = Collections.synchronizedMap( + new HashMap<SignalConnection, Slot3<T1, T2,T3> >()); + + /** + * Add a slot which will be notified + * @param bind slot, not null + * @return signal connection + */ + public SignalConnection connect(Slot3<T1, T2,T3> bind) { + final SignalConnection connection = new SignalConnection(); + binds_.put(connection, bind); + connection.onDestroyed.connect(new Slot() { + public void call() { + binds_.remove(connection); + } + }); + return connection; + } + + /** + * Notify all slots(listeners) + * @param p1 parameter value 1 + * @param p2 parameter value 2 + * @param p3 parameter value 3 + */ + public void emit(T1 p1, T2 p2,T3 p3) { + List<Slot3<T1,T2, T3>> binds = new ArrayList<Slot3<T1, T2, T3>>(); + binds.addAll(binds_.values()); + for (Slot3<T1, T2, T3> bind : binds) { + bind.call(p1, p2, p3); + } + } + + /** + * Remove all slots(listeners) + */ + public void disconnectAll() { + binds_.clear(); + } +} diff --git a/src/com/isode/stroke/signals/Slot3.java b/src/com/isode/stroke/signals/Slot3.java new file mode 100644 index 0000000..ee5ccbc --- /dev/null +++ b/src/com/isode/stroke/signals/Slot3.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.signals; + +/** + * Bind class for connecting to a signal with 3 parameters. + * @param <T1> Type 1 + * @param <T2> Type 2 + * @param <T3> Type 3 + */ +public interface Slot3<T1, T2,T3> { + /** + * This method will be called on notification from a signal + * @param p1 parameter value 1 + * @param p2 parameter value 2 + * @param p3 parameter value 3 + */ + void call(T1 p1, T2 p2,T3 p3); +} |