tracesrv/tracecore/btrace_handler/inc/TraceCoreRouter.h
changeset 56 aa2539c91954
equal deleted inserted replaced
54:a151135b0cf9 56:aa2539c91954
       
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Router receives subscriptions and delegates messages to them
       
    15 //
       
    16 
       
    17 #ifndef __TRACECOREROUTER_H__
       
    18 #define __TRACECOREROUTER_H__
       
    19 
       
    20 
       
    21 // Include files
       
    22 #include <kernel/kernel.h>
       
    23 #include "TraceCoreMessageReceiver.h"
       
    24 
       
    25 
       
    26 // Forward declarations
       
    27 class DTraceCoreSendReceive;
       
    28 class DTraceCoreSubscriber;
       
    29 class MTraceCoreMessageSender;
       
    30 
       
    31 /**
       
    32  * Routing item
       
    33  */
       
    34 NONSHARABLE_CLASS( TRoutingItem )
       
    35     {
       
    36 public:
       
    37 
       
    38     /**
       
    39      * Message ID
       
    40      * Higest bit (MSB) is set when subscribed OST Protocol Id
       
    41      */
       
    42     TUint32 iMessageID;
       
    43     
       
    44     /**
       
    45      * The subscriber associated with the message ID
       
    46      */
       
    47     DTraceCoreSubscriber* iSubscriber;
       
    48     
       
    49     /**
       
    50      * Header format (TMessageHeaderFormat)
       
    51      */
       
    52     TUint32 iMsgFormat;
       
    53     
       
    54     };
       
    55 
       
    56 
       
    57 /**
       
    58  * Router receives subscriptions and delegates messages to them
       
    59  */
       
    60 NONSHARABLE_CLASS( DTraceCoreRouter ) : public DBase, public MTraceCoreMessageReceiver
       
    61     {
       
    62 public:
       
    63 
       
    64     /**
       
    65      * Constructor
       
    66      */
       
    67     DTraceCoreRouter();
       
    68     
       
    69     /**
       
    70      * Destructor
       
    71      */
       
    72     ~DTraceCoreRouter();
       
    73     
       
    74     /**
       
    75      * Initializes this router
       
    76      *
       
    77      * @param aSender Interface to send messages
       
    78      */
       
    79     TInt Init( MTraceCoreMessageSender& aSender );
       
    80     
       
    81     /**
       
    82      * Subscribes to a message
       
    83      *
       
    84      * @param aItem The properties of the subscription
       
    85      */
       
    86 	TInt Subscribe( TRoutingItem& aItem );
       
    87 	
       
    88 	/**
       
    89 	 * Unsubscribes from a message
       
    90 	 *
       
    91 	 * @param aItem The message to be unregistered
       
    92 	 */
       
    93 	void Unsubscribe( TRoutingItem& aItem );
       
    94 	
       
    95 	/**
       
    96 	 * Unsubscribes all messages of given subscriber
       
    97 	 *
       
    98 	 * @param aSubscriber The subscriber to be unregistered
       
    99 	 */
       
   100 	void Unsubscribe( DTraceCoreSubscriber& aSubscriber );
       
   101 	
       
   102 	/**
       
   103 	 * Callback when message is received
       
   104      * 
       
   105      * @param aMsg The message that was received
       
   106      * @return KErrNotFound if the message id was not found (not subscribed), KErrNone if found
       
   107 	 */
       
   108     TInt MessageReceived( TTraceMessage &aMsg );
       
   109 
       
   110 private:
       
   111 
       
   112     /**
       
   113      * Active subscriptions
       
   114      */
       
   115 	RArray< TRoutingItem > iRoutingItems;
       
   116 
       
   117     /**
       
   118      * Sender abstracts the messaging interface. 
       
   119      * The pointer is passed to subscribers during call to Subscribe
       
   120      */
       
   121     MTraceCoreMessageSender* iMessageSender;
       
   122     
       
   123     /**
       
   124      * Lock to protect internal structurees.
       
   125      */
       
   126     DMutex* iLock;
       
   127     };
       
   128 
       
   129 #endif
       
   130 
       
   131 // End of File