simpleengine/xdmrlspres/src/presenceactionxdm.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 Presence Action
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // Includes
       
    22 #include <utf.h>
       
    23 #include <XdmDocumentNode.h>
       
    24 #include <XdmNodeAttribute.h>
       
    25 #include <xcapappusagedef.h>
       
    26 
       
    27 #include "cpresencexdm.h"
       
    28 #include "presenceactionxdm.h"
       
    29 #include "rlspresxdmlogger.h"
       
    30 #include "rlspresxdmconstsint.h"
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // TPresenceActionXDM::TPresenceActionXDM()
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C TPresenceActionXDM::TPresenceActionXDM():iPresXDM(NULL)
       
    37     {
       
    38     OPENG_DP(D_OPENG_LIT( "TPresenceActionXDM::TPresenceActionXDM()" ) );
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // TPresenceActionXDM::Init()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C void TPresenceActionXDM::Init(CPresenceXDM* const aPresXDM)
       
    46     {
       
    47     OPENG_DP(D_OPENG_LIT( "TPresenceActionXDM::Init(aPresXDM=%d)"),aPresXDM );
       
    48     iPresXDM = aPresXDM;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // TPresenceActionXDM::AddOrReplaceAction()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C TInt TPresenceActionXDM::AddOrReplaceActionL(const TDesC& aRuleID, 
       
    56                                                         const TDesC& aAction)
       
    57 	{
       
    58     OPENG_DP(D_OPENG_LIT( "TPresenceActionXDM::AddOrReplaceActionL()" ) );
       
    59     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S, aAction = %S" ),&aRuleID, &aAction);
       
    60 
       
    61     TInt err(KErrNone);
       
    62 
       
    63     CXdmDocumentNode* subHandlingNode = GetSubHandlingNodeL(aRuleID, ETrue);
       
    64     if(subHandlingNode!=NULL)
       
    65         {
       
    66         if(IsValidAction(aAction))
       
    67             {
       
    68             subHandlingNode->SetLeafNode(ETrue);
       
    69             subHandlingNode->SetLeafNodeContentL(aAction);
       
    70             err = KErrNone;			
       
    71             }
       
    72         else
       
    73             err = KErrArgument;		
       
    74         }
       
    75     else
       
    76 		err = KErrNotFound;
       
    77 	
       
    78     OPENG_DP(D_OPENG_LIT( "     return: %d" ),err);
       
    79     return err;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // TPresenceActionXDM::RemoveAction()
       
    84 // ---------------------------------------------------------------------------
       
    85 //                                                                
       
    86 EXPORT_C TInt TPresenceActionXDM::RemoveActionL(const TDesC& aRuleID)
       
    87 	{
       
    88     OPENG_DP(D_OPENG_LIT( "TPresenceActionXDM::RemoveActionL()" ) );
       
    89     OPENG_DP(D_OPENG_LIT( "     aRuleID = %S" ),&aRuleID );
       
    90     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
    91 
       
    92     TInt err(KErrNone);
       
    93     CXdmDocumentNode* subHandlingNode = GetSubHandlingNodeL(aRuleID, EFalse);
       
    94     if(subHandlingNode!=NULL)
       
    95         iPresXDM->RemoveFromModelL(subHandlingNode);
       
    96     else
       
    97         err = KErrNotFound;
       
    98 
       
    99     OPENG_DP(D_OPENG_LIT( "     return: %d" ),err);
       
   100     return err;
       
   101 	}
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // TPresenceActionXDM::GetAction()
       
   105 // ---------------------------------------------------------------------------
       
   106 //         
       
   107 EXPORT_C TInt TPresenceActionXDM::GetActionL(const TDesC& aRuleID, TDes& aAction)
       
   108 	{
       
   109     OPENG_DP(D_OPENG_LIT( "TPresenceActionXDM::GetActionL()" ) );
       
   110     OPENG_DP(D_OPENG_LIT( "		aRuleID = %S" ),&aRuleID );
       
   111 	
       
   112     TInt err(KErrNone);
       
   113 	
       
   114 	CXdmDocumentNode* subHandlingNode = GetSubHandlingNodeL(aRuleID, EFalse);
       
   115 	if(subHandlingNode==NULL)
       
   116     	{
       
   117         OPENG_DP(D_OPENG_LIT( "     return: KErrNotFound" ));
       
   118     	return KErrNotFound;	
       
   119     	}
       
   120 	    
       
   121 	HBufC* nodeContents(NULL);
       
   122 
       
   123     subHandlingNode->SetLeafNode(ETrue);
       
   124     nodeContents = CnvUtfConverter::ConvertToUnicodeFromUtf8L
       
   125                                             (subHandlingNode->LeafNodeContent());
       
   126     //Check given string length
       
   127     if((nodeContents->Des()).Length() > aAction.MaxLength())
       
   128         err = KErrArgument;
       
   129     else
       
   130     aAction = nodeContents->Des();
       
   131 	
       
   132 	delete nodeContents;
       
   133 
       
   134     OPENG_DP(D_OPENG_LIT( "     return: err" ));
       
   135     return err;
       
   136 	}
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // TPresenceActionXDM::GetSubHandlingNode()
       
   140 // ---------------------------------------------------------------------------
       
   141 //    
       
   142 CXdmDocumentNode* TPresenceActionXDM::GetSubHandlingNodeL(const TDesC& aRuleID,  
       
   143                                                                 TBool aCreate)
       
   144     {
       
   145     OPENG_DP(D_OPENG_LIT( " TPresenceActionXDM::GetSubHandlingNodeL()" ) );
       
   146     OPENG_DP(D_OPENG_LIT( "		GetSubHandlingNodeL aRuleID = %S, aCreate = %d" ),
       
   147                                                             &aRuleID,aCreate);
       
   148                                                             
       
   149     __ASSERT_ALWAYS(iPresXDM, User::Leave(KErrNotReady));
       
   150     
       
   151     CXdmDocumentNode* actionNode = iPresXDM->GetRuleChildNodeL(aRuleID, 
       
   152                                                         KXdmActions, aCreate);
       
   153     if ( (!aCreate) && (actionNode==NULL))
       
   154         return NULL;
       
   155 
       
   156     RPointerArray<CXdmDocumentNode> nodes;
       
   157     CXdmDocumentNode* subHandling(NULL);
       
   158 
       
   159     // Finding subhandling node
       
   160 	actionNode->Find(KXdmSubHandling, nodes);
       
   161 	OPENG_DP(D_OPENG_LIT( "		GetSubHandlingNodeL nodesCount = %d" ),nodes.Count());
       
   162 	if(nodes.Count()) // if action node exist
       
   163 	    {
       
   164 	    subHandling = nodes[0]; // only one sub-handling node can exist
       
   165 	    }
       
   166 	else if (aCreate) // if asked to create
       
   167 	    {
       
   168 	    subHandling = actionNode->CreateChileNodeL(KXdmSubHandling);
       
   169 	    }
       
   170 
       
   171     nodes.Close();        
       
   172     return subHandling;   
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // TPresenceActionXDM::IsValidAction()
       
   177 // ---------------------------------------------------------------------------
       
   178 //    
       
   179 TBool TPresenceActionXDM::IsValidAction(const TDesC& aAction)
       
   180     {
       
   181     OPENG_DP(D_OPENG_LIT( " TPresenceActionXDM::IsValidAction()" ) );
       
   182     if((aAction==KPresBlock)||(aAction==KPresConfirm)||(aAction==KPresPoliteBlock)||(aAction==KPresAllow))
       
   183         return ETrue;
       
   184     return EFalse;
       
   185     }
       
   186     
       
   187 // end of file
       
   188