mmshplugins/mmshaoplugin/src/musaoplugin.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Main plugin class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musmanager.h"
       
    20 #include "musresourceproperties.h"
       
    21 #include "mussesseioninformationapi.h"
       
    22 #include "mussettingskeys.h"
       
    23 #include "mussessionproperties.h"
       
    24 #include "mussettings.inl"
       
    25 #include "musaoplugin.h"
       
    26 #include "mustsypropertymonitor.h"
       
    27 // Enable the below line if Kodiak Ptt has to be monitered
       
    28 // #include "muspttcallmonitor.h"
       
    29 #include "muspropertymonitor.h"
       
    30 #include "mustsypropertymonitor.h"
       
    31 #include "muslogger.h"
       
    32 
       
    33 #include <AlwaysOnlineManagerCommon.h>
       
    34 #include <AlwaysOnlineManagerClient.h>
       
    35 #include <mmtsy_names.h>
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // Symbian two-phase constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMusAoPlugin* CMusAoPlugin::NewL()
       
    42     {
       
    43     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::NewL" )
       
    44     CMusAoPlugin* self = new (ELeave) CMusAoPlugin();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( self );
       
    48     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::NewL" )
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // C++ constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CMusAoPlugin::CMusAoPlugin() :
       
    57     CAlwaysOnlineEComInterface()
       
    58     {     
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // Symbian second-phase constructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CMusAoPlugin::ConstructL()
       
    66     {
       
    67     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::ConstructL" )
       
    68     DefinePropertiesL();
       
    69     User::LeaveIfError( iServer.Connect() );
       
    70     User::LeaveIfError( iPhone.Open( iServer, KMmTsyPhoneName() ) );        
       
    71     iTsyPropertyMonitor = CMusTsyPropertyMonitor::NewL(iPhone, *this );    
       
    72     iPropertyMonitor = CMusPropertyMonitor::NewL(*this);    
       
    73     // Enable the below line if Kodiak Ptt has to be monitered
       
    74     // iPttCallMonitor = CMusPttCallMonitor::NewL(*iLineMonitor);    
       
    75     
       
    76     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::ConstructL" )
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // C++ destructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CMusAoPlugin::~CMusAoPlugin()
       
    84     {
       
    85     MUS_LOG( "-> CMusAoPlugin::~CMusAoPlugin" )
       
    86     // should never come here, because service should always be on
       
    87     delete iManager;
       
    88     delete iPropertyMonitor;
       
    89     delete iTsyPropertyMonitor;
       
    90     // Enable the below line if Kodiak Ptt has to be monitered
       
    91     // delete iPttCallMonitor;
       
    92     DeleteProperties();
       
    93     iPhone.Close();
       
    94     iServer.Close();
       
    95     MUS_LOG( "<- CMusAoPlugin::~CMusAoPlugin" )
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMusAoPlugin::DefineResourcePropertiesL()
       
   101 // Note : Ignore Define Errors . Because if define fails for sure Set
       
   102 //        will fail too . But there are some cases in Define Error should
       
   103 //        be ignored like KErrAlreadyExists , KErrPersmissionDenied.So It
       
   104 //        could be better if we dont care Define Error but care about Set Err.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CMusAoPlugin::DefinePropertiesL()
       
   108     {
       
   109     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::DefineResourceProperties" )
       
   110     // define resource properties
       
   111     // they need to be defined here to make them exist always
       
   112 	// Read from cenrep key about the availability of camera and keypad
       
   113 	// if the availability is dynamic then define a key else no.
       
   114 	MusSettingsKeys::TAvailability camera = MusSettingsKeys::EAvailabilityStatic;
       
   115 	MusSettingsKeys::TAvailability keypad = MusSettingsKeys::EAvailabilityStatic ;
       
   116     MultimediaSharingSettings::ResourceAvailability(camera,keypad);         
       
   117     if( camera == MusSettingsKeys::EAvailabilityDynamic )
       
   118     	{
       
   119         DefinePropertyL(NMusResourceApi::KCameraAvailability,
       
   120                         RProperty::EInt,( TInt ) NMusResourceApi::ENotAvailable);
       
   121     	}	
       
   122 	if( keypad == MusSettingsKeys::EAvailabilityDynamic )
       
   123 		{		
       
   124         DefinePropertyL(NMusResourceApi::KKeypadAvailability,
       
   125                         RProperty::EInt,( TInt ) NMusResourceApi::ENotAvailable);      	
       
   126 		}    		    
       
   127     DefinePropertyL(NMusResourceApi::KCameraInformation,
       
   128                     RProperty::EInt,( TInt ) NMusResourceApi::EUsePrimaryCamera);   
       
   129     DefinePropertyL(NMusSessionInformationApi::KMusCallEvent,
       
   130                     RProperty::EInt,( TInt ) NMusSessionInformationApi::ENoCall); 
       
   131     DefinePropertyL(NMusSessionInformationApi::KMusCallCount,RProperty::EInt,0); 
       
   132     _LIT(KEmptyTelNumber,"");
       
   133     DefinePropertyL(NMusSessionInformationApi::KMusTelNumber,
       
   134                     RProperty::EText,KEmptyTelNumber); 
       
   135     DefinePropertyL(NMusSessionInformationApi::KMUSForbidden,
       
   136                  RProperty::EInt,( TInt ) NMusSessionInformationApi::EMUSAllowed); 
       
   137     DefinePropertyL(NMusSessionInformationApi::KMusCallDirection,
       
   138                 RProperty::EInt,( TInt ) NMusSessionInformationApi::ENoDirection);  
       
   139     _LIT( KEmptyCallProvider,"" );
       
   140     DefinePropertyL(NMusSessionInformationApi::KMUSCallProvider,
       
   141                         RProperty::EText,KEmptyCallProvider);
       
   142 
       
   143     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::DefineResourceProperties" )
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CMusAoPlugin::DefineProperty()
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CMusAoPlugin::DefinePropertyL(TInt aKey,RProperty::TType aType,TInt aVal)
       
   151     {
       
   152     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::DefinePropertyL( intValue )" )
       
   153     
       
   154     TInt error = RProperty::Define( NMusResourceApi::KCategoryUid,
       
   155                                      aKey,
       
   156                                      aType );
       
   157     MUS_LOG2( "mus: [MUSAO]     Key=%d defining tried, return=%d", aKey, error )
       
   158     
       
   159     if ( error == KErrNone )
       
   160         {
       
   161         error = RProperty::Set( NMusResourceApi::KCategoryUid, aKey, aVal );
       
   162         MUS_LOG2( "mus: [MUSAO]     RProperty value %d set, return = %d",
       
   163                   aVal, error )
       
   164         User::LeaveIfError( error );
       
   165         }
       
   166     else
       
   167         {
       
   168         MUS_LOG( "mus: [MUSAO]     Defining failed, do not set value" )
       
   169         }
       
   170     
       
   171     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::DefinePropertyL( intValue )" )
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CMusAoPlugin::DefineProperty()
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CMusAoPlugin::DefinePropertyL( TInt aKey,
       
   179                                     RProperty::TType aType,
       
   180                                     const TDesC& aVal )
       
   181     {
       
   182     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::DefinePropertyL( DesCValue )" )
       
   183     
       
   184     TInt error = RProperty::Define( NMusResourceApi::KCategoryUid,
       
   185                                      aKey,
       
   186                                      aType );
       
   187     MUS_LOG2( "mus: [MUSAO]     Key=%d defining tried, return=%d", aKey, error )  
       
   188     
       
   189     if ( error == KErrNone )
       
   190         {
       
   191         error = RProperty::Set( NMusResourceApi::KCategoryUid, aKey, aVal);
       
   192         MUS_LOG_TDESC( "mus: [MUSAO]     Tried to set RProperty value: ", aVal )
       
   193         MUS_LOG1("mus: [MUSAO]     return value = %d",error )
       
   194         User::LeaveIfError( error );         
       
   195         }
       
   196     else
       
   197         {
       
   198         MUS_LOG( "mus: [MUSAO]     Defining failed, do not set value" )
       
   199         }
       
   200     
       
   201     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::DefinePropertyL( DesCValue )" )
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CMusAoPlugin::DeleteResourceProperties()
       
   206 // Note : There is no need of caring the return value in deleting
       
   207 //        This will be called when AO Plugin destroyed which is rare to happen
       
   208 //        Any unwanted deletion of AO Plugin should leave some PS Keys open.
       
   209 //        But this is OK if we ignore KErrAlreadyExists while defining next time.
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CMusAoPlugin::DeleteProperties()
       
   213     {
       
   214     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::DeleteResourcePropertiesL" )
       
   215     // Delete resource properties
       
   216     // they need to be defined here to make them exist always
       
   217     DeleteProperty(NMusResourceApi::KCameraAvailability);
       
   218     DeleteProperty(NMusResourceApi::KKeypadAvailability);    
       
   219     DeleteProperty(NMusResourceApi::KCameraInformation);
       
   220     DeleteProperty(NMusSessionInformationApi::KMusCallEvent);
       
   221     DeleteProperty(NMusSessionInformationApi::KMusCallCount);
       
   222     DeleteProperty(NMusSessionInformationApi::KMusTelNumber);
       
   223     DeleteProperty(NMusSessionInformationApi::KMUSCallProvider);
       
   224     DeleteProperty(NMusSessionInformationApi::KMUSForbidden);
       
   225     DeleteProperty(NMusSessionInformationApi::KMusCallDirection);
       
   226     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::DeleteResourcePropertiesL" )
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CMusAoPlugin::DeleteProperty()
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CMusAoPlugin::DeleteProperty(TInt aKey)
       
   234     {
       
   235     TInt retVal = RProperty::Delete( NMusResourceApi::KCategoryUid,aKey); 
       
   236     MUS_LOG2( "mus: [MUSAO]     RProperty::Delete Type=%d return=%d",\
       
   237                                                            aKey, retVal )                           
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CMusAoPlugin::HandleServerCommandL
       
   242 // CallBack from base class.
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TAny* CMusAoPlugin::HandleServerCommandL( TInt /*aCommand*/,
       
   246                                                       TDesC8* /*aParameters*/  )
       
   247     {
       
   248     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::HandleServerCommandL" )
       
   249     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::HandleServerCommandL: KErrNone" )
       
   250     return &iError;;
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CMusAoPlugin::StartMusClient()
       
   255 // This will start the MusManager Client which inturn should start
       
   256 // MusManager Server and Availability Plugin.
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CMusAoPlugin::StartMusClientL()
       
   260     {
       
   261     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::StartMusClient" )
       
   262     if( !iManager )
       
   263         {
       
   264         iManager = CMusManager::NewL();
       
   265         }
       
   266     iManager->ExamineAvailabilityL();   
       
   267     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::StartMusClient" ) 
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CMusAoPlugin::StopMusClient()
       
   272 // This will stop the MusManager Client which inturn should stop
       
   273 // MusManager Server and Availability Plugin.
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CMusAoPlugin::StopMusClient()
       
   277     {
       
   278     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::StopMusClient" )
       
   279     if( iManager )
       
   280         {
       
   281         delete iManager;
       
   282         iManager = NULL;
       
   283         }
       
   284     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::StopMusClient" )
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // From MMusCallStateObserver
       
   289 // CMusAoPlugin::MusCallStateChanged()
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CMusAoPlugin::MusCallStateChanged( )
       
   293     {
       
   294     MUS_LOG( "mus: [MUSAO]  -> CMusAoPlugin::MusCallStateChanged" )
       
   295 
       
   296     TBool dataReady = EFalse;
       
   297     TRAPD( error, dataReady = iTsyPropertyMonitor->IsDataReadyL() )
       
   298     
       
   299     if ( error == KErrNone &&
       
   300             dataReady &&
       
   301             iPropertyMonitor->IsCallConnected() )
       
   302         {
       
   303         MUS_LOG( "mus: [MUSAO]  Starting Mush Client" )
       
   304         TRAP( error, StartMusClientL() )
       
   305         
       
   306         MUS_LOG1("mus: [MUSAO]  Error Ocurred = %d",error )
       
   307         
       
   308         if ( error != KErrNone )
       
   309             {
       
   310             StopMusClient();
       
   311             }
       
   312         }
       
   313     else
       
   314         {
       
   315         MUS_LOG( "mus: [MUSAO]  Stopping Mush Client" )
       
   316         StopMusClient();
       
   317         }
       
   318     MUS_LOG( "mus: [MUSAO]  <- CMusAoPlugin::MusCallStateChanged" )
       
   319     }
       
   320 
       
   321 // End of file