simpleengine/xdmrlspres/src/prescondidentityone.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    RLS and Presence XDM, This class represents 'one' identity part
       
    15 *                 of a Presence Condition in a rule
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // Includes
       
    23 #include <XdmDocumentNode.h>
       
    24 #include <XdmNodeAttribute.h>
       
    25 #include <xcapappusagedef.h>
       
    26 #include <utf.h>
       
    27 
       
    28 #include "prescondidentityone.h"
       
    29 #include "cpresencexdm.h"
       
    30 #include "rlspresxdmlogger.h"
       
    31 #include "rlspresxdmconstsint.h"
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // TPresCondIdentityOne::TPresCondIdentityOne()
       
    36 // ---------------------------------------------------------------------------
       
    37 //	
       
    38 EXPORT_C TPresCondIdentityOne::TPresCondIdentityOne(): iPresXDM(NULL)
       
    39     {
       
    40     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::TPresCondIdentityOne()" ));
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // TPresCondIdentityOne::Init()
       
    45 // ---------------------------------------------------------------------------
       
    46 //    
       
    47 EXPORT_C void TPresCondIdentityOne::Init(CPresenceXDM* const aPresXDM)
       
    48     {
       
    49     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::Init(%d)" ), aPresXDM);
       
    50     iPresXDM = aPresXDM;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // TPresCondIdentityOne::AddIdentitiesL()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C TInt TPresCondIdentityOne::AddIdentitiesL(const TDesC& aRuleID,
       
    58                                                 const MDesCArray& aIds)
       
    59 	{
       
    60     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::AddIdentitiesL()" ) );
       
    61     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aIdsCount = %d" ),&aRuleID, 
       
    62                                                         aIds.MdcaCount() );
       
    63     
       
    64     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));                                                    
       
    65     
       
    66 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
    67 	                                                KXdmIdentity, ETrue);
       
    68 	if(identityNode==NULL)
       
    69 	    {
       
    70 	    OPENG_DP(D_OPENG_LIT( "     return: KErrNotFound" ));
       
    71 	    return KErrNotFound;
       
    72 	    }
       
    73 	    
       
    74     CXdmDocumentNode* oneNode(NULL);
       
    75     CXdmNodeAttribute* idAttr(NULL);
       
    76   	RPointerArray<CXdmDocumentNode> nodes;
       
    77   	
       
    78 	// finding 'one' nodes
       
    79     TInt err = identityNode->Find(KXdmOne, nodes);
       
    80     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),nodes.Count());
       
    81 
       
    82     // putting ids to identity node
       
    83     TInt entitiesCount = aIds.MdcaCount();
       
    84     for(TInt i=0;i<entitiesCount;i++)
       
    85         {
       
    86         // find whether its already exist
       
    87         if(IsIdExistInNodeArray(nodes, aIds.MdcaPoint(i)) )
       
    88             continue;    
       
    89         oneNode = identityNode->CreateChileNodeL(KXdmOne);
       
    90         idAttr = oneNode->CreateAttributeL(KXdmId);
       
    91         idAttr->SetAttributeValueL(aIds.MdcaPoint(i));
       
    92         }
       
    93     
       
    94     nodes.Close();
       
    95     OPENG_DP(D_OPENG_LIT( "     return: KErrNone" ));    
       
    96     return KErrNone;
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // TPresCondIdentityOne::GetIdentitiesL()
       
   101 // ---------------------------------------------------------------------------
       
   102 //	
       
   103 EXPORT_C void TPresCondIdentityOne::GetIdentitiesL(const TDesC& aRuleID, 
       
   104                                                     CDesCArray& aIds)
       
   105 	{
       
   106     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::GetIdentitiesL()" ) );
       
   107     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S" ),&aRuleID);
       
   108     
       
   109     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   110     
       
   111 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   112 	                                                KXdmIdentity, EFalse);
       
   113 	if(identityNode==NULL)
       
   114 	    return;
       
   115 	
       
   116 	RPointerArray<CXdmDocumentNode> nodes;
       
   117     CXdmNodeAttribute* idAttr(NULL);
       
   118 	
       
   119 	// finding 'one' nodes
       
   120     TInt err = identityNode->Find(KXdmOne, nodes);
       
   121     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),nodes.Count());
       
   122 
       
   123     // extracting ids from ones nodes
       
   124     TInt idsCountInNode = nodes.Count();
       
   125     for (TInt i=0;i<idsCountInNode;i++)
       
   126         { // get the id attribute
       
   127         idAttr = (nodes[i])->Attribute(KXdmId);
       
   128         // push it to given discriptor array
       
   129         aIds.AppendL(idAttr->AttributeValue());
       
   130         }
       
   131 
       
   132     nodes.Close();    
       
   133     return;
       
   134 	}
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // TPresCondIdentityOne::DeleteIdentitiesL()
       
   138 // ---------------------------------------------------------------------------
       
   139 //	
       
   140 EXPORT_C void TPresCondIdentityOne::DeleteIdentitiesL(const TDesC& aRuleID,
       
   141                                                     const MDesCArray& aIds)
       
   142 	{
       
   143     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::DeleteIdentitiesL()" ) );
       
   144     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aIdsCount = %d" ),&aRuleID, 
       
   145                                                         aIds.MdcaCount() );
       
   146 	
       
   147     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));                                                    
       
   148 	
       
   149 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   150 	                                                KXdmIdentity, EFalse);
       
   151 	if(identityNode==NULL)
       
   152 	    return;
       
   153 	
       
   154 	RPointerArray<CXdmDocumentNode> nodes;
       
   155     CXdmNodeAttribute* idAttr(NULL);
       
   156 	
       
   157 	// finding 'one' nodes
       
   158     TInt err = identityNode->Find(KXdmOne, nodes);
       
   159 
       
   160     // extracting ids from ones nodes
       
   161     TInt idsCountInNode = nodes.Count();
       
   162     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),idsCountInNode);
       
   163 
       
   164     TInt entitiesCount = aIds.MdcaCount();
       
   165     for (TInt i=0;i<idsCountInNode;i++)
       
   166         { // get the id attribute
       
   167         idAttr = (nodes[i])->Attribute(KXdmId);
       
   168         // match it with all given entries
       
   169         for (TInt j=0;j<entitiesCount ; j++)
       
   170             {
       
   171             if ((aIds.MdcaPoint(j))==(idAttr->AttributeValue()))
       
   172                 {
       
   173                 OPENG_DP(D_OPENG_LIT( "     RemoveFromModelL i=%d,j=%d" ),i,j);
       
   174                 iPresXDM->RemoveFromModelL(nodes[i]);
       
   175                 break;               
       
   176                 }
       
   177             }
       
   178         }
       
   179 
       
   180     nodes.Close();    
       
   181     return;
       
   182 	}
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // TPresCondIdentityOne::DeleteAllIdentitiesL()
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C void TPresCondIdentityOne::DeleteAllIdentitiesL(const TDesC& aRuleID)
       
   189 	{
       
   190     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::DeleteAllIdentitiesL()" ) );
       
   191     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S"),&aRuleID);
       
   192 	
       
   193     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   194 	
       
   195 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   196 	                                                KXdmIdentity, EFalse);
       
   197 	if(identityNode==NULL)
       
   198 	    return;
       
   199 	
       
   200 	RPointerArray<CXdmDocumentNode> nodes;
       
   201 	
       
   202 	// finding 'one' nodes
       
   203     TInt err = identityNode->Find(KXdmOne, nodes);
       
   204     
       
   205     // extracting ids from ones nodes
       
   206     TInt idsCountInNode = nodes.Count();
       
   207     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),idsCountInNode);
       
   208     
       
   209     for (TInt i=0;i<idsCountInNode;i++)
       
   210         {
       
   211         iPresXDM->RemoveFromModelL(nodes[i]);
       
   212         }
       
   213 
       
   214     nodes.Close();    
       
   215     return;
       
   216 	}
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // TPresCondIdentityOne::AddIdentityL()
       
   220 // ---------------------------------------------------------------------------
       
   221 //	
       
   222 EXPORT_C TInt TPresCondIdentityOne::AddIdentityL(const TDesC& aRuleID, 
       
   223                                                         const TDesC& aId)
       
   224 	{
       
   225     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::AddIdentityL()" ) );
       
   226     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aId = %S"),&aRuleID, &aId);
       
   227 	
       
   228     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   229 	
       
   230 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   231 	                                                KXdmIdentity, ETrue);
       
   232 	if(identityNode==NULL)
       
   233 	    return KErrNotFound;
       
   234 	
       
   235 	if(IsIdentityExistL(aRuleID,aId))
       
   236 	    return KErrAlreadyExists;
       
   237 	
       
   238     CXdmDocumentNode* oneNode(NULL);
       
   239     CXdmNodeAttribute* idAttr(NULL);
       
   240    
       
   241     oneNode = identityNode->CreateChileNodeL(KXdmOne);
       
   242     idAttr = oneNode->CreateAttributeL(KXdmId);
       
   243     idAttr->SetAttributeValueL(aId);
       
   244     
       
   245     OPENG_DP(D_OPENG_LIT( "     return: KErrNone"));
       
   246     return KErrNone;
       
   247 	}
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // TPresCondIdentityOne::DeleteIdentityL()
       
   251 // ---------------------------------------------------------------------------
       
   252 //	
       
   253 EXPORT_C TInt TPresCondIdentityOne::DeleteIdentityL(const TDesC& aRuleID, 
       
   254                                                         const TDesC& aId)
       
   255 	{
       
   256     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::DeleteIdentityL()" ) );
       
   257     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aId = %S"),&aRuleID, &aId);
       
   258 	
       
   259     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   260 	
       
   261 	TInt ret(KErrNotFound);
       
   262 	
       
   263 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   264 	                                                KXdmIdentity, EFalse);
       
   265 	if(identityNode==NULL)
       
   266 	    return ret;
       
   267 
       
   268 	RPointerArray<CXdmDocumentNode> nodes;
       
   269     CXdmNodeAttribute* idAttr(NULL);
       
   270 	
       
   271 	// finding 'one' nodes
       
   272     if ( (identityNode->Find(KXdmOne, nodes))==KErrNone)
       
   273         {
       
   274         // extracting ids from ones nodes
       
   275         TInt idsCountInNode = nodes.Count();
       
   276         OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),idsCountInNode);
       
   277        
       
   278         for (TInt i=0;i<idsCountInNode;i++)
       
   279             { // get the id attribute
       
   280             idAttr = (nodes[i])->Attribute(KXdmId);
       
   281             if (aId==(idAttr->AttributeValue()))
       
   282                 {
       
   283                 OPENG_DP(D_OPENG_LIT( "     RemoveFromModelL: i=%d" ),i);
       
   284                 iPresXDM->RemoveFromModelL(nodes[i]);
       
   285                 ret = KErrNone;
       
   286                 break;               
       
   287                 }
       
   288             }
       
   289         }
       
   290     nodes.Close();    
       
   291     return ret;
       
   292 	}
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // TPresCondIdentityOne::IsIdentityExistL()
       
   296 // ---------------------------------------------------------------------------
       
   297 //	
       
   298 EXPORT_C TBool TPresCondIdentityOne::IsIdentityExistL(const TDesC& aRuleID, 
       
   299                                                     const TDesC& aId)
       
   300 	{
       
   301     OPENG_DP(D_OPENG_LIT( "TPresCondIdentityOne::IsIdentityExist()" ) );
       
   302     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aId = %S"),&aRuleID, &aId);
       
   303 
       
   304     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   305 
       
   306 	CXdmDocumentNode* identityNode = iPresXDM->GetConditionChildNodeL(aRuleID, 
       
   307 	                                                KXdmIdentity, EFalse);
       
   308 	if(identityNode==NULL)
       
   309 	    return EFalse;
       
   310 
       
   311 	RPointerArray<CXdmDocumentNode> nodes;
       
   312     CXdmNodeAttribute* idAttr(NULL);
       
   313 	
       
   314 	// finding 'one' nodes
       
   315     TInt err = identityNode->Find(KXdmOne, nodes);
       
   316     
       
   317     // extracting ids from ones nodes
       
   318     TInt idsCountInNode = nodes.Count();
       
   319     OPENG_DP(D_OPENG_LIT( "     nodesCount = %d" ),idsCountInNode);
       
   320     
       
   321     for (TInt i=0;i<idsCountInNode;i++)
       
   322         { // get the id attribute
       
   323         idAttr = (nodes[i])->Attribute(KXdmId);
       
   324         if (aId==(idAttr->AttributeValue()))
       
   325             {
       
   326             OPENG_DP(D_OPENG_LIT( "     ETrue"));
       
   327             nodes.Close();
       
   328             return ETrue;               
       
   329             }
       
   330         }
       
   331 
       
   332     nodes.Close();    
       
   333     return EFalse;
       
   334 	}
       
   335 	
       
   336 // ---------------------------------------------------------------------------
       
   337 // TPresCondIdentityOne::IsIdExistInNodeArray()
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 TBool TPresCondIdentityOne::IsIdExistInNodeArray(
       
   341                         const RPointerArray<CXdmDocumentNode>& nodes, 
       
   342                                                     const TDesC& aId)
       
   343     {
       
   344     OPENG_DP(D_OPENG_LIT( " TPresCondIdentityOne::IsIdExistInNodeArray()" ) );
       
   345     OPENG_DP(D_OPENG_LIT( "     IsIdExistInNodeArray aId = %S"), &aId);
       
   346 
       
   347     TInt idsCountInNode = nodes.Count();
       
   348     CXdmNodeAttribute* idAttr(NULL);
       
   349     for (TInt i=0;i<idsCountInNode;i++)
       
   350         { // get the id attribute
       
   351         idAttr = (nodes[i])->Attribute(KXdmId);
       
   352         if (aId==(idAttr->AttributeValue()))
       
   353             {
       
   354             OPENG_DP(D_OPENG_LIT( "     IsIdExistInNodeArray True"));
       
   355             return ETrue;               
       
   356             }
       
   357         }
       
   358     return EFalse;  
       
   359     }
       
   360     
       
   361 // end of file
       
   362