LCM.LCM.LCM.Subscribe C# (CSharp) Method

Subscribe() public method

Subscribe to all channels whose name matches the regular expression. Note that to subscribe to all channels, you must specify ".*", not "*".
public Subscribe ( string regex, LCMSubscriber sub ) : void
regex string regular expression determining the channels to subscribe
sub LCMSubscriber subscribing object providing callback
return void
		public void Subscribe(string regex, LCMSubscriber sub)
		{
            if (this.closed)
            {
                throw new SystemException();
            }

			SubscriptionRecord srec = new SubscriptionRecord();
			srec.regex = regex;
			srec.pat = new Regex(regex);
			srec.lcsub = sub;
			
			lock (this)
			{
				foreach (Provider p in providers)
                {
				    p.Subscribe(regex);
                }
			}
			
			lock (subscriptions)
			{
                subscriptions.Add(srec);
                List<SubscriptionRecord> subs;
				
				foreach (string channel in subscriptionsMap.Keys)
				{
					if (srec.pat.IsMatch(channel))
                    {
                        if (subscriptionsMap.TryGetValue(channel, out subs))
                        {
                            subs.Add(srec);
                        }
					}
				}
			}
		}
		

Usage Example

示例#1
0
 private void subscribeForResponses()
 {
     _lcm.Subscribe(Channels.discovery_res_channel, new DiscoveryResponseHandler());
     _lcm.Subscribe(Channels.init_session_res_channel, new InitSessionResponseHandler());
     _lcm.Subscribe(Channels.end_session_res_channel, new EndSessionResponseHandler());
     _lcm.Subscribe(Channels.position_res_channel, new PositionResponseHandler());
     _lcm.Subscribe(Channels.stream_res_channel, new StreamUriResponseHandler());
     _lcm.Subscribe(Channels.start_program_res_channel, new StartProgramResponseHandler());
     _lcm.Subscribe(Channels.stop_program_res_channel, new StopProgramResponseHandler());
     _lcm.Subscribe(Channels.output_req_channel, new OutputRequestHandler());
     _lcm.Subscribe(Channels.program_status_mes_channel, new ProgramStatusUpdateHandler());
     _lcm.Subscribe(Channels.end_program_mes_channel, new EndProgramMessageReceivedHandler());
 }