radioengine/utils/stub/src/cradioaccessoryobserver_stub.cpp
changeset 57 21be958eb3ce
parent 34 bc10a61bd7d3
equal deleted inserted replaced
56:04837bf3a628 57:21be958eb3ce
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5  * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:
    14  * Description:
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include "cradioenginelogger.h"
    18 #include "cradioenginelogger.h"
    19 
    19 
    20 #include "cradioaccessoryobserver_stub.h"
    20 #include "cradioaccessoryobserver_stub.h"
    21 #include "mradioheadseteventobserver.h"
    21 #include "mradioheadseteventobserver.h"
    29 CRadioAccessoryObserver::CRadioAccessoryObserver()
    29 CRadioAccessoryObserver::CRadioAccessoryObserver()
    30     {
    30     {
    31     LOG_METHOD_AUTO;
    31     LOG_METHOD_AUTO;
    32     }
    32     }
    33 
    33 
    34 
       
    35 // ---------------------------------------------------------------------------
    34 // ---------------------------------------------------------------------------
    36 //
    35 //
    37 // ---------------------------------------------------------------------------
    36 // ---------------------------------------------------------------------------
    38 //
    37 //
    39 void CRadioAccessoryObserver::ConstructL()
    38 void CRadioAccessoryObserver::ConstructL()
    40     {
    39     {
    41     LOG_METHOD_AUTO;
    40     LOG_METHOD_AUTO;
    42     // Open chunk for test configuration/control data
    41     // Open chunk for test configuration/control data
    43     TInt err = iRadioStubManagerChunk.OpenGlobal(
    42     TInt err = iRadioStubManagerChunk.OpenGlobal(
    44             KRadioStubManagerLocalChunkName,
    43             KRadioStubManagerLocalChunkName, EFalse, // == Read | Write
    45             EFalse, // == Read | Write
    44             EOwnerThread);
    46             EOwnerThread );
    45     User::LeaveIfError(err);
    47     User::LeaveIfError( err );
    46     if (sizeof(SRadioStubManager) > iRadioStubManagerChunk.MaxSize())
    48     if ( sizeof(SRadioStubManager) > iRadioStubManagerChunk.MaxSize() )
       
    49         {
    47         {
    50         User::Leave( KErrTooBig );
    48         User::Leave(KErrTooBig);
    51         }
    49         }
    52     TUint8* basePtr = iRadioStubManagerChunk.Base();
    50     TUint8* basePtr = iRadioStubManagerChunk.Base();
    53     User::LeaveIfNull( basePtr );    
    51     User::LeaveIfNull(basePtr);
    54     iRadioStubManager = (SRadioStubManager*)basePtr;
    52     iRadioStubManager = (SRadioStubManager*) basePtr;
    55     if ( STUB.iLeaveNewL.iError )
    53     if (STUB.iLeaveNewL.iError)
    56         {
    54         {
    57         User::Leave( STUB.iLeaveNewL.iError );
    55         User::Leave(STUB.iLeaveNewL.iError);
    58         }
    56         }
    59     if ( STUB.iLeaveConstructL.iError )
    57     if (STUB.iLeaveConstructL.iError)
    60         {
    58         {
    61         User::Leave( STUB.iLeaveConstructL.iError );
    59         User::Leave(STUB.iLeaveConstructL.iError);
    62         }
    60         }
       
    61     iHeadsetObserver = CRadioPropertyObserver::NewL(*this, KStub_KRadioPSUid,
       
    62             SRadioStubManager::EStub_KRadioTestPSKeyHeadsetConnected,
       
    63             CRadioPropertyObserver::ERadioPropertyInt);
       
    64     iHeadsetObserver->ActivateL();
       
    65     STUB.iHeadsetConnected = iHeadsetObserver->ValueInt();
    63     }
    66     }
    64 
    67 
    65 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    66 //
    69 //
    67 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    68 //
    71 //
    69 CRadioAccessoryObserver* CRadioAccessoryObserver::NewL()
    72 CRadioAccessoryObserver* CRadioAccessoryObserver::NewL()
    70     {
    73     {
    71     LOG_METHOD_AUTO;
    74     LOG_METHOD_AUTO;
    72     CRadioAccessoryObserver* self = new( ELeave ) CRadioAccessoryObserver;
    75     CRadioAccessoryObserver* self = new (ELeave) CRadioAccessoryObserver;
    73     CleanupStack::PushL( self );
    76     CleanupStack::PushL(self);
    74     self->ConstructL();
    77     self->ConstructL();
    75     CleanupStack::Pop( self );
    78     CleanupStack::Pop(self);
    76     return self;
    79     return self;
    77     }
    80     }
    78 
    81 
    79 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    80 //
    83 //
    81 // ---------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------
    82 //
    85 //
    83 CRadioAccessoryObserver::~CRadioAccessoryObserver()
    86 CRadioAccessoryObserver::~CRadioAccessoryObserver()
    84     {
    87     {
    85     LOG_METHOD_AUTO;
    88     LOG_METHOD_AUTO;
       
    89     delete iHeadsetObserver;
    86     iRadioStubManagerChunk.Close();
    90     iRadioStubManagerChunk.Close();
    87     }
    91     }
    88 
    92 
    89 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    90 //
    94 //
    91 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
    92 //
    96 //
    93 TBool CRadioAccessoryObserver::IsHeadsetConnectedL() const
    97 TBool CRadioAccessoryObserver::IsHeadsetConnectedL() const
    94     {
    98     {
    95     LOG_METHOD_AUTO;
    99     LOG_METHOD_AUTO;
    96     if ( STUB.iLeaveIsHeadsetConnectedL.iError )
   100     if (STUB.iLeaveIsHeadsetConnectedL.iError)
    97         {
   101         {
    98         User::Leave( STUB.iLeaveIsHeadsetConnectedL.iError );
   102         User::Leave(STUB.iLeaveIsHeadsetConnectedL.iError);
    99         }
   103         }
   100     return STUB.iHeadsetConnected;
   104     return STUB.iHeadsetConnected;
   101     }
   105     }
   102 
       
   103 
   106 
   104 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
   105 //
   108 //
   106 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   107 //
   110 //
   108 void CRadioAccessoryObserver::SetObserver( MRadioHeadsetEventObserver* aObserver )
   111 void CRadioAccessoryObserver::SetObserver(
       
   112         MRadioHeadsetEventObserver* aObserver)
   109     {
   113     {
   110     LOG_METHOD_AUTO;
   114     LOG_METHOD_AUTO;
   111     STUB.iObserver = aObserver;
   115     STUB.iObserver = aObserver;
   112     }
   116     }
   113 
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Handling of the int property changes is done here.
       
   120 // Observer components are getting notifications in correspondence with what
       
   121 // has changed
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CRadioAccessoryObserver::HandlePropertyChangeL(const TUid& aCategory,
       
   125         const TUint aKey, const TInt aValue)
       
   126     {
       
   127     LEVEL2( LOG_METHOD_AUTO );
       
   128     if ((KStub_KRadioPSUid == aCategory)
       
   129             && (SRadioStubManager::EStub_KRadioTestPSKeyHeadsetConnected
       
   130                     == aKey))
       
   131         {
       
   132         STUB.iHeadsetConnected = aValue;
       
   133         if (STUB.iHeadsetConnected)
       
   134             {
       
   135             if ( STUB.iObserver )
       
   136                 {
       
   137                 STUB.iObserver->HeadsetConnectedCallbackL();
       
   138                 }
       
   139             }
       
   140         else
       
   141             {
       
   142             if ( STUB.iObserver )
       
   143                  {
       
   144                  STUB.iObserver->HeadsetDisconnectedCallbackL();
       
   145                  }
       
   146             }
       
   147         }
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Dummy version for WINS in order to avoid compiler warnings.
       
   152 // The real implementation of function is above.
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CRadioAccessoryObserver::HandlePropertyChangeL(
       
   156         const TUid& /*aCategory*/, const TUint /*aKey*/, const TDesC8& /*aValue*/)
       
   157     {
       
   158     LOG_METHOD_AUTO;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // Handling of the text property changes is done here.
       
   163 // Observer components are getting notifications in correspondence with what
       
   164 // has changed
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CRadioAccessoryObserver::HandlePropertyChangeL(
       
   168         const TUid& /*aCategory*/, const TUint /*aKey*/, const TDesC& /*aValue*/)
       
   169     {
       
   170     LOG_METHOD_AUTO;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // This is a callback function which is called when a P&S components returns
       
   175 // an error
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CRadioAccessoryObserver::HandlePropertyChangeErrorL(
       
   179         const TUid& DEBUGVAR(aCategory), const TUint DEBUGVAR(aKey), TInt DEBUGVAR(aError) )
       
   180     {
       
   181     LOG_METHOD_AUTO;
       
   182     LOG_FORMAT( "aCategory = %i, aKey = %i, aError = %i", aCategory, aKey, aError );
       
   183     }