internetradio2.0/actionhandlersrc/iractionhandler.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2008-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include <e32property.h>
       
    21 #include <e32std.h>
       
    22 #include <w32std.h>
       
    23 #include <implementationproxy.h>
       
    24 #include <liwvariant.h>
       
    25 #include "irdebug.h"
       
    26 #include <apgtask.h>
       
    27 #include <apgcli.h>
       
    28 #include <apacmdln.h>
       
    29 
       
    30 
       
    31 #include "iractionhandler.h"
       
    32 #include "iractionhandler.hrh"
       
    33 #include "iractionhandlerdefs.h"
       
    34 #include "irpubsubkeys.h"
       
    35 
       
    36 _LIT8( KIRSpace, " " );
       
    37 _LIT8( KIRCommandLineActionHandler, "-a" );
       
    38 _LIT8( KIRCommandLineActionHandlerCommandStartNowPlayingView, "startnowplaying" );
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // CIRActionHandler::NewL
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44 CIRActionHandler* CIRActionHandler::NewL()
       
    45     {
       
    46     CIRActionHandler* self = new ( ELeave ) CIRActionHandler(); 
       
    47     CleanupStack::PushL( self );
       
    48     
       
    49     self->ConstructL();
       
    50     
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CIRActionHandler::~CIRActionHandler
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CIRActionHandler::~CIRActionHandler()
       
    60     {
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CIRActionHandler::CIRActionHandler
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CIRActionHandler:: CIRActionHandler()
       
    68     {
       
    69     
       
    70     }
       
    71     
       
    72 // ---------------------------------------------------------
       
    73 // CIRActionHandler::ConstructL
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CIRActionHandler::ConstructL()
       
    77     {
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CIRActionHandler::ExecuteActionL
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 TInt CIRActionHandler::ExecuteActionL( const CLiwMap* aMap )
       
    85     {
       
    86     IRRDEBUG2("InternetRadio -- CIRActionHandler::ExecuteActionL Entering", KNullDesC);
       
    87 
       
    88     TInt retValue( KErrNone );
       
    89     RBuf command;
       
    90     CleanupClosePushL( command );
       
    91     
       
    92 	retValue  = ExtractStringL( aMap, command, KIRCommand);    
       
    93     
       
    94     if  (retValue== KErrNone )
       
    95         {
       
    96         if ( !command.CompareF( KIRCommandValueStop) )
       
    97             {
       
    98             Stop();
       
    99             }
       
   100         else if ( !command.CompareF( KIRCommandValuePlay ) )
       
   101             {
       
   102             Play();
       
   103             }
       
   104 
       
   105         else if ( !command.CompareF( KIRCommandValueStartNowPlaying ) )
       
   106             {
       
   107             StartToNowPlayingL();
       
   108             }
       
   109         else
       
   110             {
       
   111             retValue = KErrNotSupported;
       
   112             }
       
   113         }
       
   114     CleanupStack::PopAndDestroy( &command );
       
   115     IRRDEBUG2("InternetRadio -- CIRActionHandler::ExecuteActionL exiting", KNullDesC);
       
   116     return retValue;
       
   117     }
       
   118 
       
   119 
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CIRActionHandler::Mute
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 void CIRActionHandler::Stop()
       
   126     {
       
   127     IRRDEBUG2("CIRActionHandler::Stop entering", KNullDesC);
       
   128       
       
   129    	TInt err = RProperty::Set(KUidActiveInternetRadioApp, KIRPSControlSetPlayState, EIRStateStop );
       
   130    	
       
   131     IRRDEBUG2("CIRActionHandler::Stop exiting err =%d", err);
       
   132 	
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CIRActionHandler::Unmute
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 void CIRActionHandler::Play()
       
   140     {
       
   141     IRRDEBUG2("CIRActionHandler::Play entering", KNullDesC);
       
   142 
       
   143     TInt err = RProperty::Set(KUidActiveInternetRadioApp, KIRPSControlSetPlayState, EIRStatePlay);	
       
   144   	
       
   145     IRRDEBUG2("CIRActionHandler::Play exiting err=%d", err);
       
   146 
       
   147     }
       
   148 
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CIRActionHandler::StartToNowPlayingL
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 void CIRActionHandler::StartToNowPlayingL()
       
   156     {
       
   157     
       
   158     IRRDEBUG2("CIRActionHandler::StartToNowPlayingL entering", KNullDesC);
       
   159 
       
   160     RWsSession wsSession;
       
   161                 
       
   162     User::LeaveIfError(wsSession.Connect() );
       
   163     TApaTaskList taskList( wsSession );
       
   164 
       
   165     TApaTask irTask = taskList.FindApp(KUidActiveInternetRadioApp);
       
   166    
       
   167    
       
   168     IRRDEBUG2("CIRActionHandler::StartToNowPlayingL irTask.Exists()=%d", irTask.Exists());
       
   169 
       
   170     TPtrC8 actionHandlerCmdId( KIRCommandLineActionHandler );
       
   171     TPtrC8 spacePtr( KIRSpace );
       
   172     
       
   173     TPtrC8 startNowPlayingCmdvalue(
       
   174     KIRCommandLineActionHandlerCommandStartNowPlayingView );
       
   175 
       
   176     HBufC8* buf = HBufC8::NewLC(actionHandlerCmdId.Length()
       
   177     			 + spacePtr.Length() + startNowPlayingCmdvalue.Length());
       
   178     TPtr8 tail( buf->Des() );
       
   179        
       
   180     tail.Append( actionHandlerCmdId );
       
   181     tail.Append( spacePtr );
       
   182     tail.Append( startNowPlayingCmdvalue );
       
   183 
       
   184     if ( !irTask.Exists() )
       
   185         {
       
   186         IRRDEBUG2("CIRActionHandler::StartToNowPlayingL !irTask.Exists", KNullDesC);
       
   187 
       
   188         RApaLsSession apaSession;
       
   189         CleanupClosePushL( apaSession );
       
   190            
       
   191         User::LeaveIfError( apaSession.Connect() );
       
   192         User::LeaveIfError( apaSession.GetAllApps() );
       
   193        
       
   194         TApaAppInfo appInfo;
       
   195         User::LeaveIfError( apaSession.GetAppInfo( appInfo, KUidActiveInternetRadioApp ) );
       
   196 
       
   197       
       
   198            
       
   199         CApaCommandLine* internetRadioApplicationStartParams = CApaCommandLine::NewLC();
       
   200         internetRadioApplicationStartParams->SetExecutableNameL( appInfo.iFullName );
       
   201         // Start the application to the foreground
       
   202         internetRadioApplicationStartParams->SetCommandL( EApaCommandRun );
       
   203         internetRadioApplicationStartParams->SetTailEndL( tail );
       
   204        
       
   205         User::LeaveIfError( apaSession.StartApp( *internetRadioApplicationStartParams ) );
       
   206     
       
   207         IRRDEBUG2("CIRActionHandler::StartToNowPlayingL StartApp", KNullDesC);
       
   208 
       
   209         CleanupStack::PopAndDestroy( internetRadioApplicationStartParams );
       
   210         CleanupStack::PopAndDestroy( &apaSession );
       
   211         }
       
   212     else
       
   213         {
       
   214         IRRDEBUG2("CIRActionHandler::StartToNowPlayingL SendMessage", KNullDesC);
       
   215 
       
   216         User::LeaveIfError( irTask.SendMessage( KUidActiveInternetRadioApp , tail ) );
       
   217 
       
   218         }
       
   219     CleanupStack::PopAndDestroy( buf );
       
   220     wsSession.Close();
       
   221 
       
   222     IRRDEBUG2("InternetRadio -- CIRActionHandler::StartToNowPlayingL exiting", KNullDesC);
       
   223 
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CIRActionHandler::ExtractStringLC
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 TInt CIRActionHandler::ExtractStringL( const CLiwMap* aMap, RBuf& aString,
       
   231 										 const TDesC8& aMapName)
       
   232     {
       
   233     IRRDEBUG2("InternetRadio -- CIRActionHandler::ExtractStringL entering", KNullDesC);
       
   234 
       
   235     TInt err( KErrNotFound );
       
   236     TLiwVariant variant;
       
   237     variant.PushL();
       
   238     TPtrC tempString( KNullDesC );    
       
   239     if ( aMap->FindL( aMapName, variant ) )
       
   240         {
       
   241         variant.Get( tempString );
       
   242         aString.Close();
       
   243         aString.CreateL( tempString );
       
   244         err = KErrNone;
       
   245         }
       
   246     CleanupStack::PopAndDestroy( &variant );    
       
   247     IRRDEBUG2("InternetRadio -- CIRActionHandler::ExtractStringL exiting", KNullDesC);
       
   248    
       
   249     return err;
       
   250 
       
   251     }
       
   252 
       
   253 /** Provides a key-value pair table, that is used to identify the correct construction function for the requested interface. */
       
   254 const TImplementationProxy KIRActionHandlerImplementationTable[] =
       
   255     {
       
   256     /*lint -save -e611 (Warning -- Suspicious cast)*/
       
   257     IMPLEMENTATION_PROXY_ENTRY( KIRActionHandlerImplementationUid, CIRActionHandler::NewL )
       
   258     /*lint -restore*/
       
   259     };
       
   260 
       
   261 const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount );
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // Returns the implementations provided by this ECOM plugin DLL.
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   268     {
       
   269     IRRDEBUG2("InternetRadio -- CIRActionHandler::ImplementationGroupProxy", KNullDesC);
       
   270 
       
   271     aTableCount = sizeof( KIRActionHandlerImplementationTable ) / sizeof( TImplementationProxy );
       
   272     return KIRActionHandlerImplementationTable;
       
   273     }