From 735cb47b9c55991d30e7fa75bb4f477edb27411b Mon Sep 17 00:00:00 2001
From: Alexander Mueller <alexander.mueller@hs.uni-hamburg.de>
Date: Mon, 31 Oct 2005 16:20:32 +0000
Subject: [PATCH] BugID: 258 The most save solution for this problem is to
 perform the real unload action in the Navigator context (thus not in a
 seperate thread). For this purpose the so far unused message DPE of the
 GCFNavigatorInstance DPType will be used. The usage of the
 navPMLunloadPropertySet stays the same but this method "sends" a message to
 the message DPE of the current naviagtor instance. The callback than performs
 the real unload actions.

---
 .../nav_fw/gcfnav-configuration-functions.ctl | 550 +++++++++---------
 .../libs/nav_fw/gcfnav-pmlinterface.ctl       | 107 ++--
 .../libs/nav_fw/gcfnav-tab-functions.ctl      |  17 -
 .../scripts/libs/nav_fw/gcfpa-cwd.ctl         |  32 +-
 .../scripts/libs/nav_fw/gcfpa-pml.ctl         |  29 +-
 5 files changed, 357 insertions(+), 378 deletions(-)

diff --git a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-configuration-functions.ctl b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-configuration-functions.ctl
index f6c3e7f0ba9..e0050d4233a 100644
--- a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-configuration-functions.ctl
+++ b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-configuration-functions.ctl
@@ -48,6 +48,7 @@ global string   ELNAME_SUBVIEWS                 = "subViews";
 global string   ELNAME_CONFIGS                  = "configs";
 global string   ELNAME_TRIGGERUPDATE            = "triggerUpdate";
 global string   ELNAME_NEWDATAPOINT             = "newDatapoint";
+global string   ELNAME_MESSAGE		              = "message";
 global string   DPTYPENAME_NAVIGATOR_INSTANCE   = "GCFNavigatorInstance";
 global int      g_navigatorID = 0;
 
