osaf/services/saf/smfsv/smfd/SmfCampaignXmlParser.cc |  22 ++++-
 osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.cc     |  77 +++++++++++++++++++-
 osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.hh     |  33 ++++++++-
 3 files changed, 126 insertions(+), 6 deletions(-)


The redundant <swAdd> and <swRemove> entries in single step procedures are 
removed.
This can happen in 2 cases where the upgrade scope is:
-forAddRemove: the activationUnit contains swAdd and the deactivation unit 
contains swRemove
-forModify: the activationUnit contains swAdd and swRemove

diff --git a/osaf/services/saf/smfsv/smfd/SmfCampaignXmlParser.cc 
b/osaf/services/saf/smfsv/smfd/SmfCampaignXmlParser.cc
--- a/osaf/services/saf/smfsv/smfd/SmfCampaignXmlParser.cc
+++ b/osaf/services/saf/smfsv/smfd/SmfCampaignXmlParser.cc
@@ -225,12 +225,26 @@ SmfCampaignXmlParser::parseCampaignXml(s
                                        goto error_exit;
                                }
                                const SmfTargetNodeTemplate *nodeTemplate = 
byTemplate->getTargetNodeTemplate();
-
-                               const_cast<SmfTargetNodeTemplate 
*>(nodeTemplate)->removeSwAddRemoveDuplicates();
-
+                               const_cast<SmfTargetNodeTemplate 
*>(nodeTemplate)->removeSwAddRemoveDuplicates();
                                break;
                        }
