os/mm/devsoundextensions/globalaudiosettings/src/AudioClientsListManagerAO.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:   This file contains implementation of Audio Clients List Manager.
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
#include "AudioClientsListManagerAO.h"
sl@0
    22
#include <AudioClientsListPSKeys.h>
sl@0
    23
#include <AudioClientsListPSData.h>
sl@0
    24
#include <MAudioClientsListObserver.h>
sl@0
    25
sl@0
    26
// -----------------------------------------------------------------------------
sl@0
    27
// CAudioClientsListManagerAO::CAudioClientsListManagerAO
sl@0
    28
//
sl@0
    29
// -----------------------------------------------------------------------------
sl@0
    30
//
sl@0
    31
CAudioClientsListManagerAO::CAudioClientsListManagerAO(
sl@0
    32
                                CGlobalAudioSettings& aGlobalAudioSettings,
sl@0
    33
                                RPointerArray<MAudioClientsListObserver>& aArray, 
sl@0
    34
                                TUint32 aKey )
sl@0
    35
:CActive(CActive::EPriorityStandard),
sl@0
    36
 iGlobalAudioSettings(aGlobalAudioSettings),
sl@0
    37
 iAudioClientsListObserverArray(aArray),
sl@0
    38
 iKey(aKey)
sl@0
    39
    {
sl@0
    40
    CActiveScheduler::Add(this);
sl@0
    41
    }
sl@0
    42
sl@0
    43
// -----------------------------------------------------------------------------
sl@0
    44
// CAudioClientsListManagerAO::~CAudioClientsListManagerAO
sl@0
    45
//
sl@0
    46
// -----------------------------------------------------------------------------
sl@0
    47
//
sl@0
    48
CAudioClientsListManagerAO::~CAudioClientsListManagerAO()
sl@0
    49
    { 
sl@0
    50
    Cancel();
sl@0
    51
    iActiveAudioClients.Close();
sl@0
    52
    }
sl@0
    53
sl@0
    54
// -----------------------------------------------------------------------------
sl@0
    55
// CAudioClientsListManagerAO::NewL
sl@0
    56
//
sl@0
    57
// -----------------------------------------------------------------------------
sl@0
    58
//
sl@0
    59
CAudioClientsListManagerAO* CAudioClientsListManagerAO::NewL(
sl@0
    60
                                                CGlobalAudioSettings& aGlobalAudioSettings,
sl@0
    61
                                                RPointerArray<MAudioClientsListObserver>& aArray,
sl@0
    62
                                                TUint32 aKey )
sl@0
    63
    {
sl@0
    64
    CAudioClientsListManagerAO* self = new (ELeave) CAudioClientsListManagerAO(aGlobalAudioSettings,aArray,aKey);
sl@0
    65
    CleanupStack::PushL(self);
sl@0
    66
    self->ConstructL();
sl@0
    67
    CleanupStack::Pop(self);
sl@0
    68
    return self;
sl@0
    69
    }
sl@0
    70
sl@0
    71
// -----------------------------------------------------------------------------
sl@0
    72
// CAudioClientsListManagerAO::ConstructL
sl@0
    73
//
sl@0
    74
// -----------------------------------------------------------------------------
sl@0
    75
//
sl@0
    76
void CAudioClientsListManagerAO::ConstructL()
sl@0
    77
    {
sl@0
    78
    User::LeaveIfError( iActiveAudioClients.Attach(
sl@0
    79
                                KPSUidMMFAudioServer,
sl@0
    80
                                iKey,
sl@0
    81
                                EOwnerThread ) );
sl@0
    82
    }
sl@0
    83
sl@0
    84
// -----------------------------------------------------------------------------
sl@0
    85
// CAudioClientsListManagerAO::MonitorStart
sl@0
    86
//
sl@0
    87
// -----------------------------------------------------------------------------
sl@0
    88
//
sl@0
    89
TInt CAudioClientsListManagerAO::MonitorStart()
sl@0
    90
    {
sl@0
    91
    TInt status(KErrAlreadyExists);
sl@0
    92
    if ( !IsActive() )
sl@0
    93
        {
sl@0
    94
        SetActive();	
sl@0
    95
        iActiveAudioClients.Subscribe(iStatus);
sl@0
    96
        status = KErrNone;
sl@0
    97
        }
sl@0
    98
  
sl@0
    99
    return status;
sl@0
   100
    }
sl@0
   101
sl@0
   102
// -----------------------------------------------------------------------------
sl@0
   103
// CAudioClientsListManagerAO::MonitorStop
sl@0
   104
//
sl@0
   105
// -----------------------------------------------------------------------------
sl@0
   106
//
sl@0
   107
TInt CAudioClientsListManagerAO::MonitorStop()
sl@0
   108
    {
sl@0
   109
    TInt status(KErrNone);
sl@0
   110
    if ( IsActive() )
sl@0
   111
        {
sl@0
   112
        Cancel();
sl@0
   113
        }
sl@0
   114
    return status;
sl@0
   115
    }
sl@0
   116
sl@0
   117
// -----------------------------------------------------------------------------
sl@0
   118
// CAudioClientsListManagerAO::GetAudioClientsList
sl@0
   119
//
sl@0
   120
// -----------------------------------------------------------------------------
sl@0
   121
//
sl@0
   122
TInt CAudioClientsListManagerAO::GetAudioClientsList(
sl@0
   123
                        CGlobalAudioSettings::TAudioClientListType aType,
sl@0
   124
                        RArray<TProcessId>& aList )