@@ -65,10 +66,10 @@ global int      g_navigatorID = 0;
 void navConfigInitPathNames()
 {
   dyn_string pathNames;
-  if(_WIN32)
+  if (_WIN32)
   {
     dpGet("__navigator.pathNamesWindows", pathNames);
-    if(""!=pathNames[g_path_temp_index])
+    if ("" != pathNames[g_path_temp_index])
       g_path_temp    = pathNames[g_path_temp_index];
     else
       g_path_temp    = "c:/temp";
@@ -79,7 +80,7 @@ void navConfigInitPathNames()
   else
   {
     dpGet("__navigator.pathNamesLinux", pathNames);
-    if(""!=pathNames[g_path_temp_index])
+    if ("" != pathNames[g_path_temp_index])
       g_path_temp    = pathNames[g_path_temp_index];
     else
       g_path_temp    = "/tmp";
@@ -101,7 +102,7 @@ void navConfigInitPathNames()
 string navConfigGetPathName(string pathName)
 {
   string output;
-  if(_WIN32) //windows
+  if (_WIN32) //windows
   {
     strreplace(pathName, "/", "\\");
     output = pathName;
@@ -116,7 +117,7 @@ string navConfigGetPathName(string pathName)
 string navConfigGetSlashes()
 {
   string output;
-  if(_WIN32) //windows
+  if (_WIN32) //windows
   {
     output = "\\";
   }
@@ -149,18 +150,18 @@ int navConfigGetNavigatorID()
 void navConfigSetNavigatorID(int newID)
 {
   bool createConfiguration = false;
-  if(newID > 256)
+  if (newID > 256)
   {
     g_navigatorID = newID;
-    if(!dpAccessable(DPNAME_NAVIGATOR + g_navigatorID))
+    if (!dpAccessable(DPNAME_NAVIGATOR + g_navigatorID))
     {
       createConfiguration = true;
     }
   }
   else
   {
-  	g_navigatorID = myManNum();
-    if(!dpAccessable(DPNAME_NAVIGATOR + g_navigatorID))
+    g_navigatorID = myManNum();
+    if (!dpAccessable(DPNAME_NAVIGATOR + g_navigatorID))
     {
       createConfiguration = true;
     }
@@ -182,7 +183,7 @@ void navConfigSetNavigatorID(int newID)
 void navConfigIncreaseUseCount()
 {
   // increase usecount
-  int usecount=0;
+  int usecount = 0;
   dpGet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_USECOUNT, usecount);
   usecount++;
   dpSet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_USECOUNT, usecount);
@@ -197,10 +198,10 @@ void navConfigIncreaseUseCount()
 void navConfigDecreaseUseCount()
 {
   // lower usecount of this navigator
-  int usecount=0;
+  int usecount = 0;
   dpGet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_USECOUNT, usecount);
   usecount--;
-  if(usecount > 0)
+  if (usecount > 0)
   {
     dpSet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_USECOUNT, usecount);
   }
@@ -221,29 +222,29 @@ void navConfigDecreaseUseCount()
 bool navConfigCheckEnabled(string datapointName)
 {
   bool enabled = false;
-  if(dpAccessable(datapointName + "__enabled"))
+  if (dpAccessable(datapointName + "__enabled"))
   {
     enabled = true;
-    LOG_TRACE("dpName__enabled Exists",datapointName, enabled);
+    LOG_TRACE("dpName__enabled Exists", datapointName, enabled);
   }
   else
   {
-    LOG_TRACE("dpName__enabled NOT Exists",datapointName, enabled);
+    LOG_TRACE("dpName__enabled NOT Exists", datapointName, enabled);
     // check the ignoreEnabledRoots field
     dyn_string ignoreEnabledDPs;
     dyn_errClass err;
-    dpGet(DPNAME_NAVIGATOR + "." + ELNAME_IGNOREENABLEDROOTS,ignoreEnabledDPs);
+    dpGet(DPNAME_NAVIGATOR + "." + ELNAME_IGNOREENABLEDROOTS, ignoreEnabledDPs);
     // If the datapointName is a reference, use the refernce to check for enabled
     err = getLastError();
-    if(dynlen(err) == 0)
+    if (dynlen(err) == 0)
     {
-      for(int i=1;i<=dynlen(ignoreEnabledDPs) && !enabled;i++)
+      for (int i = 1; i <= dynlen(ignoreEnabledDPs) && !enabled; i++)
       {
-        int pos = strpos(datapointName,ignoreEnabledDPs[i]);
-        LOG_TRACE("checkEnabled",pos,datapointName,ignoreEnabledDPs[i]);
-        if(pos >= 0)
+        int pos = strpos(datapointName, ignoreEnabledDPs[i]);
+        LOG_TRACE("checkEnabled", pos, datapointName, ignoreEnabledDPs[i]);
+        if (pos >= 0)
         {
-          enabled=true;
+          enabled = true;
         }
       }
     }
@@ -261,9 +262,9 @@ void navConfigSetSelectedElement(string datapointPath)
 {
   string dpSelectedElementContainer = DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDELEMENT;
   string dpSelectedElement = datapointPath;
-  if(dpAccessable(dpSelectedElementContainer))
+  if (dpAccessable(dpSelectedElementContainer))
   {
-    dpSet(dpSelectedElementContainer,dpSelectedElement);
+    dpSet(dpSelectedElementContainer, dpSelectedElement);
   }
 }
 
@@ -275,7 +276,7 @@ void navConfigSetSelectedElement(string datapointPath)
 string navConfigGetViewsPath()
 {
   string viewsPath = "nav_fw/";
-  dpGet(DPNAME_NAVIGATOR+ "." + ELNAME_VIEWSPATH,viewsPath);
+  dpGet(DPNAME_NAVIGATOR+ "." + ELNAME_VIEWSPATH, viewsPath);
   return viewsPath;
 }
 
@@ -300,12 +301,12 @@ void navConfigSetSelectedView(string datapoint, int viewid)
 {
   string dpViewConfig = navConfigGetViewConfig(datapoint);
   dyn_string views = navConfigGetViews(dpViewConfig);
-  if(viewid <= dynlen(views))
+  if (viewid <= dynlen(views))
   {
     string caption = navConfigGetViewCaption(views[viewid]);
     dpSet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDVIEWCAPTION, caption);
   }
-  dpSet(dpViewConfig + "." + ELNAME_SELECTEDVIEW,viewid);
+  dpSet(dpViewConfig + "." + ELNAME_SELECTEDVIEW, viewid);
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -359,14 +360,13 @@ string navConfigGetViewConfigPanel(string dpView)
 bool checkForReference(string &parentDatapoint, dyn_string &reference, bool &parentDatapointIsReference)
 {
   dyn_string refOut;
-  bool stopCheck=FALSE;
-  //parentDatapointIsReference=FALSE;
-  for(int i=1; (i<=dynlen(g_referenceList) && !stopCheck); i++)
+  bool stopCheck = FALSE;
+  for (int i = 1; (i <= dynlen(g_referenceList) && !stopCheck); i++)
   {
-    refOut = strsplit(g_referenceList[i],"=");
-    if(dynlen(refOut)>=1)
+    refOut = strsplit(g_referenceList[i], "=");
+    if (dynlen(refOut) >= 1)
     {
-      if (refOut[1] == parentDatapoint || patternMatch(refOut[1]+ "*",parentDatapoint))
+      if (strpos(parentDatapoint, refOut[1]) == 0)
       {
         stopCheck = TRUE;
         parentDatapointIsReference = TRUE;
@@ -388,7 +388,7 @@ bool checkForReference(string &parentDatapoint, dyn_string &reference, bool &par
 ///////////////////////////////////////////////////////////////////////////
 void checkForReferenceReplaceOriginal(dyn_string &resources, dyn_string reference)
 {
-  for(int i=1; i<=dynlen(resources); i++)
+  for (int i = 1; i <= dynlen(resources); i++)
   {
     strreplace(resources[i], reference[2], reference[1]);
   }
@@ -413,52 +413,51 @@ dyn_string navConfigGetResources(string parentDatapoint, int depth)
   int maxDepth;
   bool parentDatapointIsReference;
   checkForReference(parentDatapoint, reference, parentDatapointIsReference);
-  if(parentDatapoint == "")
+  if (parentDatapoint == "")
   {
     maxDepth = depth;
     // read the roots from the configuration
-    dpGet(DPNAME_NAVIGATOR+"." + ELNAME_RESOURCEROOTS,resourceRoots);
+    dpGet(DPNAME_NAVIGATOR + "." + ELNAME_RESOURCEROOTS, resourceRoots);
     err = getLastError();
-    if(dynlen(err)>0)
+    if (dynlen(err) > 0)
     {
       // if nothing specified, take the local PIC and PAC trees
-      resourceRoots = makeDynString("PIC","PAC");
+      resourceRoots = makeDynString("PIC", "PAC");
     }  
   }
   else
   {
-    dyn_string dpPathElements = strsplit(parentDatapoint,"_");
+    dyn_string dpPathElements = strsplit(parentDatapoint, "_");
     maxDepth = depth + dynlen(dpPathElements);
     resourceRoots = makeDynString(parentDatapoint);
   }
-  for(int i=1;i<=dynlen(resourceRoots);i++)
+  for (int i = 1; i <= dynlen(resourceRoots); i++)
   {
     // query the database for all resources under the given root
-    dynAppend(allResources,dpNames(resourceRoots[i]+"*"));
+    dynAppend(allResources, dpNames(resourceRoots[i] + "*"));
   }
   
-
   /////////////////////////////////////////////////////////////
-  LOG_DEBUG("All resources: ",dynlen(allResources));
+  LOG_DEBUG("All resources: ", dynlen(allResources));
   dyn_string newCollection;
   dyn_string checkCollection = allResources;
   dyn_string enabledCollection = dynPatternMatch("*__enabled", allResources);
   int enabledCollectionLength = dynlen(enabledCollection);
   int position;
-  for(int j=1; j<=enabledCollectionLength; j++)
+  for (int j = 1; j<= enabledCollectionLength; j++)
   {
     string enabledCollectionItem = enabledCollection[j];
     strreplace(enabledCollectionItem, "__enabled", "");
     position = dynContains(checkCollection, enabledCollectionItem);
-    if(position>0)
+    if (position > 0)
     {
-      LOG_DEBUG("Adding: ",checkCollection[position]);
+      LOG_DEBUG("Adding: ", checkCollection[position]);
       dynAppend(newCollection, checkCollection[position]);
       dynRemove(checkCollection, position);
     }
-    else if(0==position)
+    else if (0 == position)
     {
-      if(navPMLisTemporary(enabledCollectionItem + "__enabled"))
+      if (navPMLisTemporary(enabledCollectionItem + "__enabled"))
       {
         LOG_DEBUG("Adding temp: ", enabledCollectionItem);
         dynAppend(newCollection, enabledCollectionItem);
@@ -467,23 +466,23 @@ dyn_string navConfigGetResources(string parentDatapoint, int depth)
   }
   ///////////////////////////////////////////////////////////////
 
-  if(dynlen(checkCollection)>0)
+  if (dynlen(checkCollection) > 0)
   {
-    bool enabled=FALSE;
+    bool enabled = FALSE;
     dyn_string ignoreEnabledDPs;
     dyn_errClass err;
-    dpGet(DPNAME_NAVIGATOR + "." + ELNAME_IGNOREENABLEDROOTS,ignoreEnabledDPs);
+    dpGet(DPNAME_NAVIGATOR + "." + ELNAME_IGNOREENABLEDROOTS, ignoreEnabledDPs);
     
-    for(int j=1; j<=dynlen(checkCollection);j++)
+    for (int j = 1; j <= dynlen(checkCollection); j++)
     {
       // check the ignoreEnabledRoots field
       err = getLastError();
-      if(dynlen(err) == 0)
+      if (dynlen(err) == 0)
       {
-        for(int n=1;n<=dynlen(ignoreEnabledDPs) && !enabled;n++)
+        for (int n = 1; n <= dynlen(ignoreEnabledDPs) && !enabled; n++)
         {
-          int pos = strpos(checkCollection[j],ignoreEnabledDPs[n]);
-          if(pos >= 0)
+          int pos = strpos(checkCollection[j], ignoreEnabledDPs[n]);
+          if (pos >= 0)
           {
             dynAppend(newCollection, checkCollection[j]);
             enabled = TRUE;
@@ -494,43 +493,40 @@ dyn_string navConfigGetResources(string parentDatapoint, int depth)
   }
   ////////////////////////////////////////////////////////////////
   allResources = newCollection;
-  //DebugTN("###2. All resources: ",allResources);
   /////////////////////////////////////////////////////////////
   // now remove all DP's with double '_' (e.g. __enabled)
   // strip everything below the requested level
   // remove duplicates  
-  int i=1;
+  int i = 1;
   
-  while(i<=dynlen(allResources))
+  while(i <= dynlen(allResources))
   {
-    //if((strpos(allResources[i],"__") < 0) || navPMLisTemporary(allResources[i]))
-    if(strpos(allResources[i],"__") < 0)
+    if (strpos(allResources[i], "__") < 0)
     {
       strreplace(allResources[i], "__enabled", "");
-      dyn_string dpPathElements = strsplit(allResources[i],"_");
+      dyn_string dpPathElements = strsplit(allResources[i], "_");
       string addResource;
-      int d=1;
-      while(d<=maxDepth && d<=dynlen(dpPathElements))
+      int d = 1;
+      while(d <= maxDepth && d <= dynlen(dpPathElements))
       {
-        if(d>1)
+        if (d > 1)
           addResource += "_";
         addResource += dpPathElements[d];
         d++;
       }
-      if(!dynContains(resources,addResource))
+      if (!dynContains(resources, addResource))
       {
-        LOG_DEBUG("Adding: ",addResource);
-        dynAppend(resources,addResource);
+        LOG_DEBUG("Adding: ", addResource);
+        dynAppend(resources, addResource);
       }
     }
     i++;
   }
-  if(parentDatapointIsReference)
+  if (parentDatapointIsReference)
   {
     checkForReferenceReplaceOriginal(resources, reference);
   }
   return resources;
-  DebugTN("### Get all resources ready");
 }
 
 
@@ -554,7 +550,7 @@ string navConfigGetEnvironment(string environmentName, string userName)
   dyn_string environmentNames;
   dpGet(DPNAME_NAVIGATOR + "." + ELNAME_ENVIRONMENTNAMES, environmentNames);
   
-  if(environmentName=="") // work with the current selected environment
+  if (environmentName == "") // work with the current selected environment
   {
     string navInstanceEnvironmentName;
     dpGet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDENVIRONMENT, navInstanceEnvironmentName);
@@ -565,10 +561,10 @@ string navConfigGetEnvironment(string environmentName, string userName)
     environment = environmentName;
   }
     
-  if(environment=="Personal")
+  if (environment == "Personal")
   {
     environmentType = "U";
-    if(userName!="") // is userName is given, use it.
+    if (userName != "") // is userName is given, use it.
     {
       environmentNumber = getUserId(userName);
     }
@@ -580,9 +576,9 @@ string navConfigGetEnvironment(string environmentName, string userName)
   else
   {
     environmentType = "E" ;
-    environmentNumber = dynContains(environmentNames,environment);
+    environmentNumber = dynContains(environmentNames, environment);
   }
-  environmentOutput = environmentType + strexpand("\\fill{0}", 4-strlen(environmentNumber))+environmentNumber;
+  environmentOutput = environmentType + strexpand("\\fill{0}", 4-strlen(environmentNumber)) + environmentNumber;
   
   return environmentOutput;
 }
@@ -594,26 +590,26 @@ string navConfigGetEnvironment(string environmentName, string userName)
 ///////////////////////////////////////////////////////////////////////////
 void navConfigfillEnvironmentList(string dp1, dyn_string environmentNames)
 {
-  setValue("","deleteAllItems");
+  setValue("", "deleteAllItems");
   string selectedEnvironment;
-  int itemCount=0;
+  int itemCount = 0;
   dpGet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDENVIRONMENT, selectedEnvironment);
   
   
-  for(int i=1; i<= dynlen(environmentNames); i++)
+  for (int i = 1; i<= dynlen(environmentNames); i++)
   {
-    if(environmentNames[i]!="")
-      setValue("","appendItem",environmentNames[i]);
-    if(environmentNames[i]==selectedEnvironment)
+    if (environmentNames[i] != "")
+      setValue("", "appendItem", environmentNames[i]);
+    if (environmentNames[i] == selectedEnvironment)
     {
-      getValue("","itemCount", itemCount);
-      setValue("","selectedPos", itemCount);
+      getValue("", "itemCount", itemCount);
+      setValue("", "selectedPos", itemCount);
     }
     
   }
-  if(itemCount==0)
+  if (itemCount == 0)
   {
-    setValue("","selectedPos",1);
+    setValue("", "selectedPos", 1);
     dpSet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDENVIRONMENT, "Personal");
   }
 }
@@ -627,31 +623,31 @@ string navConfigGetViewConfig(string datapointPath)
 {
   string datapointType;
   string dpViewConfig = "";
-  string dpNameTemp=datapointPath;
+  string dpNameTemp = datapointPath;
   bool isReference;
   dyn_string reference;
   
   checkForReference(dpNameTemp, reference, isReference);
-  if(dpAccessable(dpNameTemp+"__enabled"))
+  if (dpAccessable(dpNameTemp + "__enabled"))
   {
-    datapointType = getDpTypeFromEnabled(dpNameTemp+"__enabled.");
+    datapointType = getDpTypeFromEnabled(dpNameTemp + "__enabled.");
     // find __nav_<datapointType>_viewconfig datapoint
-    dpViewConfig = "__nav"+navConfigGetEnvironment("","")+"_"+datapointType+"_viewconfig";
+    dpViewConfig = "__nav" + navConfigGetEnvironment("", "") + "_" + datapointType + "_viewconfig";
   }
-  else if(dpExists(dpNameTemp)) // Explicit use op dpExist!!!
+  else if (dpExists(dpNameTemp)) // Explicit use op dpExist!!!
   {
     datapointType = dpTypeName(datapointPath);
-    dpViewConfig = "__nav"+navConfigGetEnvironment("","")+"_"+datapointType+"_viewconfig";
+    dpViewConfig = "__nav" + navConfigGetEnvironment("", "") + "_" + datapointType + "_viewconfig";
   }
   else
   {
     // a system root node is selected
     // find __nav<environment>_<systemname>_viewconfig datapoint
-    dpViewConfig = "__nav"+navConfigGetEnvironment("","")+"_"+datapointPath+"_viewconfig";
+    dpViewConfig = "__nav" + navConfigGetEnvironment("", "") + "_" + datapointPath + "_viewconfig";
   }
-  if(!dpAccessable(dpViewConfig))
+  if (!dpAccessable(dpViewConfig))
   {
-    LOG_TRACE("navConfigGetViewConfig","DP does not exist, using default configuration",dpViewConfig);
+    LOG_TRACE("navConfigGetViewConfig", "DP does not exist, using default configuration", dpViewConfig);
     dpViewConfig = "__nav_default_viewconfig";
   }
   LOG_TRACE(dpViewConfig);
@@ -675,15 +671,15 @@ bool navConfigGetViewConfigElements(
   bool success = true;
   dyn_errClass err;
 
-  dpGet(dpViewConfig + "." + ELNAME_SELECTEDVIEW,selectedView,
-        dpViewConfig + "." + ELNAME_SELECTEDSUBVIEW,selectedSubView,
-        dpViewConfig + "." + ELNAME_VIEWS,views,
-        dpViewConfig + "." + ELNAME_NROFSUBVIEWS,nrOfSubViews,
-        dpViewConfig + "." + ELNAME_SUBVIEWS,subViews,
-        dpViewConfig + "." + ELNAME_CONFIGS,configs);
+  dpGet(dpViewConfig + "." + ELNAME_SELECTEDVIEW, selectedView,
+        dpViewConfig + "." + ELNAME_SELECTEDSUBVIEW, selectedSubView,
+        dpViewConfig + "." + ELNAME_VIEWS, views,
+        dpViewConfig + "." + ELNAME_NROFSUBVIEWS, nrOfSubViews,
+        dpViewConfig + "." + ELNAME_SUBVIEWS, subViews,
+        dpViewConfig + "." + ELNAME_CONFIGS, configs);
   
   err = getLastError(); //test whether no errors
-  if(dynlen(err) > 0)
+  if (dynlen(err) > 0)
   {
     throwError(err); // write errors to stderr
     success = false;
@@ -701,7 +697,7 @@ void navConfigSetSelectedSubView(
   int         selectedSubView)
 {
   string dpViewConfig = navConfigGetViewConfig(datapoint);
-  dpSet(dpViewConfig + "." + ELNAME_SELECTEDSUBVIEW,selectedSubView);
+  dpSet(dpViewConfig + "." + ELNAME_SELECTEDSUBVIEW, selectedSubView);
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -717,11 +713,11 @@ bool navConfigGetSubViewConfigElements(
   bool success = true;
   dyn_errClass err;
 
-  dpGet(dpSubViewConfig + "." + ELNAME_CAPTION,subViewCaption,
-        dpSubViewConfig + "." + ELNAME_FILENAME,subViewFileName);
+  dpGet(dpSubViewConfig + "." + ELNAME_CAPTION, subViewCaption,
+        dpSubViewConfig + "." + ELNAME_FILENAME, subViewFileName);
   
   err = getLastError(); //test whether no errors
-  if(dynlen(err) > 0)
+  if (dynlen(err) > 0)
   {
     throwError(err); // write errors to stderr
     success = false;
@@ -740,7 +736,7 @@ bool navConfigSanityCheck(string &message)
   bool sane = true;
   dyn_dyn_anytype tab;
   int i;
-  dpQuery("SELECT '_original.._value' FROM '__nav_*' WHERE _DPT=\"GCFNavViewConfiguration\" ",tab);
+  dpQuery("SELECT '_original.._value' FROM '__nav_*' WHERE _DPT=\"GCFNavViewConfiguration\" ", tab);
   
   int viewsIndex    = 4;
   
@@ -753,63 +749,63 @@ bool navConfigSanityCheck(string &message)
     // check number of items in subviews, configs and nrOfSubViews
     int nrOfViews = dynlen(tab[viewsIndex][2]);
     sane = (nrOfViews == dynlen(tab[nrOfSubviewsIndex][2]));
-    //DebugTN("check nrOfViews:",sane,nrOfViews,dynlen(tab[nrOfSubviewsIndex][2]));
-    if(!sane)
+    //DebugTN("check nrOfViews:", sane, nrOfViews, dynlen(tab[nrOfSubviewsIndex][2]));
+    if (!sane)
     {
       message = "Invalid view configuration\n#views and nrOfSubViews do not correspond\n(" + tab[viewsIndex][1] + ")";
       DebugTN(message);
     }
     
-    if(sane)
+    if (sane)
     {
       int nrOfSubViews = 0;
-      for(i=1;i<=dynlen(tab[nrOfSubviewsIndex][2]);i++)
+      for (i = 1; i <= dynlen(tab[nrOfSubviewsIndex][2]); i++)
         nrOfSubViews += tab[nrOfSubviewsIndex][2][i];
       sane = (nrOfSubViews == dynlen(tab[subViewsIndex][2]) && nrOfSubViews == dynlen(tab[configsIndex][2]));
-      //DebugTN("check nrOfSubViews:",sane,nrOfSubViews,dynlen(tab[subViewsIndex][2]),dynlen(tab[configsIndex][2]));
-      if(!sane)
+      //DebugTN("check nrOfSubViews:", sane, nrOfSubViews, dynlen(tab[subViewsIndex][2]), dynlen(tab[configsIndex][2]));
+      if (!sane)
       {
         message = "Invalid view configuration\n#subviews, #configs and total nrOfSubViews do not correspond\n(" + tab[viewsIndex][1] + ")";
         DebugTN(message);
       }
     }
     
-    if(sane)
+    if (sane)
     {
-      for(i=1;i<=dynlen(tab[viewsIndex][2]) && sane;i++)
+      for (i = 1; i <= dynlen(tab[viewsIndex][2]) && sane; i++)
       {
         sane = dpAccessable(tab[viewsIndex][2][i]);
-        LOG_TRACE("check view existance:",sane,tab[viewsIndex][2][i]);
+        LOG_TRACE("check view existance:", sane, tab[viewsIndex][2][i]);
       }
-      if(!sane)
+      if (!sane)
       {
         message = "Invalid view configuration\nview item (" + (i-1) + ") does not exist\n(" + tab[viewsIndex][1] + ")";
         DebugTN(message);
       }
     }
     
-    if(sane)
+    if (sane)
     {
-      for(i=1;i<=dynlen(tab[subViewsIndex][2]) && sane;i++)
+      for (i = 1; i <= dynlen(tab[subViewsIndex][2]) && sane; i++)
       {
         sane = dpAccessable(tab[subViewsIndex][2][i]);
-        DebugTN("check subview existance:",sane,tab[subViewsIndex][2][i]);
+        DebugTN("check subview existance:", sane, tab[subViewsIndex][2][i]);
       }
-      if(!sane)
+      if (!sane)
       {
         message = "Invalid view configuration\nsubview item (" + (i-1) + ") does not exist\n(" + tab[viewsIndex][1] + ")";
         DebugTN(message);
       }
     }
     
-    if(sane)
+    if (sane)
     {
-      for(i=1;i<=dynlen(tab[configsIndex][2]) && sane;i++)
+      for (i = 1; i <= dynlen(tab[configsIndex][2]) && sane; i++)
       {
         sane = dpAccessable(tab[configsIndex][2][i]);
-        DebugTN("check configs existance:",sane,tab[configsIndex][2][i]);
+        DebugTN("check configs existance:", sane, tab[configsIndex][2][i]);
       }
-      if(!sane)
+      if (!sane)
       {
         message = "Invalid view configuration\nconfig item (" + (i-1) + ") does not exist\n(" + tab[viewsIndex][1] + ")";
         DebugTN(message);
@@ -825,11 +821,11 @@ bool navConfigSanityCheck(string &message)
 ///////////////////////////////////////////////////////////////////////////
 //Function navConfigSubscribeUpdateTrigger
 // 
-// subscribes to the update trigger datapoint
+// subscribes to the update trigger datapointelement of the current naviagtor instance
 ///////////////////////////////////////////////////////////////////////////
 void navConfigSubscribeUpdateTrigger(string callback)
 {
-  dpConnect(callback,false,DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_TRIGGERUPDATE);
+  dpConnect(callback, false, DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_TRIGGERUPDATE);
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -869,11 +865,11 @@ void navConfigTriggerNavigatorRefreshWithDP(string newDatapoint)
 ///////////////////////////////////////////////////////////////////////////
 dyn_string environmentsAvailableToUser()
 {
-  dyn_string environmentGroups, environmentNames,currentUserGroupNames;
+  dyn_string environmentGroups, environmentNames, currentUserGroupNames;
   dyn_string Users_UserName, Users_GroupIds, Groups_UserName, Groups_UserId;
   dyn_string environmentListAvailableToUser;
   string currentGroupIds, currentUser = getUserName();
-  environmentListAvailableToUser[1]="Personal";
+  environmentListAvailableToUser[1] = "Personal";
   dpGet("_Users.UserName",  Users_UserName);
   dpGet("_Users.GroupIds",  Users_GroupIds);
   dpGet("_Groups.UserName", Groups_UserName);
@@ -881,7 +877,7 @@ dyn_string environmentsAvailableToUser()
   
   currentGroupIds = Users_GroupIds[dynContains(Users_UserName, currentUser)];
   dyn_string GroupIdsSplit= strsplit(currentGroupIds, ";");
-  for(int i=1;i<=dynlen(GroupIdsSplit);i++)
+  for (int i = 1; i <= dynlen(GroupIdsSplit); i++)
   {
    currentUserGroupNames[i] = Groups_UserName[dynContains(Groups_UserId, GroupIdsSplit[i])];
   }
@@ -889,19 +885,19 @@ dyn_string environmentsAvailableToUser()
   dpGet(DPNAME_NAVIGATOR + ".environmentGroups", environmentGroups);
   dpGet(DPNAME_NAVIGATOR + ".environmentNames", environmentNames);
  
-  for(int i=1;i<=dynlen(environmentGroups);i++) //UG assignment to Environment
+  for (int i = 1; i <= dynlen(environmentGroups); i++) //UG assignment to Environment
   {
     dyn_string environmentGroupSplit= strsplit(environmentGroups[i], "|"); //which UG do we have
-    for(int j=1;j<=dynlen(environmentGroupSplit);j++) // UG group root,para,quest for env. X
+    for (int j = 1; j <= dynlen(environmentGroupSplit); j++) // UG group root,para,quest for env. X
     {
-      for(int k=1;k<=dynlen(currentUserGroupNames);k++) //user membership in UG guest etc.
+      for (int k = 1; k <= dynlen(currentUserGroupNames); k++) //user membership in UG guest etc.
       {
         dyn_string currentUserGroupNamesSplit= strsplit(currentUserGroupNames[k], "|"); 
-        for(int m=1;m<=dynlen(currentUserGroupNamesSplit);m++)
+        for (int m = 1; m <= dynlen(currentUserGroupNamesSplit); m++)
         {
-          if(currentUserGroupNamesSplit[m]==environmentGroupSplit[j])
+          if (currentUserGroupNamesSplit[m] == environmentGroupSplit[j])
           {
-            environmentListAvailableToUser[dynlen(environmentListAvailableToUser)+1] = environmentNames[i];
+            environmentListAvailableToUser[dynlen(environmentListAvailableToUser) + 1] = environmentNames[i];
           }
         }
       }
@@ -924,9 +920,9 @@ bool navConfigConfigSubviewPermitted()
   string selectedEnvironment;
   dpGet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_SELECTEDENVIRONMENT, selectedEnvironment);
   
-  if(dpAccessable($configDatapoint) &&
-     dpGetElementName($datapoint)=="" && 
-     ((selectedEnvironment=="Personal") || (selectedEnvironment!="Personal" && getUserPermission(UR_CONFIGSYSTEMSUBVIEW))))
+  if (dpAccessable($configDatapoint) &&
+     dpGetElementName($datapoint) == "" && 
+     ((selectedEnvironment == "Personal") || (selectedEnvironment != "Personal" && getUserPermission(UR_CONFIGSYSTEMSUBVIEW))))
   {
     return TRUE;
   }
@@ -949,12 +945,12 @@ dyn_string navConfigGetElementsFromDp(string datapoint)
   dyn_string output;
   int elementIndex;
 
-  dpTypeGet(getDpTypeFromEnabled(datapoint + "__enabled."),elementNames,elementTypes);
-  for(elementIndex=2;elementIndex<=dynlen(elementNames);elementIndex++) 
+  dpTypeGet(getDpTypeFromEnabled(datapoint + "__enabled."), elementNames, elementTypes);
+  for (elementIndex = 2; elementIndex <= dynlen(elementNames); elementIndex++) 
   {
     int elementLevel = dynlen(elementNames[elementIndex])-1; // how deep is the element?
-    string elementName = elementNames[elementIndex][elementLevel+1];
-    output[dynlen(output)+1] = elementName;
+    string elementName = elementNames[elementIndex][elementLevel + 1];
+    output[dynlen(output) + 1] = elementName;
   }
   dynSortAsc(output);
   return output;
@@ -978,16 +974,16 @@ void arrangeUserGroupMembership()
   string GroupsForEnvironment = environmentGroups[dynContains(environmentNames, ComboBox_environmentMembership.selectedText)];
   dyn_string GroupsForEnvironmentsplit = strsplit(GroupsForEnvironment, "|");
   
-  for(int i=1; i<=dynlen(GroupsForEnvironmentsplit);i++)
+  for (int i = 1; i <= dynlen(GroupsForEnvironmentsplit); i++)
   {
     int position = dynContains(UserGroups, GroupsForEnvironmentsplit[i]);
-    if(position>0)
+    if (position>0)
     {
       UG_selected.appendItem = GroupsForEnvironmentsplit[i];
       dynRemove(UserGroups, position);
     }
   }
-  UG_available.items=UserGroups;
+  UG_available.items = UserGroups;
 }
 
 navConfigAddRemoveSubView()
@@ -999,15 +995,15 @@ navConfigAddRemoveSubView()
   dfReturn[2] = 0; // new nr of subviews
   string viewsPath = navConfigGetViewsPath();
   string subViewName;
-  if(comboCaption.visible == true) // adding existing subview
+  if (comboCaption.visible == true) // adding existing subview
     subViewName = comboCaption.selectedText;
   else
     subViewName = textFieldCaption.text;
   
   string cleanedText;  
-  for(int i=0;i<strlen(subViewName);i++)
+  for (int i = 0; i<strlen(subViewName); i++)
   {
-    if(! ( (subViewName[i] >= 'a' && subViewName[i] <= 'z') || 
+    if (! ( (subViewName[i] >= 'a' && subViewName[i] <= 'z') || 
            (subViewName[i] >= 'A' && subViewName[i] <= 'Z') || 
            (subViewName[i] >= '0' && subViewName[i] <= '9') ) )
     {
@@ -1020,121 +1016,121 @@ navConfigAddRemoveSubView()
   }
   subViewName = $viewName + "_" + cleanedText;
 
-  string subViewDpName = "__nav"+navConfigGetEnvironment("","")+"_subview_" + subViewName;
+  string subViewDpName = "__nav" + navConfigGetEnvironment("", "") + "_subview_" + subViewName;
   string configDpTypeName = "GCFNavSubViewConfig" + $viewName;
-  string configDpName     = "__nav"+navConfigGetEnvironment("","")+"_" + $selectedElementDpType + "_config_" + subViewName;
-  string viewConfigDpName = "__nav"+navConfigGetEnvironment("","")+"_" + $selectedElementDpType + "_viewconfig";
-  if($addView)
+  string configDpName     = "__nav" + navConfigGetEnvironment("", "") + "_" + $selectedElementDpType + "_config_" + subViewName;
+  string viewConfigDpName = "__nav" + navConfigGetEnvironment("", "") + "_" + $selectedElementDpType + "_viewconfig";
+  if ($addView)
   {
-	  //########################################################
-	  if(!dpAccessable(subViewDpName)&& !dpAccessable(configDpName))
-	  {
-	    if(comboCaption.visible == false) // adding new subview
-	    {
-	      // create new GCFNavSubView instance
-	      dpCreate(subViewDpName,"GCFNavSubView"); //__nav_subview_Alert_Red-Alert-125
-	      err = getLastError();
-	      if(dynlen(err) > 0)
-	      {
-	        errorDialog(err);
-	        // open dialog box with errors
-	        throwError(err); // write errors to stderr
-	      }
-	      else
-	      {
-	        dpSet(subViewDpName+".caption",textFieldCaption.text,
-	              subViewDpName+".filename", viewsPath + textFieldFileName.text);
-	      }
-	    }      
-	    err = getLastError();
-	    if(dynlen(err) > 0)
-	    {
-	      errorDialog(err);
-	      // open dialog box with errors
-	      throwError(err); // write errors to stderr
-	    }
-	    else
-	    {
-	      // create new config datapoint
-	      LOG_DEBUG("creating DP:",configDpName,configDpTypeName);
-	      dpCreate(configDpName,configDpTypeName); //__nav_TLcuPic_config_Alert_Red-Alert-125
-	      err = getLastError();
-	      if(dynlen(err) > 0)
-	      {
-	        errorDialog(err);
-	        // open dialog box with errors
-	        throwError(err); // write errors to stderr
-	      }
-	      else
-	      {
-	        dyn_int nrOfSubViews;
-	        dyn_string subViews,configs;
-	        if(!dpAccessable(viewConfigDpName))
-	        {
-	          // create a new datapoint, based on the default config
-	          int err;
-	          dpCopy("__nav_default_viewconfig",viewConfigDpName,err);
-	  
-	          // copy the contents of the default config
-	          int i;
-	          dyn_string allC;
-	          dyn_anytype para;
-	          allC = dpNames("__nav_default_viewconfig"+".**:_original.._value", "GCFNavViewConfiguration");
-	          dpGet(allC, para);
-	          for (i=1; i<=dynlen(allC); i++)
-	          {
-	            strreplace(allC[i], "__nav_default_viewconfig", viewConfigDpName);
-	          }
-	          dpSet(allC, para);
-	        }
-	        dpGet(viewConfigDpName + ".nrOfSubViews",nrOfSubViews,
-	              viewConfigDpName + ".subViews",subViews,
-	              viewConfigDpName + ".configs",configs);
-	
-	        err = getLastError();
-	        if(dynlen(err) > 0)
-	        {
-	          errorDialog(err);
-	          // open dialog box with errors
-	          throwError(err); // write errors to stderr
-	        }
-	        else
-	        {
-	          int insertIndex = 1;
-	          for(int i=1;i<=$selectedView;i++)
-	            insertIndex += nrOfSubViews[i];
-	          dfReturn[2] = nrOfSubViews[$selectedView];
-	          nrOfSubViews[$selectedView] = nrOfSubViews[$selectedView]+1;
-	          dynInsertAt(subViews,subViewDpName,insertIndex);
-	          dynInsertAt(configs,configDpName,insertIndex);
-	          dpSet(viewConfigDpName + ".nrOfSubViews",nrOfSubViews,
-	                viewConfigDpName + ".subViews",subViews,
-	                viewConfigDpName + ".configs",configs);
-	
-	          err = getLastError();
-	          if(dynlen(err) > 0)
-	          {
-	            errorDialog(err);
-	            // open dialog box with errors
-	            throwError(err); // write errors to stderr
-	          }
-	          else
-	          {
-	            dfReturn[1] = 1; // 0 = failure, 1 = success
-	            dfReturn[2] = nrOfSubViews[$selectedView];
-	          }
-	        }
-	      }
-	    }
-	  }
-	  else
-	  {
-	    //If the current subview name already exists, show message on screen
-	    string message = "Entered caption already exists. \nPlease enter a new one.";
-	    ChildPanelOnCentralModal(viewsPath + "MessageWarning.pnl", "Warning", makeDynString("$1:"+message));
-	    return;
-	  }
-	  //########################################################
+    //########################################################
+    if (!dpAccessable(subViewDpName)&& !dpAccessable(configDpName))
+    {
+      if (comboCaption.visible == false) // adding new subview
+      {
+        // create new GCFNavSubView instance
+        dpCreate(subViewDpName, "GCFNavSubView"); //__nav_subview_Alert_Red-Alert-125
+        err = getLastError();
+        if (dynlen(err) > 0)
+        {
+          errorDialog(err);
+          // open dialog box with errors
+          throwError(err); // write errors to stderr
+        }
+        else
+        {
+          dpSet(subViewDpName + ".caption", textFieldCaption.text,
+                subViewDpName + ".filename", viewsPath + textFieldFileName.text);
+        }
+      }      
+      err = getLastError();
+      if (dynlen(err) > 0)
+      {
+        errorDialog(err);
+        // open dialog box with errors
+        throwError(err); // write errors to stderr
+      }
+      else
+      {
+        // create new config datapoint
+        LOG_DEBUG("creating DP:", configDpName, configDpTypeName);
+        dpCreate(configDpName, configDpTypeName); //__nav_TLcuPic_config_Alert_Red-Alert-125
+        err = getLastError();
+        if (dynlen(err) > 0)
+        {
+          errorDialog(err);
+          // open dialog box with errors
+          throwError(err); // write errors to stderr
+        }
+        else
+        {
+          dyn_int nrOfSubViews;
+          dyn_string subViews, configs;
+          if (!dpAccessable(viewConfigDpName))
+          {
+            // create a new datapoint, based on the default config
+            int err;
+            dpCopy("__nav_default_viewconfig", viewConfigDpName, err);
+    
+            // copy the contents of the default config
+            int i;
+            dyn_string allC;
+            dyn_anytype para;
+            allC = dpNames("__nav_default_viewconfig" + ".**:_original.._value", "GCFNavViewConfiguration");
+            dpGet(allC, para);
+            for (i = 1; i <= dynlen(allC); i++)
+            {
+              strreplace(allC[i], "__nav_default_viewconfig", viewConfigDpName);
+            }
+            dpSet(allC, para);
+          }
+          dpGet(viewConfigDpName + ".nrOfSubViews", nrOfSubViews,
+                viewConfigDpName + ".subViews", subViews,
+                viewConfigDpName + ".configs", configs);
+  
+          err = getLastError();
+          if (dynlen(err) > 0)
+          {
+            errorDialog(err);
+            // open dialog box with errors
+            throwError(err); // write errors to stderr
+          }
+          else
+          {
+            int insertIndex = 1;
+            for (int i = 1; i <= $selectedView; i++)
+              insertIndex += nrOfSubViews[i];
+            dfReturn[2] = nrOfSubViews[$selectedView];
+            nrOfSubViews[$selectedView] = nrOfSubViews[$selectedView] + 1;
+            dynInsertAt(subViews, subViewDpName, insertIndex);
+            dynInsertAt(configs, configDpName, insertIndex);
+            dpSet(viewConfigDpName + ".nrOfSubViews", nrOfSubViews,
+                  viewConfigDpName + ".subViews", subViews,
+                  viewConfigDpName + ".configs", configs);
+  
+            err = getLastError();
+            if (dynlen(err) > 0)
+            {
+              errorDialog(err);
+              // open dialog box with errors
+              throwError(err); // write errors to stderr
+            }
+            else
+            {
+              dfReturn[1] = 1; // 0 = failure, 1 = success
+              dfReturn[2] = nrOfSubViews[$selectedView];
+            }
+          }
+        }
+      }
+    }
+    else
+    {
+      //If the current subview name already exists, show message on screen
+      string message = "Entered caption already exists. \nPlease enter a new one.";
+      ChildPanelOnCentralModal(viewsPath + "MessageWarning.pnl", "Warning", makeDynString("$1:" + message));
+      return;
+    }
+    //########################################################
   }
   else
   {
@@ -1142,15 +1138,15 @@ navConfigAddRemoveSubView()
 
     int selectedSubView;
     dyn_int nrOfSubViews;
-    dyn_string subViews,configs;
-    if(dpAccessable(viewConfigDpName))
+    dyn_string subViews, configs;
+    if (dpAccessable(viewConfigDpName))
     {
-      dpGet(viewConfigDpName + ".selectedSubView",selectedSubView,
-            viewConfigDpName + ".nrOfSubViews",nrOfSubViews,
-            viewConfigDpName + ".subViews",subViews,
-            viewConfigDpName + ".configs",configs);
+      dpGet(viewConfigDpName + ".selectedSubView", selectedSubView,
+            viewConfigDpName + ".nrOfSubViews", nrOfSubViews,
+            viewConfigDpName + ".subViews", subViews,
+            viewConfigDpName + ".configs", configs);
       err = getLastError();
-      if(dynlen(err) > 0)
+      if (dynlen(err) > 0)
       {
         errorDialog(err);
         // open dialog box with errors
@@ -1159,21 +1155,21 @@ navConfigAddRemoveSubView()
       else
       {
         int removeIndex = 0;
-        for(int i=1;i<$selectedView;i++)
+        for (int i = 1; i<$selectedView; i++)
           removeIndex += nrOfSubViews[i];
         removeIndex += selectedSubView;
 
         dfReturn[2] = nrOfSubViews[$selectedView];
         nrOfSubViews[$selectedView] = nrOfSubViews[$selectedView]-1;
-        dynRemove(subViews,removeIndex);
-        dynRemove(configs,removeIndex);
+        dynRemove(subViews, removeIndex);
+        dynRemove(configs, removeIndex);
 
-        dpSet(viewConfigDpName + ".nrOfSubViews",nrOfSubViews,
-              viewConfigDpName + ".subViews",subViews,
-              viewConfigDpName + ".configs",configs);
+        dpSet(viewConfigDpName + ".nrOfSubViews", nrOfSubViews,
+              viewConfigDpName + ".subViews", subViews,
+              viewConfigDpName + ".configs", configs);
 
         err = getLastError();
-        if(dynlen(err) > 0)
+        if (dynlen(err) > 0)
         {
           errorDialog(err);
           // open dialog box with errors
@@ -1192,8 +1188,8 @@ navConfigAddRemoveSubView()
   }
 
   // write return parameters to the database
-  dpSet("_Ui_" + myManNum() + ".ReturnValue.Float:_original.._value",dfReturn);
-  dpSet("_Ui_" + myManNum() + ".ReturnValue.Text:_original.._value",dsReturn);
+  dpSet("_Ui_" + myManNum() + ".ReturnValue.Float:_original.._value", dfReturn);
+  dpSet("_Ui_" + myManNum() + ".ReturnValue.Text:_original.._value", dsReturn);
 
   PanelOff();
 }
diff --git a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-pmlinterface.ctl b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-pmlinterface.ctl
index 490f0354da7..f87dcfa5465 100644
--- a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-pmlinterface.ctl
+++ b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-pmlinterface.ctl
@@ -44,32 +44,47 @@ global string    NAVPML_ENABLED_AUTOLOAD =  "autoloaded";
 void navPMLinitialize()
 {
   LOG_TRACE("navPMLinitialize");
-  if(g_PAclientId == 0) 
-  	g_PAclientId = gcfInit("pmlCallback");
+  if (g_PAclientId == 0) 
+    g_PAclientId = gcfInit("pmlCallback");
   else
     LOG_WARN("PML already initialized");
   
-  if(g_PAclientId == 0) 
+  if (g_PAclientId == 0) 
   {
     LOG_FATAL("PML not properly initialized");
   }
   else
   {
-    LOG_INFO("PML initialized. Using ID:",g_PAclientId);
+    dpConnect("HandlePanelMessage", false, DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_MESSAGE);
+    LOG_INFO("PML initialized. Using ID:", g_PAclientId);
   }
 }  
 
+void HandlePanelMessage(string dp, string msg)
+{
+  dyn_string splittedMsg = strsplit(msg, "|");  
+  if ((dynlen(splittedMsg) == 2) && (splittedMsg[1] == "PML_UNLOAD"))
+  {
+    string datapoint = splittedMsg[2];
+    if (!navPMLisAutoLoaded(datapoint))
+    {
+      LOG_TRACE("PML unload propertyset", g_PAclientId, datapoint);
+      gcfUnloadPS(g_PAclientId, datapoint);
+    }
+  }
+}
+
 ///////////////////////////////////////////////////////////////////////////
 //Function navPMLterminate
 //
 // closes the connection with the PML
 ///////////////////////////////////////////////////////////////////////////
-void navPMLterminate()
+void navPMLterminate(bool inTerminate = false)
 {
   LOG_TRACE("navPMLterminate");
-  if(g_PAclientId != 0)
+  if (g_PAclientId != 0)
   {
-  	gcfLeave(g_PAclientId);
+    gcfLeave(g_PAclientId, inTerminate);
     g_PAclientId = 0;
   }
 }  
@@ -81,10 +96,10 @@ void navPMLterminate()
 ///////////////////////////////////////////////////////////////////////////
 void navPMLloadPropertySet(string datapoint)
 {
-  LOG_TRACE("navPMLloadPropertySet",datapoint);
-  if(!navPMLisAutoLoaded(datapoint))
+  LOG_TRACE("navPMLloadPropertySet", datapoint);
+  if (!navPMLisAutoLoaded(datapoint))
   {
-    gcfLoadPS(g_PAclientId,datapoint);
+    gcfLoadPS(g_PAclientId, datapoint);
   }
 }
 
@@ -95,17 +110,16 @@ void navPMLloadPropertySet(string datapoint)
 ///////////////////////////////////////////////////////////////////////////
 bool navPMLunloadPropertySet(string datapoint)
 {
-  LOG_TRACE("navPMLunloadPropertySet",datapoint);
-  if(dpExists(datapoint))
+  LOG_TRACE("navPMLunloadPropertySet", datapoint);
+  if (dpExists(datapoint))
   {
-    if(!navPMLisAutoLoaded(datapoint))
-    {
-      gcfUnloadPS(g_PAclientId,datapoint);
-    }
+  	// in this way the context can be switched from the terminated panel to a still running 
+  	// panel (the navigator)
+    dpSet(DPNAME_NAVIGATOR + g_navigatorID + "." + ELNAME_MESSAGE, "PML_UNLOAD|" + datapoint);
   }
   else
   {
-    LOG_TRACE("navPMLunloadPropertySet -- Datapoint does not exist",datapoint);
+    LOG_TRACE("navPMLunloadPropertySet -- Datapoint does not exist", datapoint);
   }
 }
 
@@ -116,49 +130,49 @@ bool navPMLunloadPropertySet(string datapoint)
 ///////////////////////////////////////////////////////////////////////////
 void navPMLconfigurePropertySet(string psScope, string psApcName)
 {
-  LOG_TRACE("navPMLconfigurePropertySet",psScope,psApcName);
-  gcfConfigurePS(g_PAclientId,psScope,psApcName);
+  LOG_TRACE("navPMLconfigurePropertySet", psScope, psApcName);
+  gcfConfigurePS(g_PAclientId, psScope, psApcName);
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // pmlCallback - this function is called by the PropertyAgent when a (un)load request
 //               has finished. 
 // response array contents:
-// [1] : response ("loaded","unloaded","configured","gone")
+// [1] : response ("loaded", "unloaded", "configured", "gone")
 // [2] : datapoint name
-// [3] : result ("OK","failed")
+// [3] : result ("OK", "failed")
 ///////////////////////////////////////////////////////////////////////////
 void pmlCallback(dyn_string response)
 {
-  LOG_DEBUG("pmlCallback:",LOG_DYN(response));
-  if(response[1] == "loaded")
+  LOG_DEBUG("pmlCallback:", LOG_DYN(response));
+  if (response[1] == "loaded")
   {
-    if(response[3] == "OK")
+    if (response[3] == "OK")
     {
     }
     else
     {
     }
   }
-  else if(response[1] == "unloaded")
+  else if (response[1] == "unloaded")
   {
-    if(response[3] == "OK ")
+    if (response[3] == "OK ")
     {
     }
     else
     {
     }
   }
-  else if(response[1] == "configured")
+  else if (response[1] == "configured")
   {
-    if(response[3] == "OK ")
+    if (response[3] == "OK ")
     {
     }
     else
     {
     }
   }
-  else if(response[1] == "gone")
+  else if (response[1] == "gone")
   {
   }
   else
@@ -173,24 +187,24 @@ void pmlCallback(dyn_string response)
 ///////////////////////////////////////////////////////////////////////////
 bool navPMLisAutoLoaded(string datapoint)
 {
-  bool autoLoaded=false;
-  LOG_TRACE("navPMLisAutoLoaded",datapoint);
-  if(dpAccessable(datapoint))
+  bool autoLoaded = false;
+  LOG_TRACE("navPMLisAutoLoaded", datapoint);
+  if (dpAccessable(datapoint))
   {
     // check if the propertyset is autoloaded by GCF
-    if(dpAccessable(datapoint + NAVPML_DPNAME_ENABLED))
+    if (dpAccessable(datapoint + NAVPML_DPNAME_ENABLED))
     {
-      string enabled="";
-      dpGet(datapoint + NAVPML_DPNAME_ENABLED + ".",enabled);
-      if(patternMatch(NAVPML_ENABLED_AUTOLOAD, enabled))
+      string enabled = "";
+      dpGet(datapoint + NAVPML_DPNAME_ENABLED + ".", enabled);
+      if (strpos(enabled, NAVPML_ENABLED_AUTOLOAD) == 0)
       {
         autoLoaded = true;
       }
     }
   }
   else
- {
-    LOG_TRACE("navPMLloadPropertySet -- Datapoint does not exist",datapoint);
+  {
+    LOG_TRACE("navPMLloadPropertySet -- Datapoint does not exist", datapoint);
   }
   return autoLoaded;
 }
@@ -203,24 +217,23 @@ bool navPMLisAutoLoaded(string datapoint)
 ///////////////////////////////////////////////////////////////////////////
 bool navPMLisTemporary(string datapoint)
 {
-  bool temporary=false;
-  //LOG_TRACE("navPMLisTemporary",datapoint);
-  
+  bool temporary = false;
+
   // check if the propertyset is temporary by GCF
-  if(strpos(datapoint, NAVPML_DPNAME_ENABLED)>=0)
+  if (strpos(datapoint, NAVPML_DPNAME_ENABLED) > 0)
   {
-    if(dpAccessable(datapoint))
+    if (dpAccessable(datapoint))
     {
-      string enabled="";
+      string enabled = "";
       dpGet(datapoint + ".", enabled);
-      LOG_TRACE("navPMLisTemporary[content enabled]",enabled);
-      if(strpos(enabled, NAVPML_ENABLED_TEMP)>=0)
+      LOG_TRACE("navPMLisTemporary[content enabled]", enabled);
+      if (strpos(enabled, NAVPML_ENABLED_TEMP) == 0)
       {
         temporary = true;
       }
     }
   }
-  //LOG_TRACE("navPMLisTemporary[T/F]",temporary);
+  LOG_TRACE("navPMLisTemporary[T/F]", temporary);
   return temporary;
 }
 
diff --git a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-tab-functions.ctl b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-tab-functions.ctl
index e31cdb6c878..cc71818287a 100644
--- a/MAC/Navigator/scripts/libs/nav_fw/gcfnav-tab-functions.ctl
+++ b/MAC/Navigator/scripts/libs/nav_fw/gcfnav-tab-functions.ctl
@@ -237,14 +237,6 @@ void ComboBoxViewsSelectionChanged()
   }            
  
   string datapointTypeName = "";
-  //DebugTN("g_datapoint",g_datapoint);
-  //getDpTypeFromEnabled( + "__enabled.")
-  //This was the original one AdB 25-5-2005
-  // if(dpAccessable(g_datapoint))
-  //    datapointTypeName = getDpTypeFromEnabled(g_datapoint + "__enabled.");
-  //else
-  //    datapointTypeName = getDpTypeFromEnabled(g_datapoint + "__enabled."); //original was only <= g_datapoint>
-  //////////////////////////////////////////////////////////////
   if(dpAccessable(g_datapoint+"__enabled"))
   {
     datapointTypeName = getDpTypeFromEnabled(g_datapoint+"__enabled.");
@@ -258,7 +250,6 @@ void ComboBoxViewsSelectionChanged()
     datapointTypeName = g_datapoint;
   }
 
-  //  if(g_subViewConfigs[selectedSubView]==0)
   // Load the config panel in the viewTabsCtrl
   dyn_string configPanelParameters = makeDynString(
     "$selectedView:" + g_selectedView,
@@ -268,14 +259,6 @@ void ComboBoxViewsSelectionChanged()
     "$configDatapoint:"+insertSubViewConfigs,
     "$referenceDatapoint:" +referenceDatapoint);
   
-  //////////////////////////////////////////////////////////////  
-//  This is the original one
-/*  dyn_string configPanelParameters = makeDynString(
-    "$selectedView:" + g_selectedView,
-    "$viewName:" + g_selectedViewName,
-    "$selectedElementDpType:" + datapointTypeName,
-    "$datapoint:" + g_datapoint,
-    "$configDatapoint:"+g_subViewConfigs[selectedSubView]); */
   LOG_TRACE("configPanel,configParameters: ",g_configPanelFileName,configPanelParameters);
   
   // check if the file exists:
diff --git a/MAC/Navigator/scripts/libs/nav_fw/gcfpa-cwd.ctl b/MAC/Navigator/scripts/libs/nav_fw/gcfpa-cwd.ctl
index 63a0c5545c0..2b44723fdf9 100644
--- a/MAC/Navigator/scripts/libs/nav_fw/gcfpa-cwd.ctl
+++ b/MAC/Navigator/scripts/libs/nav_fw/gcfpa-cwd.ctl
@@ -1,4 +1,6 @@
 #uses "nav_fw/gcfpa-com.ctl"
+#uses "nav_fw/gcf-util.ctl"
+
 const string GCF_WD_DP = "__gcf_wd";
 main()
 {
@@ -12,7 +14,7 @@ main()
 
 void gcfConnectionWatchDog()
 {
-	//DebugTN("GCF: Starting GCF connection watch-dog");
+	LOG_INFO("GCF: Starting GCF connection watch-dog");
 	retrieveManNums(getSystemId());
  	dpGet("_DistManager.State.SystemNums", gDistSysList);
  	for (int i = 1; i <= dynlen(gDistSysList); i++)
@@ -20,12 +22,12 @@ void gcfConnectionWatchDog()
  		retrieveManNums(gDistSysList[i]);	 		
  	}
  	dpConnect("distSystemChanged", FALSE, "_DistManager.State.SystemNums");
-	//DebugTN("GCF: Watch-dog started");
+	LOG_TRACE("GCF: Watch-dog started");
 }
 
 void retrieveManNums(unsigned sysNr)
 {
-	//DebugTN("GCF: Add managers for (new) system " + getSystemName(sysNr) + ".");
+	LOG_TRACE("GCF: Add managers for (new) system " + getSystemName(sysNr) + ".");
 	string sysName = getSystemName(sysNr);
 	dyn_anytype manNums;
  	dpGet(sysName + "_Connections.Ui.ManNums", manNums);
@@ -44,7 +46,7 @@ void addManagers(unsigned sysNr, dyn_anytype manNums, string manType)
 	for (int i = 1; i <= dynlen(manNums); i++)
 	{
 		manItem = makeDynString(sysNr, manType, manNums[i]);	
-		//DebugTN("GCF: Add mananger: " + getSystemName(sysNr) + manType + ":" + manNums[i]);
+		LOG_TRACE("GCF: Add mananger: " + getSystemName(sysNr) + manType + ":" + manNums[i]);
 		gConnManList[dynlen(gConnManList) + 1] = manItem;
 	}
 }
@@ -71,23 +73,9 @@ void distSystemChanged(string dp, dyn_uint newDistSysList)
 
 void remoteSystemGone(unsigned sysNr)
 {
-	//DebugTN("GCF: System " + getSystemName(sysNr) + " gone.");	
+	LOG_TRACE("GCF: System " + getSystemName(sysNr) + " gone.");	
 	string msg = "d" + sysNr + ":";
-	//sendEventToPA(msg, getSystemName());
 	dpSet(GCF_WD_DP + ".sys", msg);
-	//dyn_anytype manNums;
-	//dpGet("_Connections.Api.ManNums", manNums);
-	//dyn_string apiDPNames;
-	//msg = "u|" + getSystemId() + ":Ctrl:" + myManNum() + ":|" + 
-	//			getSystemName() + "__gcf_DPA_server|gone|" + getSystemName() + "|";	
-	//for (int i = 1; i <= dynlen(manNums); i++)
-	//{
-	//	apiDPNames = dpNames("__gcf_DPA_client_API" + i + "_*", "GCFDistPort");		
-	//	for (int j = 1; j <= dynlen(apiDPNames); j++)
-	//	{
-	//		sendEvent(apiDPNames[j] + ".", msg);
-	//	}
-	//}	
 	for (int i = 1; i <= dynlen(gConnManList); i++)
 	{
 		if (gConnManList[i][1] == sysNr)
@@ -95,7 +83,6 @@ void remoteSystemGone(unsigned sysNr)
 			dynRemove(gConnManList, i);
 		}
 	}
-	//dpSet("__gcf_WDGoneSys.", sysNr);
 }
 
 void uiConnectionsChanged(string dp, dyn_uint value)
@@ -131,7 +118,7 @@ void connectionsChanged(string dp, dyn_uint value, string manType)
 		if (!manNumFound)
 		{
 			newItem = makeDynString(sysNr, manType, value[i]);
-			//DebugTN("GCF: Add mananger: " + getSystemName(sysNr) + manType + ":" + value[i]);
+			LOG_TRACE("GCF: Add mananger: " + getSystemName(sysNr) + manType + ":" + value[i]);
 			gConnManList[dynlen(gConnManList) + 1] = newItem;
 		}
 		else
@@ -147,9 +134,8 @@ void connectionsChanged(string dp, dyn_uint value, string manType)
 		{
 			// a (remote) manager is disconnected from PVSS so inform the local property agent
 			msg = "d" + sysNr + ":" + manType + ":" + gConnManList[i][3] + ":";
-			//DebugTN("GCF: Remove mananger: " + msg);
+			LOG_TRACE("GCF: Remove mananger: " + msg);
 			dpSet(GCF_WD_DP + ".man", msg);
-			//sendEventToPA(msg, getSystemName());
 
 			dynRemove(gConnManList, i);
 		}
diff --git a/MAC/Navigator/scripts/libs/nav_fw/gcfpa-pml.ctl b/MAC/Navigator/scripts/libs/nav_fw/gcfpa-pml.ctl
index 895f84b9e19..79624cac7f9 100644
--- a/MAC/Navigator/scripts/libs/nav_fw/gcfpa-pml.ctl
+++ b/MAC/Navigator/scripts/libs/nav_fw/gcfpa-pml.ctl
@@ -1,4 +1,5 @@
 #uses "nav_fw/gcfpa-com.ctl"
+#uses "nav_fw/gcf-util.ctl"
 
 global dyn_dyn_string gCallBackList; // 1 == callBackFuncName; 2 == ID; 3 == myManNum
 global dyn_dyn_string gSeqList;	// 1 == seqNr ; 2 == ID; 3 == scope
@@ -17,14 +18,14 @@ unsigned gcfInit(string callBackFuncName)
 		ID++;
 	} while (dynContains(IDlist, ID) > 0);
 	
-	//DebugTN("GCF: ID " + ID + " is claimed for unique communication with PA of GCF.");
+	LOG_INFO("GCF: ID " + ID + " is claimed for unique communication with PA of GCF.");
 	dyn_string newItem;
 	string callBackDP = "__gcfportUIM" + myManNum() +"_" + ID + "_DPAclient";
 	if (!dpExists(callBackDP))
 	{
 		dpCreate(callBackDP, "GCFDistPort");
 	}
-	//DebugTN("GCF: " + callBackDP + " will be used for communication with PA.");
+	LOG_DEBUG("GCF: " + callBackDP + " will be used for communication with PA.");
 	dpConnect("gcfMainCallBack", FALSE, callBackDP + ".");			
 	newItem = makeDynString(callBackFuncName, ID, myManNum());
 	gCallBackList[dynlen(gCallBackList) + 1] = newItem;
@@ -32,17 +33,17 @@ unsigned gcfInit(string callBackFuncName)
 	return ID;
 }
 
-void gcfLeave(unsigned ID)
+void gcfLeave(unsigned ID, bool inTerminate = false)
 {
-	//DebugTN("GCF: ID " + ID + " will be freed.");
+	LOG_INFO("GCF: ID " + ID + " will be freed.");
 	
 	for (int i = 1; i <= dynlen(gCallBackList); i++)
 	{
 		if (gCallBackList[i][2] == ID)
 		{
 			string callBackDP = buildCallBackDP(ID) + ".";
-			//DebugTN("GCF: " + callBackDP + " will not be used anymore.");
-			dpDisconnect("gcfMainCallBack", callBackDP);
+			LOG_DEBUG("GCF: " + callBackDP + " will not be used anymore.");
+			if (!inTerminate) dpDisconnect("gcfMainCallBack", callBackDP);
 			dynRemove(gCallBackList, i);
 			break;
 		}
@@ -77,7 +78,7 @@ void gcfLeave(unsigned ID)
 void gcfLoadPS(unsigned ID, string psScope)
 {
 	correctScope(psScope);
-	//DebugTN("GCF: Request to load property set " + psScope);
+	LOG_TRACE("GCF: Request to load property set " + psScope);
 	if (idExists(ID) && isPAOnline(dpSubStr(psScope, DPSUB_SYS)))
 	{
 		string portID = buildPortId(ID);
@@ -91,7 +92,7 @@ void gcfLoadPS(unsigned ID, string psScope)
 void gcfUnloadPS(unsigned ID, string psScope)
 {
 	correctScope(psScope);
-	//DebugTN("GCF: Request to unload property set " + psScope);
+	LOG_TRACE("GCF: Request to unload property set " + psScope);
 	if (idExists(ID) && isPAOnline(dpSubStr(psScope, DPSUB_SYS)))
 	{
 		string portID = buildPortId(ID);
@@ -106,7 +107,7 @@ void gcfUnloadPS(unsigned ID, string psScope)
 void gcfConfigurePS(unsigned ID, string psScope, string psApcName)
 {
 	correctScope(psScope);
-	//DebugTN("GCF: Request to configure property set " + psScope + " with APC " + psApcName);
+	LOG_TRACE("GCF: Request to configure property set " + psScope + " with APC " + psApcName);
 	if (idExists(ID) && isPAOnline(dpSubStr(psScope, DPSUB_SYS)))
 	{
 		string portID = buildPortId(ID);
@@ -130,7 +131,7 @@ void gcfMainCallBack(string callBackDP, blob value)
 	dyn_string msg;
 	string msgValue;
 	blobGetValue(value, 0, msgValue, bloblen(value));
-	//DebugTN("GCF: Incomming message: " + msgValue);
+	LOG_TRACE("GCF: Incomming message: " + msgValue);
 	msg = strsplit(msgValue, "|");
 	dyn_string response;
 	if (msg[1] == "m")
@@ -256,7 +257,7 @@ void callUserDefinedFunction(string& callBackFunc, dyn_string& response)
 	}
 	else
 	{
-		DebugTN("GCF ERROR: CallBackFunc '" + callBackFunc + "' not defined by user!"); 
+		LOG_TRACE("GCF ERROR: CallBackFunc '" + callBackFunc + "' not defined by user!"); 
 	}	
 }
 
@@ -309,7 +310,7 @@ bool isPAOnline(string sysName)
 {
 	bool paOnline = dpExists(sysName + "__gcfportAPI_DPAserver");
 	
-	if (!paOnline) DebugTN("GCF ERROR: PA on system " + sysName + " not reachable!");
+	if (!paOnline) LOG_ERROR("GCF ERROR: PA on system " + sysName + " not reachable!");
 	return paOnline;
 }
 
@@ -322,7 +323,7 @@ void gcfWatchDog(string dp, string wdMsg)
 		string callBackFunc;
 		dyn_string indication;
 		
-		DebugTN("GCF: System " + getSystemName(sysNr) + " is gone.");
+		LOG_TRACE("GCF: System " + getSystemName(sysNr) + " is gone.");
 		for (int i = 1; i <= dynlen(gPSList); i++)
 		{
 			sysNrOfLoadedPS = getSystemId(dpSubStr(gPSList[i][1], DPSUB_SYS)); // 1 == loaded property set scope
@@ -350,6 +351,6 @@ void gcfWatchDog(string dp, string wdMsg)
 	}
 	else
 	{
-		DebugTN("GCF: System " + getSystemName(sysNr) + " came.");
+		LOG_TRACE("GCF: System " + getSystemName(sysNr) + " came.");
 	}
 }
\ No newline at end of file
-- 
GitLab