videofeeds/viewmessageutility/src/vcxviewmessageutility.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:    Message sending component for MPX views.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include "IptvDebug.h"
       
    21 
       
    22 #include "vcxviewmessageutility.h"
       
    23 #include "vcxviewmessageutility.hrh"
       
    24 
       
    25 // Each CCoeStatic object must have a unique TUid, let's use dll uid
       
    26 const TUid KVcxViewMessageUtilitySingletonUid = { KVcxViewMessageUtilityDllUid };
       
    27 
       
    28 // Negative priority destroys this singleton after AppUi is destroyed.
       
    29 // This way all views can remove observers before this object is destroyed.
       
    30 const TInt KVcxSingletonDestructionPriority( -1 );
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Static function that initializes the singleton object
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CVcxViewMessageUtility* CVcxViewMessageUtility::InstanceL()
       
    37     {
       
    38     IPTVLOGSTRING_LOW_LEVEL("CVcxViewMessageUtility::InstanceL"); 
       
    39     // Ownership of the object remains with CCoeEnv
       
    40     CVcxViewMessageUtility* instance = static_cast<CVcxViewMessageUtility*>( 
       
    41         CCoeEnv::Static( KVcxViewMessageUtilitySingletonUid ) );
       
    42     
       
    43     if ( !instance )
       
    44         {
       
    45         IPTVLOGSTRING_LOW_LEVEL("CVcxViewMessageUtility::InstanceL - Creating object"); 
       
    46         instance = new( ELeave ) CVcxViewMessageUtility();
       
    47         }
       
    48     return instance;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Destructor
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CVcxViewMessageUtility::~CVcxViewMessageUtility()
       
    56     {
       
    57     IPTVLOGSTRING_LOW_LEVEL("CVcxViewMessageUtility destructor"); 
       
    58     iObservers.Close();
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CVcxViewMessageUtility::CVcxViewMessageUtility() :
       
    66         CCoeStatic( KVcxViewMessageUtilitySingletonUid, 
       
    67                     KVcxSingletonDestructionPriority )
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // Adds observer
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C void CVcxViewMessageUtility::AddObserverL( MVcxViewMessageObserver& aObserver )
       
    76     {
       
    77     IPTVLOGSTRING2_LOW_LEVEL("CVcxViewMessageUtility::AddObserverL - Adding %X", &aObserver); 
       
    78     TInt errorCode = KErrNoMemory;
       
    79     MtvObserverUtils::AddObserverL(iObservers, aObserver, errorCode);
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // Removes observer
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C void CVcxViewMessageUtility::RemoveObserver( MVcxViewMessageObserver& aObserver )
       
    87     {
       
    88     MtvObserverUtils::RemoveObserver(iObservers, aObserver );       
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // Forwards messages to views
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CVcxViewMessageUtility::SendCustomViewMessageL( 
       
    96         const TUid aMessageUid, const TDesC8 &aCustomMessage )
       
    97     {
       
    98     IPTVLOGSTRING2_LOW_LEVEL("CVcxViewMessageUtility::SendCustomViewMessageL Uid=%d", aMessageUid.iUid); 
       
    99     // Send the same message to all observers.
       
   100     TInt err( KErrNone );
       
   101     RUN_NOTIFY_LOOP_L( HandleCustomViewMessageL( aMessageUid, aCustomMessage ), iObservers, err );
       
   102     User::LeaveIfError( err );
       
   103     }
       
   104