mediator/src/Client/MediatorEventProviderBody.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2005 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:  An implementation class for raising Mediator Service events.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <e32base.h>
       
    21 #include    "MediatorEventProviderBody.h"
       
    22 #include    "Debug.h"
       
    23 
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 CMediatorEventProviderBody::CMediatorEventProviderBody()
       
    28     {
       
    29     }
       
    30 
       
    31 void CMediatorEventProviderBody::ConstructL()
       
    32     {
       
    33     User::LeaveIfError( iMediatorServer.Connect() );
       
    34     }
       
    35 
       
    36 CMediatorEventProviderBody* CMediatorEventProviderBody::NewL()
       
    37     {
       
    38     CMediatorEventProviderBody* self = new( ELeave ) CMediatorEventProviderBody;
       
    39     
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43 
       
    44     return self;
       
    45     }
       
    46     
       
    47 CMediatorEventProviderBody::~CMediatorEventProviderBody()
       
    48     {
       
    49     iMediatorServer.Close();
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMediatorEventProviderBody::RegisterEventL
       
    54 // Registers complete event list using Mediator Server API
       
    55 // (other items were commented in a header).
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 TInt CMediatorEventProviderBody::RegisterEvent( TUid aDomain,
       
    59                                                 TUid aCategory, 
       
    60                                                 const REventList& aEvents )
       
    61     {
       
    62     LOG(_L("[Mediator Server]\t CMediatorEventProviderBody::RegisterEvent list\n")); 
       
    63     
       
    64     return iMediatorServer.RegisterEventList( aDomain,
       
    65                                               aCategory,
       
    66                                               aEvents );                                     
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CMediatorEventProviderBody::RegisterEventL
       
    71 // Registers a single event. 
       
    72 // (other items were commented in a header).
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 TInt CMediatorEventProviderBody::RegisterEvent( TUid aDomain,
       
    76                                                 TUid aCategory,
       
    77                                                 TInt aEventId, 
       
    78                                                 TVersion aVersion,
       
    79                                                 TCapabilitySet aCaps )
       
    80     {
       
    81     LOG(_L("[Mediator Server]\t CMediatorEventProviderBody::RegisterEventL\n"));
       
    82     __UHEAP_MARK; 
       
    83     
       
    84     // Create a list to contain one event
       
    85     REventList eventList;
       
    86     TEvent newEvent;
       
    87     newEvent.iCaps      = aCaps;
       
    88     newEvent.iEventId   = aEventId;
       
    89     newEvent.iVersion   = aVersion;
       
    90     TInt error = eventList.Append( newEvent );
       
    91         
       
    92     if ( !error )
       
    93         {
       
    94         // Register event
       
    95         error = iMediatorServer.RegisterEventList( aDomain,
       
    96                                                    aCategory,
       
    97                                                    eventList );
       
    98         }
       
    99     else
       
   100         {
       
   101         ERROR_TRACE(Print(_L("[Mediator] CMediatorEventProviderBody::RegisterEvent: error=%d\n"), error ) );
       
   102         }
       
   103         
       
   104     // Clean up                                        
       
   105     eventList.Reset();
       
   106     eventList.Close();
       
   107     
       
   108     __UHEAP_MARKEND;
       
   109     return error;    
       
   110     }   
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CMediatorEventProviderBody::UnregisterEvent
       
   114 // Unregisters a list of events.
       
   115 // (other items were commented in a header).
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TInt CMediatorEventProviderBody::UnregisterEvent( TUid aDomain,
       
   119                                                        TUid aCategory,
       
   120                                                        const REventList& aEvents )
       
   121     {
       
   122     LOG(_L("[Mediator Server]\t CMediatorEventProviderBody::UnregisterEvent\n")); 
       
   123     
       
   124     // Unegister eventlist
       
   125     return iMediatorServer.UnregisterEventList( aDomain,
       
   126                                                 aCategory,
       
   127                                                 aEvents );                                         
       
   128     }
       
   129        
       
   130 // -----------------------------------------------------------------------------
       
   131 // CMediatorEventProviderBody::UnregisterEvent
       
   132 // Unregisters a single event.
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TInt CMediatorEventProviderBody::UnregisterEvent( TUid aDomain,
       
   137                                                   TUid aCategory, 
       
   138                                                   TInt aEventId )
       
   139     {
       
   140     LOG(_L("[Mediator Server]\t CMediatorEventProviderBody::UnregisterEvent\n"));
       
   141     __UHEAP_MARK;
       
   142     
       
   143     // Create a list to contain one event
       
   144     REventList eventList;
       
   145     TEvent newEvent;
       
   146     newEvent.iEventId = aEventId;
       
   147     TInt error = eventList.Append( newEvent );
       
   148         
       
   149     if ( !error )
       
   150         {
       
   151         // Unregister eventlist
       
   152         error = iMediatorServer.UnregisterEventList( aDomain,
       
   153                                                      aCategory,
       
   154                                                      eventList );
       
   155         }
       
   156     else
       
   157         {
       
   158         ERROR_TRACE(Print(_L("[Mediator] CMediatorEventProviderBody::UnregisterEvent: error=%d\n"), error ) );
       
   159         }
       
   160                 
       
   161     // Clean up                                        
       
   162     eventList.Reset();
       
   163     eventList.Close();
       
   164     
       
   165     __UHEAP_MARKEND;
       
   166     return error;
       
   167     }
       
   168        
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMediatorEventProviderBody::RaiseEvent
       
   171 // Raises event with parameter data.
       
   172 // (other items were commented in a header).
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt CMediatorEventProviderBody::RaiseEvent( TUid aDomain,
       
   176                                                   TUid aCategory, 
       
   177                                                   TInt aEventId,
       
   178                                                   TVersion aVersion,
       
   179                                                   const TDesC8& aData )
       
   180     {
       
   181     LOG(_L("[Mediator Server]\t CMediatorEventProviderBody::RaiseEvent\n")); 
       
   182     __UHEAP_MARK;
       
   183     
       
   184     TInt error = iMediatorServer.RaiseEvent( aDomain, 
       
   185                                             aCategory, 
       
   186                                             aEventId, 
       
   187                                             aVersion, 
       
   188                                             aData );
       
   189     __UHEAP_MARKEND;
       
   190     return error;
       
   191     }
       
   192 
       
   193 
       
   194 //  End of File