public bool unadvertise(string topic, SubscriberCallbacks callbacks) { Publication pub = null; lock ( advertisedTopicsMutex ) { foreach (Publication p in advertisedTopics) { if (p.Name == topic && !p.Dropped) { pub = p; break; } } } if (pub == null) { return(false); } pub.removeCallbacks(callbacks); lock ( advertisedTopicsMutex ) { if (pub.NumCallbacks == 0) { unregisterPublisher(pub.Name); pub.drop(); advertisedTopics.Remove(pub); } } return(true); }
public void RemoveCallbacks(SubscriberCallbacks callbacks) { lock (gate) { callbacks.CallbackQueue.RemoveByOwner(callbacks); this.callbacks.Remove(callbacks); } }
/// <summary> /// Creates a ros publisher /// </summary> /// <param name="topic">Topic name to publish to</param> /// <param name="md5sum">md5sum for topic and type</param> /// <param name="datatype">Datatype to publish</param> /// <param name="nodeHandle">nodehandle</param> /// <param name="callbacks">Any callbacks to attach</param> public Publisher(string topic, string md5sum, string datatype, NodeHandle nodeHandle, SubscriberCallbacks callbacks) { this.topic = topic; this.md5sum = md5sum; this.datatype = datatype; this.nodeHandle = nodeHandle; this.callbacks = callbacks; }
public void RemoveCallbacks(SubscriberCallbacks callbacks) { lock (gate) { if (callbacks.CallbackId >= 0) { callbacks.CallbackQueue.RemoveById(callbacks.CallbackId); } if (this.callbacks.Contains(callbacks)) { this.callbacks.Remove(callbacks); } } }
public void AddCallbacks(SubscriberCallbacks callbacks) { lock (gate) { this.callbacks.Add(callbacks); if (callbacks.OnConnect != null && callbacks.CallbackQueue != null) { foreach (SubscriberLink i in subscriberLinks) { CallbackInterface cb = new PeerConnDisconnCallback(callbacks.OnConnect, i); callbacks.CallbackQueue.AddCallback(cb, callbacks); } } } }
public void addCallbacks(SubscriberCallbacks callbacks) { lock ( callbacks_mutex ) { this.callbacks.Add(callbacks); if (callbacks.connect != null && callbacks.CallbackQueue != null) { lock ( subscriber_links_mutex ) { foreach (SubscriberLink i in subscriber_links) { CallbackInterface cb = new PeerConnDisconnCallback(callbacks.connect, i); callbacks.CallbackId = cb.Uid; callbacks.CallbackQueue.AddCallback(cb); } } } } }
/// <summary> /// Creates a publisher with the given advertise options /// </summary> /// <typeparam name="M">Type of topic</typeparam> /// <param name="ops">Advertise options</param> /// <returns>A publisher with the specified options</returns> public Publisher <M> advertise <M>(AdvertiseOptions <M> ops) where M : RosMessage, new() { ops.topic = resolveName(ops.topic); if (ops.callbackQueue == null) { ops.callbackQueue = Callback; } var callbacks = new SubscriberCallbacks(ops.connectCB, ops.disconnectCB, ops.callbackQueue); if (TopicManager.Instance.advertise(ops, callbacks)) { var pub = new Publisher <M>(ops.topic, ops.md5Sum, ops.dataType, this, callbacks); lock ( gate ) { collection.Publishers.Add(pub); } return(pub); } ROS.Error()($"[{ThisNode.Name}] Advertisement of publisher has failed"); return(null); }
/// <summary> /// Creates a publisher with the given advertise options /// </summary> /// <typeparam name="M">Type of topic</typeparam> /// <param name="ops">Advertise options</param> /// <returns>A publisher with the specified options</returns> public async Task <Publisher <M> > AdvertiseAsync <M>(AdvertiseOptions <M> ops) where M : RosMessage, new() { ops.topic = ResolveName(ops.topic); if (ops.callbackQueue == null) { ops.callbackQueue = Callback; } var callbacks = new SubscriberCallbacks(ops.connectCB, ops.disconnectCB, ops.callbackQueue); if (await TopicManager.Instance.Advertise(ops, callbacks)) { var pub = new Publisher <M>(ops.topic, ops.md5Sum, ops.dataType, this, callbacks); lock (gate) { collection.Publishers.Add(pub); } return(pub); } logger.LogError("Advertisement of publisher has failed"); return(null); }
public async Task <bool> Unadvertise(string topic, SubscriberCallbacks callbacks) { Publication pub = null; lock (gate) { foreach (Publication p in advertisedTopics) { if (p.Name == topic && !p.Dropped) { pub = p; break; } } } if (pub == null) { return(false); } pub.RemoveCallbacks(callbacks); lock (gate) { if (pub.NumCallbacks > 0) { return(true); } pub.Dispose(); advertisedTopics.Remove(pub); } await UnregisterPublisher(pub.Name); return(true); }
/// <summary> /// Register as a publisher on a topic. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ops"></param> /// <param name="callbacks"></param> /// <returns></returns> public bool advertise <T>(AdvertiseOptions <T> ops, SubscriberCallbacks callbacks) where T : RosMessage, new() { if (!isValid(ops)) { return(false); } Publication pub = null; lock ( advertisedTopicsMutex ) { if (shuttingDown) { return(false); } pub = lookupPublicationWithoutLock(ops.topic); if (pub != null) { if (pub.Md5sum != ops.md5Sum) { ROS.Error()($"[{ThisNode.Name}] Tried to advertise on topic [{ops.topic}] with md5sum [{ops.md5Sum}] and datatype [{ops.dataType}], but the topic is already advertised as md5sum [{pub.Md5sum}] and datatype [{pub.DataType}]"); return(false); } } else { pub = new Publication(ops.topic, ops.dataType, ops.md5Sum, ops.messageDefinition, ops.queueSize, ops.latch, ops.hasHeader); } pub.addCallbacks(callbacks); advertisedTopics.Add(pub); } bool found = false; Subscription sub = null; lock ( subcriptionsMutex ) { foreach (Subscription s in subscriptions) { if (s.name == ops.topic && md5sumsMatch(s.md5sum, ops.md5Sum) && !s.IsDropped) { found = true; sub = s; break; } } } if (found) { sub.addLocalConnection(pub); } var args = new XmlRpcValue(ThisNode.Name, ops.topic, ops.dataType, XmlRpcManager.Instance.Uri); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); if (!Master.execute("registerPublisher", args, result, payload, true)) { ROS.Error()($"[{ThisNode.Name}] RPC \"registerService\" for service {ops.topic} failed."); return(false); } return(true); }
/// <summary> /// Register as a publisher on a topic. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="ops"></param> /// <param name="callbacks"></param> /// <returns></returns> public async Task <bool> Advertise <T>(AdvertiseOptions <T> ops, SubscriberCallbacks callbacks) where T : RosMessage, new() { if (!IsValid(ops)) { return(false); } Publication pub = null; lock (gate) { if (shuttingDown) { return(false); } pub = LookupPublicationWithoutLock(ops.topic); if (pub != null) { if (pub.Md5Sum != ops.md5Sum) { this.logger.LogError( "Tried to advertise on topic [{0}] with md5sum [{1}] and datatype [{2}], but the topic is already advertised as md5sum [{3}] and datatype [{4}]", ops.topic, ops.md5Sum, ops.dataType, pub.Md5Sum, pub.DataType ); return(false); } } else { pub = new Publication( ops.topic, ops.dataType, ops.md5Sum, ops.messageDefinition, ops.queueSize, ops.Latch, ops.hasHeader ); } pub.AddCallbacks(callbacks); advertisedTopics.Add(pub); } bool found = false; Subscription sub = null; lock (gate) { foreach (Subscription s in subscriptions) { if (s.Name == ops.topic && Md5SumsMatch(s.Md5Sum, ops.md5Sum) && !s.IsDisposed) { found = true; sub = s; break; } } } if (found) { sub.AddLocalConnection(pub); } var args = new XmlRpcValue(ThisNode.Name, ops.topic, ops.dataType, XmlRpcManager.Instance.Uri); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); if (!await Master.ExecuteAsync("registerPublisher", args, result, payload, true)) { this.logger.LogError($"RPC \"registerPublisher\" for topic '{ops.topic}' failed."); return(false); } return(true); }