-                       case SA_SMF_SINGLE_STEP:  //No action for single step 
procedures
+                       case SA_SMF_SINGLE_STEP:
+                       {
+                               SmfSinglestepUpgrade *singleStepUpgrade = 
(SmfSinglestepUpgrade *) upgradeMethod;
+                               const SmfUpgradeScope *upgradeScope = 
singleStepUpgrade->getUpgradeScope();
+                               if(!upgradeScope) {
+                                       
LOG_NO("SmfCampaignXmlParser::parseCampaignXml: No upgrade scope for 
singleStep");
+                                       goto error_exit;
+                               }
+                               //Cast to valid upgradeScope
+                               const SmfForAddRemove* addRemove = 
dynamic_cast<const SmfForAddRemove*>(upgradeScope);
+                               const SmfForModify* modify = dynamic_cast<const 
SmfForModify*>(upgradeScope);
+                               if(addRemove)
+                                       
const_cast<SmfForAddRemove*>(addRemove)->removeSwAddRemoveDuplicates();
+                               else if(modify)
+                                       
const_cast<SmfForModify*>(modify)->removeSwAddRemoveDuplicates();
+                               break;
+                       }
                        default:
                        {
                                break;
diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.cc 
b/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.cc
--- a/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.cc
+++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.cc
@@ -201,6 +201,61 @@ SmfUpgradeScope::~SmfUpgradeScope()
 {
 }
 
+// 
------------------------------------------------------------------------------
+// removeSwAddRemoveDuplicates()
+// 
------------------------------------------------------------------------------
+void
+SmfUpgradeScope::removeSwAddRemoveDuplicates(std::list<SmfBundleRef> 
&io_addList, std::list<SmfBundleRef> &io_removeList)
+{
+       TRACE_ENTER();
+       std::list<SmfBundleRef>::iterator itAdd;
+       std::list<SmfBundleRef>::iterator itRemove;
+       std::set<std::string> toBeRemoved;
+
+       // Find out which bundles are specified in both swAdd and SwRemove.
+       // Create a set of DN, since the comparison is based on that.
+       for (itAdd = io_addList.begin(); itAdd != io_addList.end(); itAdd++) {
+               for (itRemove = io_removeList.begin(); itRemove != 
io_removeList.end(); itRemove++) {
+                       const std::string& swAddBundleDn = itAdd->getBundleDn();
+                       if (swAddBundleDn == itRemove->getBundleDn()) {
+                               
TRACE("SmfUpgradeScope::removeSwAddRemoveDuplicates(): Bundle=%s found in 
<swAdd> and <swRemove> within a procedure, remove from both lists\n", 
swAddBundleDn.c_str());
+                               toBeRemoved.insert(swAddBundleDn);
+                               // Can break now since only need to store the 
DN once.
+                               // DNs stored in set, no way to insert a DN 
twice.
+                               break;
+                       }
+               }
+       }
+
+       // Iterate through the DNs which need to be removed from add and remove 
lists.
+       // Remove all the "add" and "remove" objects which have that specific 
DN.
+       for (std::set<std::string>::iterator i = toBeRemoved.begin(); i != 
toBeRemoved.end(); i++) {
+               removeSwAddRemoveDuplicate(io_addList, *i);
+               removeSwAddRemoveDuplicate(io_removeList, *i);
+       }
+       TRACE_LEAVE();
+}
+// 
------------------------------------------------------------------------------
+// removeSwAddRemoveDuplicate()
+// 
------------------------------------------------------------------------------
+void
+SmfUpgradeScope::removeSwAddRemoveDuplicate(std::list<SmfBundleRef> 
&io_addOrRemoveList, const std::string &i_dn)
+{
+       TRACE_ENTER();
+       std::list<SmfBundleRef>::iterator iter = io_addOrRemoveList.begin();
+       while(iter != io_addOrRemoveList.end()) {
+               if(iter->getBundleDn() == i_dn) {
+                       TRACE("SmfUpgradeScope::removeSwAddRemoveDuplicate(): 
erase element \"%s\"",i_dn.c_str());
+                       io_addOrRemoveList.erase(iter);
+                       // For safety, set the iterator to the beginning of the 
list.
+                       iter = io_addOrRemoveList.begin();
+               }
+               else
+                       iter++;
+       }
+       TRACE_LEAVE();
+}
+
 
//================================================================================
 // Class SmfByTemplate
 // Purpose:
@@ -309,7 +364,15 @@ SmfForAddRemove::getDeactivationUnit(voi
 {
        return m_deactivationUnit;
 }
-
+void
+SmfForAddRemove::removeSwAddRemoveDuplicates(void)
+{
+       TRACE_ENTER();
+       std::list<SmfBundleRef> &addList = const_cast<std::list<SmfBundleRef> 
&>(getActivationUnit()->getSwAdd());
+       std::list<SmfBundleRef> &removeList = 
const_cast<std::list<SmfBundleRef> &>(getDeactivationUnit()->getSwRemove());
+       SmfUpgradeScope::removeSwAddRemoveDuplicates(addList, removeList);
+       TRACE_LEAVE();
+}
 
//================================================================================
 // Class SmfForModify
 // Purpose:
@@ -364,3 +427,15 @@ SmfForModify::getTargetEntityTemplate() 
        return m_targetEntityTemplate;
 }
 
+//------------------------------------------------------------------------------
+// removeSwAddRemoveDuplicates()
+//------------------------------------------------------------------------------
+void
+SmfForModify::removeSwAddRemoveDuplicates(void)
+{
+       TRACE_ENTER();
+       std::list<SmfBundleRef> &addList = const_cast<std::list<SmfBundleRef> 
&>(getActivationUnit()->getSwAdd());
+       std::list<SmfBundleRef> &removeList = 
const_cast<std::list<SmfBundleRef> &>(getActivationUnit()->getSwRemove());
+       SmfUpgradeScope::removeSwAddRemoveDuplicates(addList, removeList);
+       TRACE_LEAVE();
+}
diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.hh 
b/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.hh
--- a/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.hh
+++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeMethod.hh
@@ -25,6 +25,7 @@
 
 #include <string>
 #include <vector>
+#include <set>
 #include <saAis.h>
 #include <saSmf.h>
 #include "SmfTargetTemplate.hh"
@@ -220,7 +221,24 @@ class SmfUpgradeScope {
 ///
        virtual ~SmfUpgradeScope();
 
- private:
+ protected:
+
+///
+/// Purpose: Remove duplicates of SwAdd and SwRemove.
+/// @param   io_addList: addList of SmfBundleRef objects
+/// @param   io_removeList: removeList of SmfBundleRef objects
+/// @return  None.
+///
+       void removeSwAddRemoveDuplicates(std::list<SmfBundleRef> &io_addList, 
std::list<SmfBundleRef> &io_removeList);
+
+///
+/// Purpose: Remove duplicates of SwAdd and SwRemove.
+///          Based on the given DN, the specified swBundleRef objects will be 
deleted from addList/removeList
+/// @param   io_addOrRemoveList: addList or removeList
+/// @param   i_dn: DN
+/// @return  None.
+///
+       void removeSwAddRemoveDuplicate(std::list<SmfBundleRef> 
&io_addOrRemoveList, const std::string &i_dn);
 
 };
 
@@ -394,6 +412,12 @@ class SmfForAddRemove : public SmfUpgrad
 ///
        const SmfActivationUnitType *getDeactivationUnit(void) const;
 
+///
+/// Purpose: Remove duplicates of SwAdd and SwRemove.
+/// @param   None.
+/// @return  None.
+///
+       void removeSwAddRemoveDuplicates(void);
 
  private:
 
@@ -453,6 +477,13 @@ class SmfForModify : public SmfUpgradeSc
 ///
        const SmfActivationUnitType *getActivationUnit(void) const;
 
+///
+/// Purpose: Remove duplicates of SwAdd and SwRemove.
+/// @param   None.
+/// @return  None.
+///
+       void removeSwAddRemoveDuplicates(void);
+
  private:
 
        /* The list of target entity templates */

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to