contextframework/cfwplugins/displaysourceplugin/src/displayservicelight.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2009-2009 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:   CDisplayServiceLight class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <cfcontextobject.h>
       
    21 #include <cfcontextinterface.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "displayservicelight.h"
       
    25 #include "displaysourcecontextdef.h"
       
    26 #include "trace.h"
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // C++ constructor.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CDisplayServiceLight::CDisplayServiceLight( MCFContextInterface& aCF ):
       
    35     CDisplayServiceBase( CDisplayServiceBase::EDisplayLightStatus, aCF )
       
    36     {
       
    37     FUNC_LOG;
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Symbian 2nd phase constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CDisplayServiceLight::ConstructL()
       
    45     {
       
    46     FUNC_LOG;
       
    47 
       
    48     // Call base class
       
    49     CDisplayServiceBase::ConstructL();
       
    50     
       
    51     // Initialize context object
       
    52     iContext->SetSourceL( KDisplaySource );
       
    53     iContext->SetTypeL( KDisplayStatusType );
       
    54     
       
    55     // Define context:
       
    56     // Device: Display.Status.Light
       
    57     TInt err = iCF.DefineContext(
       
    58         KDisplaySource, KDisplayStatusType, KDisplayStatusTypeSec );
       
    59     User::LeaveIfError( err );
       
    60     
       
    61     // Initialize light client
       
    62     iLight = CHWRMLight::NewL( this );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Symbian two phased constructor.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CDisplayServiceLight* CDisplayServiceLight::NewL( MCFContextInterface& aCF )
       
    70     {
       
    71     FUNC_LOG;
       
    72 
       
    73     CDisplayServiceLight* self = CDisplayServiceLight::NewLC( aCF );
       
    74     CleanupStack::Pop( self );
       
    75     
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Symbian two phased constructor.
       
    81 // Leaves pointer in the cleanup stack.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CDisplayServiceLight* CDisplayServiceLight::NewLC( MCFContextInterface& aCF )
       
    85     {
       
    86     FUNC_LOG;
       
    87 
       
    88     CDisplayServiceLight* self = new ( ELeave ) CDisplayServiceLight( aCF );
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91     
       
    92     return self;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // C++ destructor.
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CDisplayServiceLight::~CDisplayServiceLight()
       
   100     {
       
   101     FUNC_LOG;
       
   102     
       
   103     delete iLight;
       
   104     }
       
   105 
       
   106 //------------------------------------------------------------------------------
       
   107 // CDisplayServiceLight::StartL
       
   108 //------------------------------------------------------------------------------
       
   109 //
       
   110 void CDisplayServiceLight::StartL()
       
   111     {
       
   112     FUNC_LOG;
       
   113 
       
   114     // Get current display light status value and publish it
       
   115     PublishContext( iLight->LightStatus( CHWRMLight::EPrimaryDisplay ) );
       
   116     }
       
   117 
       
   118 //------------------------------------------------------------------------------
       
   119 // CDisplayServiceLight::Stop
       
   120 //------------------------------------------------------------------------------
       
   121 //
       
   122 void CDisplayServiceLight::Stop()
       
   123     {
       
   124     FUNC_LOG;
       
   125     
       
   126     // Nothing to do here.
       
   127     }
       
   128 
       
   129 //----------------------------------------------------------------------------
       
   130 // CDisplayServiceLight::LightStatusChanged
       
   131 //----------------------------------------------------------------------------
       
   132 //
       
   133 void CDisplayServiceLight::LightStatusChanged(
       
   134     TInt aTarget,
       
   135     CHWRMLight::TLightStatus aStatus )
       
   136     {
       
   137     FUNC_LOG;
       
   138 
       
   139     if ( aTarget & CHWRMLight::EPrimaryDisplay )
       
   140         {
       
   141         PublishContext( aStatus );
       
   142         }
       
   143     }
       
   144 
       
   145 //------------------------------------------------------------------------------
       
   146 // CDisplayServiceLight::PublishContext
       
   147 //------------------------------------------------------------------------------
       
   148 //
       
   149 void CDisplayServiceLight::PublishContext( CHWRMLight::TLightStatus aStatus )
       
   150     {
       
   151     FUNC_LOG;
       
   152     
       
   153     INFO_1( "Primary display light status = %d", aStatus );
       
   154 
       
   155     if ( aStatus >= 0 &&
       
   156          aStatus < KDisplayStatusTypeValueCount &&
       
   157          aStatus != iCurrentStatus )
       
   158         {
       
   159         // Store new status
       
   160         iCurrentStatus = aStatus;
       
   161         
       
   162         // Publish context, ignore error values
       
   163         TRAP_IGNORE( iContext->SetValueL(
       
   164             TPtrC( KDisplayStatusTypeValues[aStatus] ) ) );
       
   165         iCF.PublishContext( *iContext, iThread );
       
   166         }
       
   167     }
       
   168 
       
   169 // End of file