X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2FUpdateMessageBroker.java;h=c03235905318b8ed4d4307f887365dae0e3b6b91;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=f2dfd2aaeb2ca1a072a37ac21d36a32874d1bbdd;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/UpdateMessageBroker.java b/tim/prune/UpdateMessageBroker.java index f2dfd2a..c032359 100644 --- a/tim/prune/UpdateMessageBroker.java +++ b/tim/prune/UpdateMessageBroker.java @@ -4,45 +4,75 @@ package tim.prune; * Class responsible for distributing update information * to all registered listeners */ -public class UpdateMessageBroker +public abstract class UpdateMessageBroker { - private DataSubscriber[] _subscribers; - private int _subscriberNum = 0; - private static final int MAXIMUM_NUMBER_SUBSCRIBERS = 4; - - - /** - * Constructor - * @param inTrack Track object - */ - public UpdateMessageBroker() - { - _subscribers = new DataSubscriber[MAXIMUM_NUMBER_SUBSCRIBERS]; - } + private static final int MAXIMUM_NUMBER_SUBSCRIBERS = 6; + /** Array of all subscribers */ + private static DataSubscriber[] _subscribers = new DataSubscriber[MAXIMUM_NUMBER_SUBSCRIBERS]; + /** Counter of the number of subscribers added so far */ + private static int _subscriberNum = 0; + /** Enable/disabled flag */ + private static boolean _enabled = true; /** * Add a data subscriber to the list * @param inSub DataSubscriber to add */ - public void addSubscriber(DataSubscriber inSub) + public static void addSubscriber(DataSubscriber inSub) { _subscribers[_subscriberNum] = inSub; _subscriberNum++; } + /** + * Enable or disable the messaging (to allow temporary disabling for multiple operations) + * @param inEnabled false to disable, true to enable again + */ + public static void enableMessaging(boolean inEnabled) + { + _enabled = inEnabled; + } /** * Send a message to all subscribers that * the data has been updated */ - public void informSubscribers() + public static void informSubscribers() + { + informSubscribers(DataSubscriber.ALL); + } + + + /** + * Send message to all subscribers + * @param inChange Change that occurred + */ + public static void informSubscribers(byte inChange) + { + // TODO: Launch separate thread so that whatever caused the inform can finish + if (!_enabled) return; + for (int i=0; i<_subscribers.length; i++) + { + if (_subscribers[i] != null) + { + _subscribers[i].dataUpdated(inChange); + } + } + } + + /** + * Send message to all subscribers + * @param inMessage message to display informing of action completed + */ + public static void informSubscribers(String inMessage) { + if (!_enabled) return; for (int i=0; i<_subscribers.length; i++) { if (_subscribers[i] != null) { - _subscribers[i].dataUpdated(); + _subscribers[i].actionCompleted(inMessage); } } }