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