tactilefeedback/tactilefeedbackresolver/src/tactilefeedbacksrv.cpp
changeset 0 d54f32e146dd
equal deleted inserted replaced
-1:000000000000 0:d54f32e146dd
       
     1 /*
       
     2 * Copyright (c) 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:  Tactile feedback server implementation.
       
    15 * Part of:      Tactile Feedback.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32debug.h>
       
    20 #include <touchlogicalfeedback.h>
       
    21 
       
    22 #include "tactilefeedbacksrv.h"
       
    23 #include "tactilefeedbacksession.h"
       
    24 
       
    25 // --------------------------------------------------------------------------
       
    26 // CTactileFeedbackSrv::NewLC
       
    27 // 2-phased constructor.
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 CTactileFeedbackSrv* CTactileFeedbackSrv::NewL()
       
    31     {
       
    32     CTactileFeedbackSrv* self = new (ELeave) CTactileFeedbackSrv();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37     }
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // CTactileFeedbackSrv::CTactileFeedbackSrv()
       
    41 // C++ constructor.
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 CTactileFeedbackSrv::CTactileFeedbackSrv() 
       
    45     : CPolicyServer( EPriorityNormal, 
       
    46                      KTactileFeedbackPolicy, 
       
    47                      ESharableSessions ),
       
    48       iSessionCount(0)
       
    49     {
       
    50     // Vibra and audio feedbacks are enabled by default.
       
    51     iDeviceFeedbackEnabled |= ETouchFeedbackAudio;
       
    52     iDeviceFeedbackEnabled |= ETouchFeedbackVibra;
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CTactileFeedbackSrv::ConstructL
       
    57 // 2nd phase constructor.
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 void CTactileFeedbackSrv::ConstructL()
       
    61     {
       
    62     StartL( KTactileFeedbackServer );
       
    63     iResolver = CTactileFeedbackResolver::NewL();
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CTactileFeedbackSrv::~CTactileFeedbackSrv()
       
    68 // C++ destructor.
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CTactileFeedbackSrv::~CTactileFeedbackSrv()
       
    72     {
       
    73     delete iResolver;
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // CTactileFeedbackSrv::NewSessionL
       
    78 // from CServer2, creates a new session.
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 CSession2* CTactileFeedbackSrv::NewSessionL( const TVersion& aVersion, 
       
    82                                              const RMessage2& /*aMsg*/ ) const
       
    83     {
       
    84     TBool supported = User::QueryVersionSupported( TVersion( 
       
    85                                                 KTactileFeedbackServerMajor,
       
    86                                                 KTactileFeedbackServerMinor,
       
    87                                                 KTactileFeedbackServerBuild ),
       
    88                                                 aVersion ); 
       
    89     if ( !supported )
       
    90         {
       
    91         User::Leave( KErrNotSupported );
       
    92         }
       
    93         
       
    94     return new (ELeave) CTactileFeedbackSession();  
       
    95     }   
       
    96     
       
    97 // --------------------------------------------------------------------------
       
    98 // CTactileFeedbackSrv::AddSession
       
    99 // --------------------------------------------------------------------------
       
   100 //  
       
   101 void CTactileFeedbackSrv::AddSession()  
       
   102     {
       
   103     iSessionCount++;
       
   104     }
       
   105   
       
   106 // --------------------------------------------------------------------------
       
   107 // CTactileFeedbackSrv::RemoveSession
       
   108 // --------------------------------------------------------------------------
       
   109 //    
       
   110 void CTactileFeedbackSrv::RemoveSession()
       
   111     {
       
   112     iSessionCount--;
       
   113     if ( !iSessionCount )
       
   114         {
       
   115         CActiveScheduler::Stop();
       
   116         }
       
   117     }    
       
   118     
       
   119 // --------------------------------------------------------------------------
       
   120 // CTactileFeedbackSrv::PlayFeedback
       
   121 // --------------------------------------------------------------------------
       
   122 //    
       
   123 void CTactileFeedbackSrv::PlayFeedback( TTouchLogicalFeedback aFeedback,
       
   124                                         TBool aPlayHaptics,
       
   125                                         TBool aPlayAudio )
       
   126     {
       
   127     TBool playHaptics(EFalse);
       
   128     TBool playAudio(EFalse);    
       
   129     
       
   130     if ( (iDeviceFeedbackEnabled & ETouchFeedbackVibra) && aPlayHaptics )
       
   131         {
       
   132         playHaptics = ETrue;
       
   133         }    
       
   134     if ( (iDeviceFeedbackEnabled & ETouchFeedbackAudio) && aPlayAudio )
       
   135         {
       
   136         playAudio = ETrue;
       
   137         }
       
   138 
       
   139     if ( playHaptics || playAudio )
       
   140         {
       
   141         iResolver->PlayFeedback( aFeedback, playHaptics, playAudio );
       
   142         }        
       
   143     }        
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // CTactileFeedbackSrv::StartFeedback
       
   147 // --------------------------------------------------------------------------
       
   148 //    
       
   149 void CTactileFeedbackSrv::StartFeedback( TTouchContinuousFeedback aType,
       
   150                                          TInt aIntensity )
       
   151     {
       
   152     iResolver->StartFeedback( aType, aIntensity );    
       
   153     }
       
   154         
       
   155 // ---------------------------------------------------------------------------
       
   156 // CTactileFeedbackSrv::ModifyFeedback.
       
   157 // ---------------------------------------------------------------------------
       
   158 //                        
       
   159 void CTactileFeedbackSrv::ModifyFeedback( TInt aIntensity )
       
   160     {
       
   161     iResolver->ModifyFeedback( aIntensity );    
       
   162     }
       
   163     
       
   164 // ---------------------------------------------------------------------------
       
   165 // CTactileFeedbackSrv::StopFeedback.
       
   166 // ---------------------------------------------------------------------------
       
   167 //    
       
   168 void CTactileFeedbackSrv::StopFeedback()
       
   169     {
       
   170     iResolver->StopFeedback();   
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CTactileFeedbackSrv::EnableFeedbackForDevice
       
   175 // ---------------------------------------------------------------------------
       
   176 //    
       
   177 void CTactileFeedbackSrv::EnableFeedbackForDevice( TTouchFeedbackType aFeedbackType )
       
   178     {
       
   179     iDeviceFeedbackEnabled = aFeedbackType;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CTactileFeedbackSrv::FeedbackEnabledForDeviceL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 TTouchFeedbackType CTactileFeedbackSrv::FeedbackEnabledForDevice()
       
   187     {
       
   188     return static_cast<TTouchFeedbackType>( iDeviceFeedbackEnabled );
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CTactileFeedbackSrv::PlayPreviewFeedbackL
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CTactileFeedbackSrv::PlayPreviewFeedback( TInt aLevel,
       
   196                                               TTouchLogicalFeedback aFeedback,
       
   197                                               TTouchFeedbackType aType )
       
   198     {
       
   199     iResolver->PlayPreviewFeedback( aLevel, aFeedback, aType );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CTactileFeedbackSrv::StartPreviewFeedbackL
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CTactileFeedbackSrv::StartPreviewFeedback( TInt aLevel,
       
   207                                           TTouchContinuousFeedback aFeedback,
       
   208                                           TInt aIntensity,
       
   209                                           TTouchFeedbackType aType )
       
   210     {
       
   211     iResolver->StartPreviewFeedback( aLevel, aFeedback, aIntensity, aType );
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CTactileFeedbackSrv::StopPreviewFeedbackL
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CTactileFeedbackSrv::StopPreviewFeedback()
       
   219     {
       
   220     iResolver->StopPreviewFeedback();
       
   221     }
       
   222 
       
   223 // End of file