telutils/telephonyservice/src/cmediatorservice.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2007-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:  This class is responsible for communication towards Mediator.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <MediatorCommandInitiator.h>
       
    19 #include <MediatorDomainUIDs.h>
       
    20 #include <callinformation.h>            //Call Information Mediator API
       
    21 #include <callremotepartyinformation.h> //Call Remote Party Information Mediator API
       
    22 
       
    23 #include "cmediatorservice.h"
       
    24 #include "telsrvlogger.h"
       
    25 
       
    26 
       
    27 
       
    28 CMediatorService::CMediatorService( TServiceCategory aService )
       
    29     : iServiceCategory( aService )
       
    30     {
       
    31     // No implementation required
       
    32     }
       
    33 
       
    34 CMediatorService::~CMediatorService()
       
    35     {
       
    36     
       
    37     if (iMediatorEvent)
       
    38             {
       
    39             iMediatorEvent->UnsubscribeEvent( iDomain,
       
    40                                               iCategory, 
       
    41                                               iEventId );
       
    42             }
       
    43         
       
    44     delete iMediatorEvent;    
       
    45     delete iCommandInitiator;
       
    46     }
       
    47 
       
    48 CMediatorService* CMediatorService::NewLC( TServiceCategory aService )    
       
    49     {
       
    50     CMediatorService* self = new (ELeave) CMediatorService( aService );
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 CMediatorService* CMediatorService::NewL( TServiceCategory aService )
       
    57     {
       
    58     CMediatorService* self = CMediatorService::NewLC( aService );
       
    59     CleanupStack::Pop(self); 
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Sets the observer.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CMediatorService::SetObserver( MMediatorServiceObserver* aObserver )
       
    68     {
       
    69     iObserver = aObserver;
       
    70     }
       
    71 
       
    72 
       
    73 void CMediatorService::ConstructL()
       
    74     {
       
    75     iCommandInitiator = CMediatorCommandInitiator::NewL( this );
       
    76     iMediatorEvent = CMediatorEventConsumer::NewL( this ); 
       
    77     SetMediatorParams();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Sends a Mediator Service command.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 TInt CMediatorService::SendCommand()
       
    85     {    
       
    86     TInt error = iCommandInitiator->IssueCommand(
       
    87                 iDomain, 
       
    88                 iCategory, 
       
    89                 iCommandId, 
       
    90                 iVersion,
       
    91                 KNullDesC8 );
       
    92     
       
    93     return error;        
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Subscribes to Mediator event.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 TInt CMediatorService::SubscribeEvent()
       
   101     {
       
   102     TInt error = iMediatorEvent->SubscribeEvent( iDomain,
       
   103                                                  iCategory, 
       
   104                                                  iEventId, 
       
   105                                                  iVersion );
       
   106     return error;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // From class MMediatorCommandResponseObserver.
       
   111 // A response to a Mediator Service command.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CMediatorService::CommandResponseL( TUid /*aDomain*/, TUid /*aCategory*/, 
       
   115   TInt aCommandId, TInt aStatus, const TDesC8& aData )
       
   116   {
       
   117   
       
   118   if( KErrNone != aStatus )
       
   119       {      
       
   120       TSLOGSTRING2("CMediatorService::CommandResponseL; status %d", aStatus);
       
   121       return;
       
   122       }
       
   123     
       
   124   if ( iCommandId == aCommandId )
       
   125       {
       
   126       if (iObserver)
       
   127           {
       
   128           iObserver->CommandResponseL(aData);
       
   129           }
       
   130       else // observer not set
       
   131           {
       
   132           TSLOGSTRING("CMediatorService::CommandResponseL; No observer");
       
   133           }
       
   134       }
       
   135   else // command ID doesn't match
       
   136       {
       
   137       TSLOGSTRING2("CMediatorService::CommandResponseL; CommandId %d", aCommandId);
       
   138       }      
       
   139   }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // From class MMediatorEventObserver.
       
   143 // A Mediator Service event.
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CMediatorService::MediatorEventL( TUid /*aDomain*/, TUid /*aCategory*/, 
       
   147   TInt aEventId, const TDesC8& aData )
       
   148   {    
       
   149   
       
   150   if ( iEventId == aEventId )
       
   151       {
       
   152       if (iObserver)
       
   153           {
       
   154           iObserver->MediatorEventL(aData); 
       
   155           }
       
   156       else
       
   157           {
       
   158           TSLOGSTRING("CMediatorService::MediatorEventL; No observer");
       
   159           }        
       
   160       }
       
   161   else
       
   162       {
       
   163       TSLOGSTRING2("CMediatorService::MediatorEventL; EventId %d", aEventId);     
       
   164       }  
       
   165   }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // Sets the parameters used in Mediator commands and events
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CMediatorService::SetMediatorParams()
       
   172     {
       
   173     iDomain = KMediatorTelephonyDomain;
       
   174     
       
   175     switch ( iServiceCategory )
       
   176         {
       
   177         case ECallInfo:            
       
   178             iCategory = KCatCallInformation;
       
   179             iCommandId = EGetAllCallStates;
       
   180             iEventId = EChangesInCallStates;            
       
   181             iVersion.iMajor = KCallInformationVersionMajor;
       
   182             iVersion.iMinor = KCallInformationVersionMinor; 
       
   183             iVersion.iBuild = KCallInformationVersionBuild;            
       
   184             break;
       
   185         case ECallRemotePartyInfo:  
       
   186             iCategory = KCatCallRemotePartyInformation;
       
   187             iCommandId = EGetCallRemotePartyInformation;
       
   188             iEventId = EChangesInRemotePartyInformation;
       
   189             iVersion.iMajor = KCallRemotePartyInformationVersionMajor;
       
   190             iVersion.iMinor = KCallRemotePartyInformationVersionMinor; 
       
   191             iVersion.iBuild = KCallRemotePartyInformationVersionBuild;            
       
   192             break;
       
   193         default:
       
   194             TSLOGSTRING("CMediatorService::SetMediatorParams; unknown service category");
       
   195             break;
       
   196         }    
       
   197     }