/// <summary> /// Initializes communications with the outside world by means of remoting /// </summary> public void InitializeRemotingCommunications() { // try to shut down in case we have already been active this.ShutDown(); try { // Read the configuration file. RemotingConfiguration.Configure("Remora.exe.config", false); WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes(); // "Activate" the NameService singleton. objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri); // Retreive the directory of messaging channels IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory"); // Retreive the Messaging Service channels we want to listen to vehicleStateChannel = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast); observedObstacleChannel = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast); observedVehicleChannel = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast); arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast); carModeChannel = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast); fakeVehicleChannel = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast); // Create a channel listeners and listen on wanted channels channelListener = new MessagingListener(); vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener); observedObstacleChannel.Subscribe(channelListener); observedVehicleChannel.Subscribe(channelListener); arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener); carModeChannelToken = carModeChannel.Subscribe(channelListener); fakeVehicleChannelToken = fakeVehicleChannel.Subscribe(channelListener); // set that remoting has been successfully initialize this.RemotingInitialized = true; RemoraOutput.WriteLine("Successfully initialized communications"); } catch (Exception e) { RemoraOutput.WriteLine(e.ToString() + "\n\n" + "Could not initialize communications, attempting to reconnect"); try { WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes(); // "Activate" the NameService singleton. objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri); // Retreive the directory of messaging channels IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory"); // Retreive the Messaging Service channels we want to listen to vehicleStateChannel = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast); observedObstacleChannel = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast); observedVehicleChannel = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast); arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast); carModeChannel = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast); fakeVehicleChannel = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast); // Create a channel listeners and listen on wanted channels channelListener = new MessagingListener(); vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener); observedObstacleChannel.Subscribe(channelListener); observedVehicleChannel.Subscribe(channelListener); arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener); carModeChannelToken = carModeChannel.Subscribe(channelListener); fakeVehicleChannelToken = fakeVehicleChannel.Subscribe(channelListener); // set that remoting has been successfully initialize this.RemotingInitialized = true; RemoraOutput.WriteLine("Successfully initialized communications"); } catch (Exception e1) { RemoraOutput.WriteLine(e1.ToString() + "\n\n" + "Could not reinitialize nameservice communications"); try { // Retreive the directory of messaging channels IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory"); // Retreive the Messaging Service channels we want to listen to vehicleStateChannel = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast); observedObstacleChannel = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast); observedVehicleChannel = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast); arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast); carModeChannel = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast); fakeVehicleChannel = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast); // Create a channel listeners and listen on wanted channels channelListener = new MessagingListener(); vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener); observedObstacleChannel.Subscribe(channelListener); observedVehicleChannel.Subscribe(channelListener); arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener); carModeChannelToken = carModeChannel.Subscribe(channelListener); fakeVehicleChannelToken = fakeVehicleChannel.Subscribe(channelListener); // set that remoting has been successfully initialize this.RemotingInitialized = true; RemoraOutput.WriteLine("Successfully initialized communications"); } catch (Exception e2) { RemoraOutput.WriteLine(e2.ToString() + "\n\n" + "Could not reinitialize messaging communications"); } } } }