memspy/Driver/Kernel/Source/SubChannels/MemSpyDriverLogChanUserEventMonitor.cpp
changeset 0 a03f92240627
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MemSpyDriverLogChanUserEventMonitor.h"
       
    19 
       
    20 // System includes
       
    21 #include <memspy/driver/memspydriverobjectsshared.h>
       
    22 
       
    23 // Shared includes
       
    24 #include "MemSpyDriverOpCodes.h"
       
    25 #include "MemSpyDriverObjectsInternal.h"
       
    26 
       
    27 // User includes
       
    28 #include "MemSpyDriverUtils.h"
       
    29 #include "MemSpyDriverUserEventMonitor.h"
       
    30 
       
    31 
       
    32 
       
    33 DMemSpyDriverLogChanUserEventMonitor::DMemSpyDriverLogChanUserEventMonitor( DMemSpyDriverDevice& aDevice, DThread& aThread )
       
    34 :   DMemSpyDriverLogChanBase( aDevice, aThread )
       
    35     {
       
    36     TRACE( Kern::Printf("DMemSpyDriverLogChanThreadAndProcess::DMemSpyDriverLogChanThreadAndProcess() - this: 0x%08x", this ));
       
    37     }
       
    38 
       
    39 
       
    40 DMemSpyDriverLogChanUserEventMonitor::~DMemSpyDriverLogChanUserEventMonitor()
       
    41 	{
       
    42 	TRACE( Kern::Printf("DMemSpyDriverLogChanThreadAndProcess::~DMemSpyDriverLogChanThreadAndProcess() - START - this: 0x%08x", this ));
       
    43 
       
    44     NKern::ThreadEnterCS();
       
    45     delete iEventMonitorManager;
       
    46     NKern::ThreadLeaveCS();
       
    47 
       
    48 	TRACE( Kern::Printf("DMemSpyDriverLogChanThreadAndProcess::~DMemSpyDriverLogChanThreadAndProcess() - END - this: 0x%08x", this ));
       
    49 	}
       
    50 
       
    51 
       
    52 TInt DMemSpyDriverLogChanUserEventMonitor::Construct()
       
    53     {
       
    54     TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::Construct() - START"));
       
    55     //
       
    56     TInt error = BaseConstruct();
       
    57     //
       
    58     if  ( error == KErrNone )
       
    59         {
       
    60         iEventMonitorManager = new DMemSpyDriverClientEMManager( MemSpyDevice() );
       
    61 
       
    62         if  ( iEventMonitorManager )
       
    63             {
       
    64             TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::DoCreate - creating event monitor" ));
       
    65 
       
    66             error = iEventMonitorManager->Create();
       
    67 
       
    68             TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::DoCreate - event monitor create error: %d", error ));
       
    69             }
       
    70         }
       
    71     //
       
    72     TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::Construct() - END - error: %d", error ));
       
    73     return error;
       
    74     }
       
    75 
       
    76 
       
    77 
       
    78 TInt DMemSpyDriverLogChanUserEventMonitor::Request( TInt aFunction, TAny* a1, TAny* a2 )
       
    79 	{
       
    80 	TInt r = DMemSpyDriverLogChanBase::Request( aFunction, a1, a2 );
       
    81     if  ( r == KErrNone )
       
    82         {
       
    83 	    switch( aFunction )
       
    84 		    {
       
    85         case EMemSpyDriverOpCodeEventMonitorOpen:
       
    86             r = EventMonitorOpen( a1 );
       
    87             break;
       
    88         case EMemSpyDriverOpCodeEventMonitorClose:
       
    89             r = EventMonitorClose( (TUint) a1 );
       
    90             break;
       
    91         case EMemSpyDriverOpCodeEventMonitorNotify:
       
    92             r = EventMonitorNotify( (TMemSpyDriverInternalEventMonitorParams*) a1 );
       
    93             break;
       
    94         case EMemSpyDriverOpCodeEventMonitorNotifyCancel:
       
    95             r = EventMonitorNotifyCancel( (TUint) a1 );
       
    96             break;
       
    97 
       
    98         default:
       
    99             r = KErrNotSupported;
       
   100 		    break;
       
   101 		    }
       
   102         }
       
   103     //
       
   104     return r;
       
   105 	}
       
   106 
       
   107 
       
   108 TBool DMemSpyDriverLogChanUserEventMonitor::IsHandler( TInt aFunction ) const
       
   109     {
       
   110     return ( aFunction > EMemSpyDriverOpCodeEventMonitorBase && aFunction < EMemSpyDriverOpCodeEventMonitorEnd );
       
   111     }
       
   112 
       
   113 
       
   114 
       
   115 
       
   116 
       
   117 
       
   118 
       
   119 
       
   120 
       
   121 
       
   122 
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131 TInt DMemSpyDriverLogChanUserEventMonitor::EventMonitorOpen( TAny* aHandle )
       
   132     {
       
   133 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorOpen() - START") );
       
   134     NKern::ThreadEnterCS();
       
   135     
       
   136     DMemSpyDriverClientEM* monitor = iEventMonitorManager->EMOpen();
       
   137     TInt error = ( monitor != NULL )? KErrNone : KErrNoMemory;
       
   138     const TUint handle = ( monitor != NULL )? monitor->Handle() : KNullHandle;
       
   139     
       
   140     // Write handle back
       
   141     const TInt writeErr = Kern::ThreadRawWrite( &ClientThread(), aHandle, &handle, sizeof(TUint) );
       
   142 	if  ( writeErr != KErrNone )
       
   143 		{
       
   144         TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorOpen() - write error: %d", writeErr ) );
       
   145         error = writeErr;
       
   146 		}
       
   147     //
       
   148     NKern::ThreadLeaveCS();
       
   149 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorOpen() - END - handle: 0x%08x, error: %d", handle, error ));
       
   150     return error;
       
   151     }
       
   152 
       
   153 
       
   154 TInt DMemSpyDriverLogChanUserEventMonitor::EventMonitorClose( TUint aHandle )
       
   155     {
       
   156 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorClose() - START - aHandle: 0x%08x", aHandle));
       
   157 
       
   158     NKern::ThreadEnterCS();
       
   159     const TInt error = iEventMonitorManager->EMClose( aHandle );
       
   160     NKern::ThreadLeaveCS();
       
   161 
       
   162 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorClose() - END - error: %d", error ));
       
   163     return error;
       
   164     }
       
   165 
       
   166 
       
   167 TInt DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotify( TMemSpyDriverInternalEventMonitorParams* aParams )
       
   168     {
       
   169 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotify() - START"));
       
   170     NKern::ThreadEnterCS();
       
   171 
       
   172     // Read client info
       
   173     TMemSpyDriverInternalEventMonitorParams params;
       
   174 	TInt error = Kern::ThreadRawRead( &ClientThread(), aParams, &params, sizeof(TMemSpyDriverInternalEventMonitorParams) );
       
   175     //
       
   176     if  ( error == KErrNone )
       
   177         {
       
   178         DMemSpyDriverClientEM* monitor = iEventMonitorManager->EMInstance( params.iHandle );
       
   179         //
       
   180         if  ( monitor != NULL )
       
   181             {
       
   182             error = monitor->NotifyChanges( &ClientThread(), params.iStatus, params.iContext );
       
   183             }
       
   184         else
       
   185             {
       
   186             error = KErrNotFound;
       
   187             }
       
   188         }
       
   189 
       
   190     // NB: Let client take care of completing request in error situations
       
   191     NKern::ThreadLeaveCS();
       
   192 
       
   193     TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotify() - END - error: %d", error ));
       
   194     return error;
       
   195     }
       
   196 
       
   197 
       
   198 TInt DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotifyCancel( TUint aHandle )
       
   199     {
       
   200 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotifyCancel() - START - aHandle: 0x%08x", aHandle));
       
   201     NKern::ThreadEnterCS();
       
   202 
       
   203     TInt error = KErrNotFound;
       
   204     DMemSpyDriverClientEM* monitor = iEventMonitorManager->EMInstance( aHandle );
       
   205     //
       
   206     if  ( monitor != NULL )
       
   207         {
       
   208         error = monitor->NotifyChangesCancel();
       
   209         }
       
   210 
       
   211     NKern::ThreadLeaveCS();
       
   212 
       
   213 	TRACE( Kern::Printf("DMemSpyDriverLogChanUserEventMonitor::EventMonitorNotifyCancel() - END - error: %d", error ));
       
   214     return error;
       
   215     }
       
   216 
       
   217 
       
   218 
       
   219