sl@0
   125
    {
sl@0
   126
    TInt status(KErrNone);
sl@0
   127
    aList.Reset();
sl@0
   128
    switch ( aType )
sl@0
   129
        {
sl@0
   130
        case CGlobalAudioSettings::EActiveAudioClients:
sl@0
   131
            {
sl@0
   132
            TAudioClientList audioClientListPckg;
sl@0
   133
            status = iActiveAudioClients.Get( KPSUidMMFAudioServer,
sl@0
   134
                                              KAudioPolicyAudioClients,
sl@0
   135
                                              audioClientListPckg );
sl@0
   136
            if ( status == KErrNone )
sl@0
   137
                {
sl@0
   138
                for ( TInt index = 0; index < audioClientListPckg().iNumOfProcesses; index++ )
sl@0
   139
                    {
sl@0
   140
                    status = aList.Append((audioClientListPckg().iProcessList)[index]);
sl@0
   141
                    if ( status != KErrNone )
sl@0
   142
                        {
sl@0
   143
                        aList.Reset();
sl@0
   144
                        break;
sl@0
   145
                        }
sl@0
   146
                    }
sl@0
   147
                }
sl@0
   148
            }
sl@0
   149
            break;
sl@0
   150
            
sl@0
   151
         case CGlobalAudioSettings::EPausedAudioClients:
sl@0
   152
            {
sl@0
   153
            TAudioPolicyProcessIdList audioClientListPckg;
sl@0
   154
            status = iActiveAudioClients.Get(KPSUidMMFAudioServer,
sl@0
   155
                                             KAudioPolicyApplicationAudioStatePaused,
sl@0
   156
                                             audioClientListPckg );
sl@0
   157
            if ( status == KErrNone )
sl@0
   158
                {
sl@0
   159
                for ( TInt index = 0; index < audioClientListPckg().iNumOfProcesses; index++ )
sl@0
   160
                    {
sl@0
   161
                    status = aList.Append((audioClientListPckg().iProcessList)[index]);
sl@0
   162
                    if ( status != KErrNone )
sl@0
   163
                        {
sl@0
   164
                        aList.Reset();
sl@0
   165
                        break;
sl@0
   166
                        }
sl@0
   167
                    }
sl@0
   168
                }
sl@0
   169
            }
sl@0
   170
            break;
sl@0
   171
              
sl@0
   172
        default:
sl@0
   173
            status = KErrNotFound;
sl@0
   174
            break;
sl@0
   175
        };
sl@0
   176
    return status;
sl@0
   177
    }
sl@0
   178
sl@0
   179
// -----------------------------------------------------------------------------
sl@0
   180
// CAudioClientsListManagerAO::RunL
sl@0
   181
//
sl@0
   182
// -----------------------------------------------------------------------------
sl@0
   183
//
sl@0
   184
void CAudioClientsListManagerAO::RunL()
sl@0
   185
    {
sl@0
   186
    TInt status(iStatus.Int());
sl@0
   187
#ifdef PRINT_MESSAGE
sl@0
   188
    RDebug::Print(_L(" CAudioClientsListManagerAO::RunL:iStatus[%d]"), status);
sl@0
   189
#endif // PRINT_MESSAGE
sl@0
   190
    if ( status == KErrNone ) 
sl@0
   191
        {
sl@0
   192
        MonitorStart();
sl@0
   193
        // Go through the array and notify every observer
sl@0
   194
      	switch(iKey)
sl@0
   195
      		{ 
sl@0
   196
      		case KAudioPolicyAudioClients:
sl@0
   197
      			{      		
sl@0
   198
        		for (TInt index = 0; index < iAudioClientsListObserverArray.Count(); index++)
sl@0
   199
            		{            	                		
sl@0
   200
            		iAudioClientsListObserverArray[index]->Event( iGlobalAudioSettings,
sl@0
   201
                                    MAudioClientsListObserver::KActiveAudioClientsListChanged);        
sl@0
   202
            		}
sl@0
   203
      			}
sl@0
   204
      			break;
sl@0
   205
      	 	case KAudioPolicyApplicationAudioStatePaused:
sl@0
   206
      			{
sl@0
   207
      			for (TInt index = 0; index < iAudioClientsListObserverArray.Count(); index++)
sl@0
   208
            		{            		       		
sl@0
   209
            		iAudioClientsListObserverArray[index]->Event( iGlobalAudioSettings,
sl@0
   210
                                    MAudioClientsListObserver::KPausedAudioClientsListChanged);
sl@0
   211
            		}
sl@0
   212
      			}
sl@0
   213
      			break;
sl@0
   214
      		default:
sl@0
   215
      	  		break;	
sl@0
   216
        
sl@0
   217
        	} //end swith(iKey)
sl@0
   218
        }
sl@0
   219
    }
sl@0
   220
sl@0
   221
// -----------------------------------------------------------------------------
sl@0
   222
// CAudioClientsListManagerAO::DoCancel
sl@0
   223
//
sl@0
   224
// -----------------------------------------------------------------------------
sl@0
   225
//
sl@0
   226
void CAudioClientsListManagerAO::DoCancel()
sl@0
   227
    {
sl@0
   228
    iActiveAudioClients.Cancel();
sl@0
   229
    }
sl@0
   230
sl@0
   231
// -----------------------------------------------------------------------------
sl@0
   232
// CAudioClientsListManagerAO::RunError
sl@0
   233
//
sl@0
   234
// -----------------------------------------------------------------------------
sl@0
   235
//
sl@0
   236
TInt CAudioClientsListManagerAO::RunError(TInt /*aError*/)
sl@0
   237
    {
sl@0
   238
    // Observer callback has leaving code!!!. Ignore it.
sl@0
   239
    return KErrNone;
sl@0
   240
    }
sl@0
   241
sl@0
   242
// End of file