tactilefeedback/tactilefeedbackclient/src/touchfeedbackadaptation.cpp
changeset 0 d54f32e146dd
equal deleted inserted replaced
-1:000000000000 0:d54f32e146dd
       
     1 /*
       
     2 * Copyright (c) 2007 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:  This class is an adaptation class that is instantiated
       
    15 *                by the application framework, and that instantiates the
       
    16 *                actual Tactile Feedback Client implementation.
       
    17 * Part of:      Tactile Feedback.
       
    18 *
       
    19 */
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <eikenv.h>
       
    23 #include <coecntrl.h>
       
    24 
       
    25 #include <tactilefeedbacktrace.h>
       
    26 #include <touchfeedbackadaptation.h>
       
    27 
       
    28 #include "touchfeedbackclient.h"
       
    29 #include "touchfeedbackimpl.h"
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Constructor.
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CTouchFeedbackAdaptation::CTouchFeedbackAdaptation()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // 2nd phase constructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void CTouchFeedbackAdaptation::ConstructL()
       
    46     {
       
    47     TRACE("CTouchFeedbackAdaptation::ConstructL - Begin");
       
    48 
       
    49     iTouchFeedback = CTouchFeedbackImpl::New();    
       
    50 
       
    51     TRACE("CTouchFeedbackAdaptation::ConstructL - End");
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // We store ourselves to the thread local storage here. The instance is 
       
    57 // accessible to clients via Instance -function.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CTouchFeedbackAdaptation* CTouchFeedbackAdaptation::NewL()
       
    61     {
       
    62     CTouchFeedbackAdaptation* self = new( ELeave ) CTouchFeedbackAdaptation;
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65 
       
    66     // Store ourselves to thread local storage
       
    67     User::LeaveIfError( Dll::SetTls( self ) );        
       
    68 
       
    69     CleanupStack::Pop( self );    
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Destructor.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CTouchFeedbackAdaptation::~CTouchFeedbackAdaptation()
       
    78     {
       
    79     delete iTouchFeedback;
       
    80     Dll::SetTls( NULL );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Retrieve instance from thread local storage
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 MTouchFeedback* CTouchFeedbackAdaptation::GetInstance()
       
    88     {
       
    89     TAny* selfPtr = Dll::Tls();
       
    90 
       
    91     CTouchFeedbackAdaptation* self = 
       
    92         static_cast<CTouchFeedbackAdaptation*>( selfPtr );
       
    93     
       
    94     if ( self )
       
    95         {
       
    96         return self->iTouchFeedback;
       
    97         }
       
    98     else
       
    99         {
       
   100         return NULL;
       
   101         }
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Create new instance and return it to caller
       
   106 //
       
   107 // We must have check for the case where client calls this even though
       
   108 // instance exists already (in this case we only return the existing 
       
   109 // instance).
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 MTouchFeedback* CTouchFeedbackAdaptation::CreateInstanceL()
       
   113     {   
       
   114     // Use current instance if it exists
       
   115     MTouchFeedback* feedback = GetInstance();
       
   116 
       
   117     // If current instance does not exist, then create a new one
       
   118     if ( !feedback )
       
   119         {
       
   120         CTouchFeedbackAdaptation* tmp = NewL();
       
   121         
       
   122         feedback = tmp->GetInstance();
       
   123         }
       
   124         
       
   125     return feedback;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Destroy ourselves if we are found at thread local storage (tls)
       
   130 //
       
   131 // Notice that tls content does not need to be zeroed because that is already
       
   132 // done in the destructor.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CTouchFeedbackAdaptation::DestroyInstance()
       
   136     {
       
   137     TAny* selfPtr = Dll::Tls();
       
   138 
       
   139     CTouchFeedbackAdaptation* self = 
       
   140         static_cast<CTouchFeedbackAdaptation*>( selfPtr );
       
   141     
       
   142     if ( self )
       
   143         {
       
   144         delete self;
       
   145         }        
       
   146     }    
       
   147     
       
   148 // ---------------------------------------------------------------------------
       
   149 // Empty implementation, as this function is no longer in use.
       
   150 // (Control visibility changes now handled in HandleControlStateChange)
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CTouchFeedbackAdaptation::ControlVisibilityChanged( 
       
   154     const CCoeControl* /*aControl*/ )
       
   155     {
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Nothing to do here, just pass the information to implementation.
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C void CTouchFeedbackAdaptation::LayoutChanged( )
       
   163     {
       
   164     if ( iTouchFeedback )
       
   165         {
       
   166         iTouchFeedback->LayoutChanged();
       
   167         }
       
   168     }
       
   169     
       
   170 // ---------------------------------------------------------------------------
       
   171 // From class MObjectProvider.
       
   172 // We have to implement this because it is pure virtual in base class.
       
   173 // Return Null as we are not actually part of object provider hierarchy.
       
   174 // ---------------------------------------------------------------------------
       
   175 TTypeUid::Ptr CTouchFeedbackAdaptation::MopSupplyObject( TTypeUid /*aId*/ )
       
   176     {
       
   177     return TTypeUid::Null();
       
   178     }
       
   179         
       
   180 // ---------------------------------------------------------------------------
       
   181 // From class MCoeControlStateObserver.
       
   182 // Here we just pass the information about control state change ahead to
       
   183 // actual feedback implementation.
       
   184 // ---------------------------------------------------------------------------
       
   185 TInt CTouchFeedbackAdaptation::HandleControlStateChange( 
       
   186     CCoeControl* aControl,
       
   187     TCoeState /*aState*/ )
       
   188     {
       
   189     if ( iTouchFeedback )
       
   190         {
       
   191         iTouchFeedback->ControlVisibilityChanged( aControl );
       
   192         }
       
   193         
       
   194     return KErrNone;
       
   195     }
       
   196     
       
   197 
       
   198