contextframework/cfw/src/basicoperationsplugin/cfelseifclause.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:  CCFElseIfClause class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cfelseifclause.h"
       
    22 #include "cfscriptaction.h"
       
    23 #include "cfbasicoptrace.h"
       
    24 
       
    25 #include <gmxmlnode.h>
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT( KScriptElseIfName16,  "elseIf"    );
       
    29 _LIT( KScriptActionsName16, "actions"   );
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CCFElseIfClause::CCFElseIfClause
       
    35 // C++ default constructor can NOT contain any code, that might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CCFElseIfClause::CCFElseIfClause( MCFOperationServices& aServices,
       
    39     CCFOperationNode* aParent )
       
    40     :   CCFClauseNode( aServices, aParent )
       
    41     {
       
    42     FUNC_LOG;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCFElseIfClause::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CCFElseIfClause::ConstructL()
       
    51     {
       
    52     FUNC_LOG;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCFElseIfClause::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CCFElseIfClause* CCFElseIfClause::NewL( MCFOperationServices& aServices,
       
    61     CCFOperationNode* aParent )
       
    62     {
       
    63     FUNC_LOG;
       
    64 
       
    65     CCFElseIfClause* self = NewLC( aServices, aParent );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CCFElseIfClause::NewLC
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CCFElseIfClause* CCFElseIfClause::NewLC( MCFOperationServices& aServices,
       
    76     CCFOperationNode* aParent )
       
    77     {
       
    78     FUNC_LOG;
       
    79 
       
    80     CCFElseIfClause* self = new( ELeave ) CCFElseIfClause( aServices, aParent );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     return self;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCFElseIfClause::ParseL
       
    88 // Construction with parsing from a DOM node.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CCFElseIfClause* CCFElseIfClause::ParseL( MCFOperationServices& aServices,
       
    92     CCFOperationNode* aParent,
       
    93     CMDXMLNode& aNode )
       
    94     {
       
    95     FUNC_LOG;
       
    96 
       
    97     if ( aNode.NodeName().CompareF( KScriptElseIfName16 ) != 0 )
       
    98         {
       
    99         return NULL; // Cannot create else if clause from the given node.
       
   100         }
       
   101 
       
   102     CCFElseIfClause* self = NewLC( aServices, aParent );    // CLEANUP<< self
       
   103 
       
   104     // Parse children.
       
   105     TBool unsupportedNode( EFalse );
       
   106     TBool actionsParsed( EFalse );
       
   107     CMDXMLNode* child = aNode.FirstChild();
       
   108     while ( child )
       
   109         {
       
   110         if ( child->NodeType() == CMDXMLNode::EElementNode )
       
   111             {
       
   112             if ( child->NodeName().CompareF( KScriptActionsName16 ) == 0 )
       
   113                 {
       
   114                 if ( actionsParsed )
       
   115                     {
       
   116                     INFO( "CCFElseIfClause::ParseL - Redefinition not allowed, actions already parsed" );
       
   117                     unsupportedNode = ETrue;
       
   118                     break;
       
   119                     }
       
   120                 self->ParseActionsL( *child, self->iActions );
       
   121                 actionsParsed = ETrue;
       
   122                 }
       
   123             else
       
   124                 {
       
   125                 if ( self->iChild )
       
   126                     {
       
   127                     TPtrC nodeName( child->NodeName() );
       
   128                     INFO_1( "CCFElseIfClause::ParseL - One child operation is allowed. [%S] is not supported",
       
   129                             &nodeName );
       
   130                     unsupportedNode = ETrue; // Already parsed the child.
       
   131                     break;
       
   132                     }
       
   133                 CCFOperationNode* op = self->iServices.ParseL( self, *child );
       
   134                 if ( op )
       
   135                     {
       
   136                     self->iChild = op;
       
   137                     }
       
   138                 else
       
   139                     {
       
   140                     TPtrC nodeName( child->NodeName() );
       
   141                     INFO_1( "CCFElseIfClause::ParseL - Unsupported node [%S]",
       
   142                             &nodeName );
       
   143                     unsupportedNode = ETrue;
       
   144                     break;
       
   145                     }
       
   146                 }
       
   147             }
       
   148         else if ( child->NodeType() != CMDXMLNode::ECommentNode )
       
   149             {
       
   150             TPtrC nodeName( child->NodeName() );
       
   151             INFO_1( "CCFElseIfClause::ParseL - Unsupported node [%S]",
       
   152                     &nodeName );
       
   153             unsupportedNode = ETrue;
       
   154             break;
       
   155             }
       
   156         child = child->NextSibling();
       
   157         }
       
   158 
       
   159     CleanupStack::Pop( self );                              // CLEANUP>> self
       
   160     if ( !self->iChild || unsupportedNode )
       
   161         {
       
   162         INFO( "CCFElseIfClause::ParseL - No child operation defined or unsupported node" );
       
   163         delete self; // Discard unsupported else if clause.
       
   164         self = NULL;
       
   165         }
       
   166 
       
   167     CREATE_DOM_INFO( self, aNode );
       
   168 
       
   169     return self;
       
   170     }
       
   171 
       
   172 
       
   173 // Destructor
       
   174 CCFElseIfClause::~CCFElseIfClause()
       
   175     {
       
   176     FUNC_LOG;
       
   177 
       
   178     delete iChild;
       
   179     iActions.ResetAndDestroy();
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CCFElseIfClause::FireActionsL
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CCFElseIfClause::FireActionsL()
       
   188     {
       
   189     FUNC_LOG;
       
   190 
       
   191     ACTION_DOM_INFO( "CCFElseIfClause::FireActionsL" );
       
   192     ACTION_INFO_2( "Firing [%d] ELSE-IF-actions for script ID=[%d]",
       
   193             iActions.Count(),
       
   194             iServices.ScriptId() );
       
   195 
       
   196     for ( TInt i = 0; i < iActions.Count(); ++i )
       
   197         {
       
   198         iActions[ i ]->ActL();
       
   199         }
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CCFElseIfClause::ActivateL
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CCFElseIfClause::ActivateL()
       
   207     {
       
   208     FUNC_LOG;
       
   209 
       
   210     if ( iChild )
       
   211         {
       
   212         iChild->ActivateL();
       
   213         }
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CCFElseIfClause::Deactivate
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void CCFElseIfClause::Deactivate()
       
   221     {
       
   222     FUNC_LOG;
       
   223 
       
   224     if ( iChild )
       
   225         {
       
   226         iChild->Deactivate();
       
   227         }
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CCFElseIfClause::CheckSecurity
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 TInt CCFElseIfClause::CheckSecurity()
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     TInt err( KErrNone );
       
   239     // Check security for context subscriptions.
       
   240     if ( iChild )
       
   241         {
       
   242         err = iChild->CheckSecurity();
       
   243         if ( err != KErrNone )
       
   244             {
       
   245             ERROR( err, "CCFElseIfClause::CheckSecurity - Context read security check failed!" );
       
   246             return err;
       
   247             }
       
   248         }
       
   249 
       
   250     // Check security for actions.
       
   251     for ( TInt i = 0; i < iActions.Count(); ++i )
       
   252         {
       
   253         TSecurityPolicy securityPolicy;
       
   254         TInt err = iActions[ i ]->GetSecurityPolicy( securityPolicy );
       
   255         if ( err != KErrNone )
       
   256             {
       
   257             ERROR( err, "CCFElseIfClause::CheckSecurity - Getting action security policy failed!" );
       
   258             return err;
       
   259             }
       
   260 
       
   261         err = iServices.CheckScriptOwnerAccess( securityPolicy );
       
   262         if ( err != KErrNone )
       
   263             {
       
   264             ERROR( err, "CCFElseIfClause::CheckSecurity - Checking action security policy failed!" );
       
   265             return err;
       
   266             }
       
   267         }
       
   268 
       
   269     return KErrNone;
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CCFElseIfClause::Evaluate
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CCFElseIfClause::Evaluate()
       
   277     {
       
   278     FUNC_LOG;
       
   279 
       
   280     DOM_INFO( "CCFElseIfClause::Evaluate" );
       
   281 
       
   282     if ( iChild )
       
   283         {
       
   284         // ElseIf clause has a root condition.
       
   285         TCFConditionValue newValue = iChild->Value();
       
   286 
       
   287         if ( newValue != Value() )
       
   288             {
       
   289             INFO_1( "CCFElseIfClause::Evaluate - Value changed to (-1=undefined, 0=false, 1=true): %d", newValue );
       
   290 
       
   291             iValue = newValue;
       
   292             if ( iParent )
       
   293                 {
       
   294                 iParent->Evaluate();
       
   295                 }
       
   296             }
       
   297         else
       
   298             {
       
   299             INFO_1( "CCFElseIfClause::Evaluate - Value still (-1=undefined, 0=false, 1=true): %d", newValue );
       
   300             }
       
   301         }
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CCFElseIfClause::Cleanup
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CCFElseIfClause::Cleanup()
       
   309     {
       
   310     FUNC_LOG;
       
   311 
       
   312     if ( iChild )
       
   313         {
       
   314         iChild->Cleanup();
       
   315         }
       
   316     }