tactilefeedback/tactilefeedbackresolver/src/tactilefeedbacksession.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:  Session class of Tactile Feedback server.
       
    15 * Part of:      Tactile Feedback.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <s32mem.h>
       
    20 
       
    21 // #include "tactilefeedbacktrace.h"
       
    22 #include "tactilefeedbacksrv.h"
       
    23 #include "tactilefeedbacksession.h"
       
    24 
       
    25 // --------------------------------------------------------------------------
       
    26 // CTactileFeedbackSession::CTactileFeedbackSession
       
    27 // C++ constructor.
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 CTactileFeedbackSession::CTactileFeedbackSession() 
       
    31     {
       
    32     
       
    33     }
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CTactileFeedbackSession::~CTactileFeedbackSession
       
    37 // C++ destructor.
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 CTactileFeedbackSession::~CTactileFeedbackSession()
       
    41     {
       
    42     // Stop continuous feedback, if it is started in this session. 
       
    43     if ( iFeedbackStarted )
       
    44         {
       
    45         Server().StopFeedback();
       
    46         }
       
    47     Server().RemoveSession();
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CTactileFeedbackSession::CreateL
       
    52 // From CSession2, used to increase server's session count.
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 void CTactileFeedbackSession::CreateL()
       
    56     {
       
    57     // TRACE("CTactileFeedbackSession::CreateL - Begin");
       
    58     Server().AddSession();
       
    59     // TRACE("CTactileFeedbackSession::CreateL - End");    
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CTactileFeedbackSession::Server
       
    64 // Reference to server.
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CTactileFeedbackSrv& CTactileFeedbackSession::Server()
       
    68     {   
       
    69     return *static_cast<CTactileFeedbackSrv*>
       
    70            ( const_cast<CServer2*>( CSession2::Server() ) );
       
    71     }
       
    72     
       
    73 // --------------------------------------------------------------------------
       
    74 // CTactileFeedbackSession::ServiceL
       
    75 // From CSession2, passes the request forward to DispatchMessageL.
       
    76 // --------------------------------------------------------------------------
       
    77 //
       
    78 void CTactileFeedbackSession::ServiceL( const RMessage2& aMessage )
       
    79     {
       
    80     TRAPD(err,DispatchMessageL(aMessage));
       
    81     if ( err != KErrNone )
       
    82         {
       
    83         aMessage.Complete( err );
       
    84         }    
       
    85     }
       
    86 
       
    87 // --------------------------------------------------------------------------
       
    88 // CTactileFeedbackSession::DispatchMessageL
       
    89 // Handles the request from client.
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 void CTactileFeedbackSession::DispatchMessageL( const RMessage2& aMessage )
       
    93     {
       
    94     switch( aMessage.Function() )
       
    95         {
       
    96         case EPlayFeedback:
       
    97             PlayFeedback( aMessage );
       
    98             break;
       
    99         case EStartFeedback:
       
   100             StartFeedback( aMessage );
       
   101             break;
       
   102         case EModifyFeedback:
       
   103             ModifyFeedback( aMessage );
       
   104             break;
       
   105         case EStopFeedback:            
       
   106             StopFeedback( aMessage );
       
   107             break;            
       
   108         case ESetFBEnabledDevice:            
       
   109             SetFBEnabledForDeviceL( aMessage );
       
   110             break;
       
   111         case EFBEnabledForDevice:
       
   112             FeedbackEnabledForDeviceL( aMessage );
       
   113             break;
       
   114         case  EPlayPreviewFeedback:
       
   115             PlayPreviewFeedback( aMessage );
       
   116             break;
       
   117         case  EStartPreviewFeedback:
       
   118             StartPreviewFeedback( aMessage );
       
   119             break;
       
   120         case  EModifyPreviewFeedback:
       
   121             ModifyPreviewFeedback( aMessage );
       
   122             break;
       
   123         case  EStopPreviewFeedback:
       
   124             StopPreviewFeedback( aMessage );
       
   125             break;            
       
   126         default:
       
   127             aMessage.Complete( KErrArgument );
       
   128             break;
       
   129         }
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CTactileFeedbackSession::PlayFeedbackL
       
   134 //
       
   135 // --------------------------------------------------------------------------
       
   136 //     
       
   137 void CTactileFeedbackSession::PlayFeedback( const RMessage2& aMessage )
       
   138     {
       
   139     Server().PlayFeedback( static_cast<TTouchLogicalFeedback>(aMessage.Int0()),
       
   140                            aMessage.Int1(),
       
   141                            aMessage.Int2() );
       
   142 
       
   143     aMessage.Complete( KErrNone );
       
   144     }
       
   145 
       
   146 // --------------------------------------------------------------------------
       
   147 // CTactileFeedbackSession::StartFeedbackL
       
   148 //
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 void CTactileFeedbackSession::StartFeedback( const RMessage2& aMessage )
       
   152     {
       
   153     // TRACE("CTactileFeedbackSession::StartFeedbackL - Begin");
       
   154     Server().StartFeedback( 
       
   155                      static_cast<TTouchContinuousFeedback>( aMessage.Int0() ),
       
   156                      aMessage.Int1() );
       
   157     iFeedbackStarted = ETrue;
       
   158     aMessage.Complete( KErrNone );
       
   159     // TRACE("CTactileFeedbackSession::StartFeedbackL - End");
       
   160     }
       
   161     
       
   162 // --------------------------------------------------------------------------
       
   163 // CTactileFeedbackSession::ModifyFeedbackL
       
   164 //
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 void CTactileFeedbackSession::ModifyFeedback( const RMessage2& aMessage )
       
   168     {
       
   169     // TRACE("CTactileFeedbackSession::ModifyFeedbackL - Begin");
       
   170     Server().ModifyFeedback( aMessage.Int0() );
       
   171     aMessage.Complete( KErrNone );
       
   172     // TRACE("CTactileFeedbackSession::ModifyFeedbackL - End");
       
   173     }
       
   174     
       
   175 // --------------------------------------------------------------------------
       
   176 // CTactileFeedbackSession::StopFeedbackL
       
   177 //
       
   178 // --------------------------------------------------------------------------
       
   179 //
       
   180 void CTactileFeedbackSession::StopFeedback( const RMessage2& aMessage )
       
   181     {
       
   182     // TRACE("CTactileFeedbackSession::StopFeedbackL - Begin");
       
   183     Server().StopFeedback();
       
   184     iFeedbackStarted = EFalse;
       
   185     aMessage.Complete( KErrNone );
       
   186     // TRACE("CTactileFeedbackSession::StopFeedbackL - End");
       
   187     }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CTactileFeedbackSession::SetFBEnabledForDeviceL
       
   191 //
       
   192 // --------------------------------------------------------------------------
       
   193 //
       
   194 void CTactileFeedbackSession::SetFBEnabledForDeviceL( const RMessage2& aMessage )
       
   195     {
       
   196     if ( aMessage.HasCapability( ECapabilityWriteDeviceData ) )
       
   197         {
       
   198         Server().EnableFeedbackForDevice( 
       
   199                         static_cast<TTouchFeedbackType>( aMessage.Int0() )  );
       
   200         aMessage.Complete( KErrNone );
       
   201         }
       
   202     else
       
   203         {
       
   204         User::Leave( KErrPermissionDenied );
       
   205         }
       
   206     }
       
   207 
       
   208 // --------------------------------------------------------------------------
       
   209 // CTactileFeedbackSession::FeedbackEnabledForDeviceL
       
   210 //
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 void CTactileFeedbackSession::FeedbackEnabledForDeviceL( const RMessage2& aMessage )
       
   214     {
       
   215     TTouchFeedbackType feedbackEnabled = Server().FeedbackEnabledForDevice();
       
   216     
       
   217     TPckg<TTouchFeedbackType> enabled(feedbackEnabled);
       
   218     
       
   219     aMessage.WriteL( 0, enabled );
       
   220     aMessage.Complete( KErrNone );
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 // CTactileFeedbackSession::PlayPreviewFeedbackL
       
   225 //
       
   226 // --------------------------------------------------------------------------
       
   227 //
       
   228 void CTactileFeedbackSession::PlayPreviewFeedback( const RMessage2& aMessage )
       
   229     {
       
   230     Server().PlayPreviewFeedback( aMessage.Int0(),
       
   231                          static_cast<TTouchLogicalFeedback>(aMessage.Int1() ),
       
   232                          static_cast<TTouchFeedbackType>(aMessage.Int2() ) );
       
   233     aMessage.Complete( KErrNone );    
       
   234     
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CTactileFeedbackSession::StartPreviewFeedbackL
       
   239 //
       
   240 // --------------------------------------------------------------------------
       
   241 //
       
   242 void CTactileFeedbackSession::StartPreviewFeedback( const RMessage2& aMessage )
       
   243     {
       
   244     Server().StartPreviewFeedback( 
       
   245                      aMessage.Int0(),
       
   246                      static_cast<TTouchContinuousFeedback>( aMessage.Int1() ),
       
   247                      aMessage.Int2(),
       
   248                      static_cast<TTouchFeedbackType>( aMessage.Int3() ) );
       
   249     iFeedbackStarted = ETrue;                                   
       
   250     aMessage.Complete( KErrNone );    
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // CTactileFeedbackSession::ModifyPreviewFeedbackL
       
   255 //
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 void CTactileFeedbackSession::ModifyPreviewFeedback( const RMessage2& aMessage )
       
   259     {
       
   260     // Normal ModifyFeedback function is used also for preview.
       
   261     Server().ModifyFeedback( aMessage.Int0() );
       
   262     aMessage.Complete( KErrNone );    
       
   263     }
       
   264 
       
   265 // --------------------------------------------------------------------------
       
   266 // CTactileFeedbackSession::StopPreviewFeedbackL
       
   267 //
       
   268 // --------------------------------------------------------------------------
       
   269 //
       
   270 void CTactileFeedbackSession::StopPreviewFeedback( const RMessage2& aMessage )
       
   271     {
       
   272     Server().StopPreviewFeedback();
       
   273     iFeedbackStarted = EFalse;
       
   274     aMessage.Complete( KErrNone );    
       
   275     }
       
   276     
       
   277 // End of file