Skip to content

Commit

Permalink
DynamicReconfigure: recycle a singular DynamicReconfigurePage as targ…
Browse files Browse the repository at this point in the history
…et node changes, update debug output.
  • Loading branch information
nuclearmistake committed Mar 25, 2016
1 parent fcd722c commit 32266fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions DynamicReconfigure/DynamicReconfigure.cs
Expand Up @@ -192,7 +192,7 @@ public void SubscribeForUpdates()
}
catch (InvalidCastException ice)
{
Console.WriteLine(ice);
EDB.WriteLine(ice);
}
}

Expand Down Expand Up @@ -273,7 +273,7 @@ private void _set(Config config)
_cli = null;
}
if (!set(config, ref reason))
Console.WriteLine("SET FAILED\n" + reason);
EDB.WriteLine("SET FAILED\n" + reason);
}
}

Expand Down
28 changes: 11 additions & 17 deletions DynamicReconfigureSharp/DynamicReconfigurePage.xaml.cs
Expand Up @@ -40,7 +40,8 @@ public DynamicReconfigurePage(NodeHandle n, string name) : this()
nh = n;
Loaded += (sender, args) =>
{
Namespace = name;
if (name != null)
Namespace = name;
};
}

Expand Down Expand Up @@ -85,7 +86,7 @@ private void DescriptionRecieved(ConfigDescription cd)
}
catch (Exception e)
{
Console.WriteLine(e);
EDB.WriteLine(e);
}
}));

Expand All @@ -96,25 +97,16 @@ public string Namespace
{
if (Process.GetCurrentProcess().ProcessName == "devenv")
return;
Console.WriteLine("CHANGING DYNPARAM PAGE NAMESPACE FROM " + Namespace + " to " + value);
if ((Namespace == null && value == null) || (Namespace != null && Namespace.Equals(value)))
return;
string oldn = Namespace ?? "!NULL!";
string newn = value ?? "!NULL!";
EDB.WriteLine("CHANGING DYNPARAM PAGE NAMESPACE FROM " + oldn + " to " + newn);
SetValue(NamespaceProperty, value);
Init();
}
}

public void shutdown()
{
if (dynamic != null)
{
dynamic = null;
}
if (nh != null)
{
nh.shutdown();
nh = null;
}
}

private void Init()
{
lock (this)
Expand Down Expand Up @@ -153,14 +145,16 @@ private void SetupNamespace(string Namespace)
nh = new NodeHandle();
if (dynamic != null && dynamic.Namespace != Namespace)
{
dynamic.Dispose();
dynamic = null;
}
if (dynamic == null)
if (dynamic == null && Namespace != null)
{
dynamic = new DynamicReconfigureInterface(nh, Namespace);
dynamic.SubscribeForUpdates();
dynamic.DescribeParameters(DescriptionRecieved);
}
GroupHolder.Children.Clear();
}

public event Action<string, bool> BoolChanged;
Expand Down
70 changes: 38 additions & 32 deletions DynamicReconfigureSharp/MainWindow.xaml.cs
Expand Up @@ -20,9 +20,10 @@ namespace DynamicReconfigureTest
/// </summary>
public partial class MainWindow : Window
{
private SortedDictionary<string, DynamicReconfigurePage> knownConfigurations = new SortedDictionary<string, DynamicReconfigurePage>();
private SortedDictionary<string, object> knownConfigurations = new SortedDictionary<string, object>();
private NodeHandle nh;
private Thread topicPoller;
private DynamicReconfigurePage reconfigureview;

public MainWindow()
{
Expand All @@ -42,15 +43,14 @@ public MainWindow()
}
catch (Exception e)
{
Console.WriteLine(e);
EDB.WriteLine(e);
Close();
}

topicPoller = new Thread(() =>
{
while (ROS.ok && !ROS.shutting_down)
{
TopicInfo[] topics = new TopicInfo[0];
master.getTopics(ref topics);
string[] nodes = new string[0];
Expand All @@ -77,34 +77,43 @@ public MainWindow()
string pfx = prefix;
Dispatcher.Invoke(new Action(() =>
{
DynamicReconfigurePage drp = new DynamicReconfigurePage(nh, pfx);
if (drp != null)
{
knownConfigurations.Add(pfx, drp);
TargetBox.Items.Refresh();
}
knownConfigurations.Add(pfx, null);
}), new TimeSpan(0,0,0,1));
}
}
Dispatcher.Invoke(new Action(TargetBox.Items.Refresh));
foreach (string s in prevlist)
{
if (!s.Equals("-"))
{
string pfx = s;
Dispatcher.Invoke(new Action(() =>
{
if (TargetBox.SelectedItem != null && ((string) TargetBox.SelectedItem).Equals(pfx))
{
TargetBox.SelectedIndex = 0;
}
lock (this)
{
knownConfigurations.Remove(pfx);
TargetBox.Items.Refresh();
}
}), new TimeSpan(0, 0, 0, 1));
{
if (reconfigureview != null && s.Equals(reconfigureview.Namespace))
reconfigureview.Namespace = null;
if (TargetBox.SelectedItem != null && ((string) TargetBox.SelectedItem).Equals(pfx))
{
TargetBox.SelectedIndex = 0;
}
lock (this)
{
knownConfigurations.Remove(pfx);
}
}), new TimeSpan(0, 0, 0, 1));
}
}
Dispatcher.Invoke(new Action(TargetBox.Items.Refresh));
if (reconfigureview == null && nh != null)
{
Dispatcher.Invoke(new Action(() =>
{
string target = null;
if (TargetBox.SelectedItem != null && !String.Equals(TargetBox.SelectedItem.ToString(), "-"))
target = TargetBox.SelectedItem.ToString();
reconfigureview = new DynamicReconfigurePage(nh, target);
PageContainer.Children.Add(reconfigureview);
}));
}
Thread.Sleep(500);
}
});
Expand All @@ -124,19 +133,16 @@ public MainWindow()

private void TargetBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
lock (this)
IEnumerable<string> prevs = e.RemovedItems.OfType<string>();
IEnumerable<string> news = e.AddedItems.OfType<string>();
if (!prevs.Any())
return;
string newprefix = news.ElementAt(0);
if (newprefix != null)
{
IEnumerable<string> prevs = e.RemovedItems.OfType<string>();
IEnumerable<string> news = e.AddedItems.OfType<string>();
if (prevs.Count() != 1 || news.Count() != 1) return;
PageContainer.Children.Clear();
string newprefix = news.ElementAt(0);
if (newprefix != null)
{
DynamicReconfigurePage value;
if (knownConfigurations.TryGetValue(newprefix, out value) && !newprefix.Equals("-"))
PageContainer.Children.Add(value);
}
object value;
if (knownConfigurations.TryGetValue(newprefix, out value) && reconfigureview != null)
reconfigureview.Namespace = !newprefix.Equals("-") ? newprefix : null;
}
}

Expand Down

0 comments on commit 32266fc

Please sign in to comment.