contextframework/cfw/src/basicoperationsplugin/cfandoperation.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Class that defines logical AND operation in an XML tree.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "cfandoperation.h"
       
    22 #include "cfbasicoptrace.h"
       
    23 
       
    24 #include <gmxmlnode.h>
       
    25 
       
    26 // CONSTANTS
       
    27 _LIT( KScriptAndName, "and" );
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCFAndOperation::CCFAndOperation
       
    33 // C++ default constructor can NOT contain any code, that might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CCFAndOperation::CCFAndOperation( MCFOperationServices& aServices,
       
    37     CCFOperationNode* aParent )
       
    38     :   CCFOperationNode( aServices, aParent )
       
    39     {
       
    40     FUNC_LOG;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CCFAndOperation::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CCFAndOperation::ConstructL()
       
    49     {
       
    50     FUNC_LOG;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CCFAndOperation::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CCFAndOperation* CCFAndOperation::NewL( MCFOperationServices& aServices,
       
    59     CCFOperationNode* aParent )
       
    60     {
       
    61     FUNC_LOG;
       
    62 
       
    63     CCFAndOperation* self = NewLC( aServices, aParent );
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CCFAndOperation::NewLC
       
    70 // Two-phased constructor that leaves object to the cleanup stack.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CCFAndOperation* CCFAndOperation::NewLC( MCFOperationServices& aServices,
       
    74     CCFOperationNode* aParent )
       
    75     {
       
    76     FUNC_LOG;
       
    77 
       
    78     CCFAndOperation* self = new( ELeave ) CCFAndOperation( aServices, aParent );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     return self;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCFAndOperation::ParseL
       
    86 // Construction with parsing from a DOM node.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CCFAndOperation* CCFAndOperation::ParseL( MCFOperationServices& aServices,
       
    90     CCFOperationNode* aParent,
       
    91     CMDXMLNode& aNode )
       
    92     {
       
    93     FUNC_LOG;
       
    94 
       
    95     if ( aNode.NodeName().CompareF( KScriptAndName ) != 0 )
       
    96         {
       
    97         return NULL; // Cannot create and operation from the given node.
       
    98         }
       
    99 
       
   100     CCFAndOperation* self = NewLC( aServices, aParent );    // CLEANUP<< self
       
   101 
       
   102     TBool unsupportedNode( EFalse );
       
   103     CMDXMLNode* child = aNode.FirstChild();
       
   104     while ( child )
       
   105         {
       
   106         if ( child->NodeType() == CMDXMLNode::EElementNode )
       
   107             {
       
   108             CCFOperationNode* op = self->iServices.ParseL( self, *child );
       
   109             if ( op )
       
   110                 {
       
   111                 self->iChildren.AppendL( op );
       
   112                 }
       
   113             else
       
   114                 {
       
   115                 unsupportedNode = ETrue;
       
   116                 break;
       
   117                 }
       
   118             }
       
   119         else if ( child->NodeType() != CMDXMLNode::ECommentNode )
       
   120             {
       
   121             unsupportedNode = ETrue;
       
   122             break;
       
   123             }
       
   124         child = child->NextSibling();
       
   125         }
       
   126 
       
   127     CleanupStack::Pop( self );                              // CLEANUP<< self
       
   128     if ( unsupportedNode || !self->iChildren.Count() )
       
   129         {
       
   130         delete self; // Discard unsupported and operation.
       
   131         self = NULL;
       
   132 
       
   133         if ( unsupportedNode )
       
   134             {
       
   135             TPtrC nodeName( child->NodeName() );
       
   136             INFO_1( "CCFAndOperation::ParseL - Unsupported node [%S]",
       
   137                     &nodeName );
       
   138             }
       
   139         else
       
   140             {
       
   141             INFO( "CCFAndOperation::ParseL - No children" );
       
   142             }
       
   143         }
       
   144 
       
   145     CREATE_DOM_INFO( self, aNode );
       
   146 
       
   147     return self;
       
   148     }
       
   149 
       
   150 
       
   151 // Destructor
       
   152 CCFAndOperation::~CCFAndOperation()
       
   153     {
       
   154     FUNC_LOG;
       
   155 
       
   156     iChildren.ResetAndDestroy();
       
   157     }
       
   158 
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CCFAndOperation::ActivateL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CCFAndOperation::ActivateL()
       
   165     {
       
   166     FUNC_LOG;
       
   167 
       
   168     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   169         {
       
   170         iChildren[ i ]->ActivateL();
       
   171         }
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CCFAndOperation::Deactivate
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CCFAndOperation::Deactivate()
       
   179     {
       
   180     FUNC_LOG;
       
   181 
       
   182     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   183         {
       
   184         iChildren[ i ]->Deactivate();
       
   185         }
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CCFAndOperation::CheckSecurity
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TInt CCFAndOperation::CheckSecurity()
       
   193     {
       
   194     FUNC_LOG;
       
   195 
       
   196     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   197         {
       
   198         TInt err = iChildren[ i ]->CheckSecurity();
       
   199         if ( err != KErrNone )
       
   200             {
       
   201             return err;
       
   202             }
       
   203         }
       
   204 
       
   205     return KErrNone;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CCFAndOperation::Evaluate
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CCFAndOperation::Evaluate()
       
   213     {
       
   214     FUNC_LOG;
       
   215 
       
   216     DOM_INFO( "CCFAndOperation::Evaluate" );
       
   217 
       
   218     // get the value of the condition
       
   219     TCFConditionValue newValue = Value();
       
   220     TBool branchUndefined = EFalse;
       
   221 
       
   222     // iterate through all the children
       
   223     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   224         {
       
   225         // get the child's value
       
   226         newValue = iChildren[ i ]->Value();
       
   227         if ( !newValue )
       
   228             {
       
   229             break;
       
   230             }
       
   231         else if ( newValue == ECFConditionUndefined )
       
   232             {
       
   233             branchUndefined = ETrue;
       
   234             }
       
   235         }
       
   236 
       
   237     if ( branchUndefined && newValue == ECFConditionTrue )
       
   238         {
       
   239         newValue = ECFConditionUndefined;
       
   240         }
       
   241 
       
   242     if ( newValue != Value() )
       
   243         {
       
   244         INFO_1( "CCFAndOperation::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", newValue );
       
   245 
       
   246         iValue = newValue;
       
   247         if ( iParent )
       
   248             {
       
   249             // Recursion here; hopefully tree not deep
       
   250             iParent->Evaluate();
       
   251             }
       
   252         }
       
   253     else
       
   254         {
       
   255         INFO_1( "CCFAndOperation::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", newValue );
       
   256         }
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CCFAndOperation::Cleanup
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CCFAndOperation::Cleanup()
       
   264     {
       
   265     FUNC_LOG;
       
   266 
       
   267     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   268         {
       
   269         iChildren[ i ]->Cleanup();
       
   270         }
       
   271     }