public static void UnsubscribeEvent(string name, MessageEventDelegate action) { if (dic.ContainsKey(name) && dic[name].Contains(action)) { dic[name].Remove(action); } }
protected void RaiseMessageEvent(string message) { /// To avoid a race condition where the last handler can be removed /// between the null check and the invocation of the event, event /// sources should also create a copy of the event before performing /// the null check and raising the event. MessageEventDelegate temp = MessageEvent; if (temp != null) { MessageEventArgs e = new MessageEventArgs(message); temp(this, e); } }
public static void SubscribeEvent(string name, MessageEventDelegate action) { if (!dic.ContainsKey(name)) { //throw new System.Exception("Event '" + name + "' hasn't been invoked previously"); dic.Add(name, new List <MessageEventDelegate>()); } if (!dic[name].Contains(action)) { dic[name].Add(action); } else { throw new System.Exception("Event '" + name + "' has already been subscribed to with the specified action."); } }
Subscriber <MessageEvent <M> > queue_subscribe <M> (string topic, uint queue_size, MessageEventDelegate <M> msgEvent, CallbackQueueInterface queue) where M : IRosMessage, new() // Subscriber<M, T> queue_subscribe (string topic, uint queue_size, void(T::*fp)(const ros::MessageEvent<M const>&), T* obj, ros::CallbackQueueInterface* queue) { SubscribeOptions <MessageEvent <M> > ops = new SubscribeOptions <MessageEvent <M> > (topic, queue_size, new CallbackDelegate <MessageEvent <M> > (msgEvent)); ops.callback_queue = queue; ops.topic = topic; ops.queue_size = queue_size; // md5 and datatype get generated in constructor // ops.md5sum = ros::message_traits::md5sum<M>(); // ops.datatype = ros::message_traits::datatype<M>(); ops.helper = new SubscriptionCallbackHelper <MessageEvent <M> > (Messages.MsgTypes.MessageEvent, new CallbackDelegate <MessageEvent <M> > (msgEvent)); // ops.helper = ros::SubscriptionCallbackHelperPtr( // new ros::SubscriptionCallbackHelperT<const ros::MessageEvent<M const>& >( // boost::bind(fp, obj, _1) // ) // ); return(nodeHandle.subscribe(ops)); }