analyzetool/storageserver/client/inc/atstorageserverclnt.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 19 da2cedce4920
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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:  Declaration of the client side handle class RATStorageServer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef ATSTORAGESERVERCLNT_H
       
    21 #define ATSTORAGESERVERCLNT_H
       
    22 
       
    23 
       
    24 // INCLUDES
       
    25 #include    <e32base.h>
       
    26 #include    <analyzetool/atcommon.h>
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 // Constants for the lowest version of the server with which the
       
    31 // client is compatible
       
    32 const TUint KLowestVersionNumberMaj = 0;
       
    33 const TUint KLowestVersionNumberMin = 1;
       
    34 const TUint KLowestVersionNumberBld = 1;
       
    35 
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class TATProcessInfo;
       
    39 
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 /**
       
    44 *  The main class of the Storage Server client. Objects of this class work as handles
       
    45 *  to the Storage Server's server side. Use Connect() to connect a client to the server,
       
    46 *  and Close() to end an opened session.
       
    47 */
       
    48 class RATStorageServer: public RSessionBase
       
    49     {
       
    50     public:  // Constructor and destructor
       
    51        
       
    52         /**
       
    53         * C++ default constructor.
       
    54         */
       
    55         IMPORT_C RATStorageServer();
       
    56    
       
    57     public: // New functions
       
    58         
       
    59         /**
       
    60         * Creates a new process for the server, if that doesn't already exist, and
       
    61         * connects a client to the server by creating a new session with it, and
       
    62         * initializes the client for use. To end the server session, use Close().
       
    63         * @return KErrNone, if successful; otherwise one of the other
       
    64         *   system-wide error codes.
       
    65         */
       
    66         IMPORT_C TInt Connect();
       
    67     
       
    68         /**
       
    69         * Closes a handle to a server session. This has also the effect of destroying
       
    70         * the associated server side session object. Also, the server itself and the
       
    71         * process where it is running are destroyed, if there are no other open sessions
       
    72         * left.
       
    73         */
       
    74         IMPORT_C void Close();
       
    75     
       
    76         /**
       
    77         * This method is called to initialize the server for logging and it is to be
       
    78         * called as the first method after connecting to the server. The method informs
       
    79         * the server that a new process has been started. The method cannot be called
       
    80         * again without a call to the LogProcessEnded() first. Otherwise a STSEClient: 3
       
    81         * panic is raised. A KERN-EXEC: 0 panic is raised if the client is not connected
       
    82         * to the server.
       
    83         * @param aFileName The name of the logging file used when the system is logging
       
    84         *   to a file (the logging mode is EATLogToFile). The length of aFileName must not be
       
    85         *   greater than KMaxFileName, otherwise the method raises a STSEClient: 2 panic.
       
    86         * @param aProcessName The name of the new process started. The length of this
       
    87         *   descriptor must not be greater than KMaxProcessName, otherwise the method
       
    88         *   raises a STSEClient: 2 panic.
       
    89         * @param aProcessId The ID of the process started.
       
    90         * @param aLogOption An option telling the logging mode.
       
    91         * @param aIsDebug Determines whether a binary is UDEB or UREL
       
    92         * @return KErrNone, if successful; otherwise one of the other
       
    93         *   system-wide error codes.
       
    94         */
       
    95         IMPORT_C TInt LogProcessStarted( const TDesC& aFileName,
       
    96                                          const TDesC8& aProcessName,
       
    97                                          TUint aProcessId,
       
    98                                          TUint32 aLogOption, TUint32 aIsDebug );
       
    99         
       
   100         /**
       
   101         * Asks the server to log that a new DLL has been loaded. Note, the method
       
   102         * LogProcessStarted() has to be previously called. Otherwise a STSEClient: 3
       
   103         * panic is raised. A KERN-EXEC: 0 panic is raised if the client is not connected
       
   104         * to the server.
       
   105         * @param aDllName The name of the new DLL loaded. The length of this descriptor
       
   106         *   must not be greater than KMaxLibraryName, otherwise the method raises a
       
   107         *   STSEClient: 2 panic.
       
   108         * @param aStartAddress The start address of the DLL loaded.
       
   109         * @param aEndAddress The end address of the DLL loaded.
       
   110         * @return KErrNone, if successful; otherwise one of the other
       
   111         *   system-wide error codes.
       
   112         */
       
   113         IMPORT_C TInt LogDllLoaded( const TDesC8& aDllName, TUint32 aStartAddress,
       
   114                                               TUint32 aEndAddress );
       
   115         
       
   116         /**
       
   117         * Asks the server to log that a new DLL has been unloaded. Note, the method
       
   118         * LogProcessStarted() has to be previously called. Otherwise a STSEClient: 3
       
   119         * panic is raised. A KERN-EXEC: 0 panic is raised if the client is not connected
       
   120         * to the server. If the method is called with illegal parameter values, a
       
   121         * STSEClient: 2 panic is raised.
       
   122         * @param aDllName The name of the DLL to be unloaded. The length of this
       
   123         *   descriptor must not be greater than KMaxLibraryName, otherwise the method
       
   124         *   raises a STSEClient: 2 panic.
       
   125         * @param aStartAddress The start address of the DLL to be unloaded.
       
   126         * @param aEndAddress The end address of the DLL to be unloaded.
       
   127         * @return KErrNone, if successful; otherwise one of the other
       
   128         *   system-wide error codes.
       
   129         */
       
   130         IMPORT_C TInt LogDllUnloaded( const TDesC8& aDllName, TUint32 aStartAddress,
       
   131                                                TUint32 aEndAddress );
       
   132         
       
   133         /**
       
   134         * Informs the server that a memory allocation has occured at the specified
       
   135         * address. Sends also the current call stack to the server. Note, the method
       
   136         * LogProcessStarted() has to be previously called. Otherwise a STSEClient: 3 
       
   137         * panic is raised. A KERN-EXEC: 0 panic is raised if the client is not connected
       
   138         * to the server.
       
   139         * @param aMemAddress The memory location where memory has been allocated.
       
   140         * @param aCallstack An array including the current call stack.
       
   141         * @param aSize The size of the newly allocated memory chunk.
       
   142         * @return KErrNone, if successful; otherwise one of the other
       
   143         *   system-wide error codes.
       
   144         */
       
   145         IMPORT_C TInt LogMemoryAllocated( TUint32 aMemAddress,
       
   146                                           TFixedArray<TUint32, KATMaxCallstackLength>& aCallstack,
       
   147                                           TInt aSize );
       
   148                 
       
   149         /**
       
   150         * Informs the server that memory was released at the specified address. Note,
       
   151         * the method LogProcessStarted() has to be previously called. Otherwise a 
       
   152         * STSEClient: 3 panic is raised. A KERN-EXEC: 0 panic is raised if the client is
       
   153         * not connected to the server.
       
   154         * @param aMemAddress The memory location where memory has been deallocated.
       
   155         * @param aFreeCallstack An array including the current call stack.
       
   156         * @return KErrNone, if successful; otherwise one of the other
       
   157         *   system-wide error codes.
       
   158         */
       
   159         IMPORT_C TInt LogMemoryFreed( TUint32 aMemAddress, 
       
   160                                       TFixedArray<TUint32, KATMaxFreeCallstackLength>& aFreeCallstack );
       
   161         
       
   162         /**
       
   163         * Tells the server that the process under test has been ended. Prints information
       
   164         * related to process ending, such as possibly occured memory leaks (when file
       
   165         * logging mode used), and possibly occured handle leaks. Note, the method 
       
   166         * LogProcessStarted() has to be previously called. Otherwise a STSEClient:
       
   167         * 3 panic is raised. A call to this method also closes the file opened for
       
   168         * the current process. So, no further logging is possible without a new call
       
   169         * to the method LogProcessStarted(). A KERN-EXEC: 0 panic is raised if the client
       
   170         * is not connected to the server.
       
   171         * @param aProcessId The ID number of the process ended.
       
   172         * @param aHandleLeaks Amount of handle leaks.
       
   173         * @return KErrNone, if successful; otherwise one of the other
       
   174         *   system-wide error codes.
       
   175         */
       
   176         IMPORT_C TInt LogProcessEnded( TUint aProcessId, 
       
   177                                        TUint aHandleLeaks );
       
   178            
       
   179         /**
       
   180         * Gives the lowest version number of the server needed for this client.
       
   181         * @return The lowest version of the server needed for this client.
       
   182         */
       
   183         IMPORT_C TVersion Version() const;  
       
   184 
       
   185         /**
       
   186         * Checks if the current process has allocated, but not freed, the given memory
       
   187         * address. Note, the method LogProcessStarted() has to be previously called.
       
   188         * Otherwise a STSEClient: 3 panic is raised. A KERN-EXEC: 0 panic is raised if
       
   189         * the client is not connected to the server.
       
   190         * @param aMemAddress The memory location to check.
       
   191         * @return When the system is logging into a file: the index of a found 
       
   192         *   memory address or KErrNotFound, if a matching memory address cannot
       
   193         *   be found. When the system is not logging into a file: always KErrNone.
       
   194         */
       
   195         IMPORT_C TInt CheckMemoryAddress( TUint32 aMemAddress ) const;
       
   196         
       
   197         /**
       
   198         * Gets all the processes with currently open logging sessions.
       
   199         * @param aProcesses A reference to a process array to be filled by the server.
       
   200         * @return KErrNone, if successful; otherwise one of the other
       
   201         *   system wide error codes.
       
   202         */
       
   203         IMPORT_C TInt GetProcessesL( RArray<TATProcessInfo>& aProcesses );
       
   204         
       
   205         /**
       
   206         * Gets all the DLLs loaded by the given process.
       
   207         * @param aProcessId The ID of the process whose DLLs will be fetched.
       
   208         * @param aDlls An array that after this function call includes names of
       
   209         *   the given process's dlls
       
   210         * @return KErrNone, if successful; KErrNotFound, if the requested process was
       
   211         *   not found; otherwise one of the other system wide error codes.
       
   212         */
       
   213         IMPORT_C TInt GetLoadedDllsL( TUint aProcessId,
       
   214                                       RArray< TBuf8<KMaxLibraryName> >& aDlls );
       
   215                 
       
   216         /**
       
   217         * Gets the logging mode of the given process.
       
   218         * @param aProcessId The ID of the process whose logging mode is being asked.
       
   219         * @param aLoggingMode An enumeration telling the logging mode after a call
       
   220         *   to this function.
       
   221         * @return KErrNone, if successful; KErrNotFound, if the requested process was
       
   222         *   not found; otherwise one of the other system wide error codes.
       
   223         */
       
   224         IMPORT_C TInt GetLoggingModeL( TUint aProcessId, TATLogOption& aLoggingMode );
       
   225         
       
   226         /**
       
   227         * Starts a sub test for the given process.
       
   228         * @param aProcessId The ID of the process for which to start a sub test.
       
   229         * @param aSubtestId The name identifying this particular sub test. The length
       
   230         *   of this descriptor must not be greater than KATMaxSubtestIdLength, or
       
   231         *   otherwise the method raises a STSEClient: 2 panic.
       
   232         * @param aHandleCount The current handle count of a particular process.
       
   233         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   234         *   found; KErrNotSupported, if the requested process does not have a logging
       
   235         *   session ongoing or its logging mode is not EATLogToTrace; Otherwise one of the
       
   236         *   other system wide error codes.
       
   237         */
       
   238         IMPORT_C TInt StartSubTest( TUint aProcessId, const TDesC8& aSubtestId, TInt aHandleCount = 0 );
       
   239 
       
   240         /**
       
   241         * Stops a sub test for the given process.
       
   242         * @param aProcessId The ID of the process for which to stop a sub test.
       
   243         * @param aSubtestId The name identifying this particular sub test. The length
       
   244         *   of this descriptor must not be greater than KATMaxSubtestIdLength, or
       
   245         *   otherwise the method raises a STSEClient: 2 panic.
       
   246         * @param aHandleCount The current handle count of a particular process.
       
   247         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   248         *   found; KErrNotSupported, if the requested process does not have a logging
       
   249         *   session ongoing or its logging mode is not EATLogToTrace; Otherwise one of the
       
   250         *   other system wide error codes.
       
   251         */
       
   252         IMPORT_C TInt StopSubTest( TUint aProcessId, const TDesC8& aSubtestId, TInt aHandleCount = 0 );
       
   253         
       
   254         /**
       
   255         * Gets the number and total size of the memory chunks currently allocated by the
       
   256         * requested process. 
       
   257         * @param aProcessId The ID of the process whose information is requested.
       
   258         * @param aNumber On return contains the number of memory chunks currenlty
       
   259         *   allocated by the requested process.
       
   260         * @param aSize On return contains the amount of memory currently allocated
       
   261         *   by the requested process.
       
   262         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   263         *   found; Otherwise one of the other system wide error codes.
       
   264         */
       
   265         IMPORT_C TInt GetCurrentAllocsL( TUint aProcessId, TUint32& aNumber, TUint32& aSize );
       
   266         
       
   267         /**
       
   268         * Gets the maximum number and total size of the memory chunks allocated by the
       
   269         * requested process. 
       
   270         * @param aProcessId The ID of the process whose information is requested.
       
   271         * @param aNumber On return contains the maximum number of memory chunks
       
   272         *   allocated by the requested process during the test run.
       
   273         * @param aSize On return contains the maximum amount of memory allocated
       
   274         *   by the requested process during the test run.
       
   275         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   276         *   found; Otherwise one of the other system wide error codes.
       
   277         */
       
   278         IMPORT_C TInt GetMaxAllocsL( TUint aProcessId, TUint32& aNumber, TUint32& aSize );
       
   279         
       
   280         /**
       
   281         * Starts a sub test for the calling process.
       
   282         * @param aSubtestId The name identifying this particular sub test. The length
       
   283         *   of this descriptor must not be greater than KATMaxSubtestIdLength, or
       
   284         *   otherwise the method raises a STSEClient: 2 panic.
       
   285         * @return KErrNone, if successful; KErrNotSupported, if the calling process
       
   286         *   does not have a logging session ongoing or its logging mode is not
       
   287         *   EATLogToTrace; Otherwise one of the other system wide error codes.
       
   288         */
       
   289         IMPORT_C TInt StartSubTest( const TDesC8& aSubtestId );
       
   290 
       
   291         /**
       
   292         * Stops a sub test for the calling process
       
   293         * @param aSubtestId The name identifying this particular sub test. The length
       
   294         *   of this descriptor must not be greater than KATMaxSubtestIdLength, or
       
   295         *   otherwise the method raises a STSEClient: 2 panic.
       
   296         * @return KErrNone, if successful; KErrNotSupported, if the calling process
       
   297         *   does not have a logging session ongoing or its logging mode is not
       
   298         *   EATLogToTrace; Otherwise one of the other system wide error codes.
       
   299         */
       
   300         IMPORT_C TInt StopSubTest( const TDesC8& aSubtestId );
       
   301         
       
   302         /**
       
   303         * Cancels logging for the requested process. After logging of a given process
       
   304         * has been cancelled, the session associated with that process will not be
       
   305         * usable anymore. If a process wants to start logging again, it needs to close
       
   306         * the handle and open it again in order to create a new session. Until then, most
       
   307         * of the client's methods will return KErrCancel.
       
   308         * @param aProcessId The process ID of the process whose logging is requested to
       
   309         *   be cancelled.
       
   310         * @return KErrNone, if successful; KErrNotFound, if the requested process was
       
   311         *   not found; otherwise one of the other system wide error codes.
       
   312         */
       
   313         IMPORT_C TInt CancelLogging( TUint aProcessId );
       
   314 
       
   315         /**
       
   316         * Gets the number and total size of the memory chunks currently allocated by the
       
   317         * requested process. 
       
   318         * @param aProcessId The ID of the process whose information is requested.
       
   319         * @param aIsUdeb On return contains an value greater than KErrNone if
       
   320         *   mode is UDEB. Else the mode is UREL
       
   321         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   322         *   found; Otherwise one of the other system wide error codes.
       
   323         */
       
   324         IMPORT_C TInt GetUdebL( TUint aProcessId, TUint32& aIsUdeb );
       
   325 
       
   326         /**
       
   327         * Gets the number and total size of the memory chunks currently allocated by the
       
   328         * requested process. 
       
   329         * @param aProcessId The ID of the process whose information is requested.
       
   330         * @param aFileName On return contains logging filename for the process.
       
   331         * @return KErrNone, if successful; KErrNotFound, if the requested process was not
       
   332         *   found; Otherwise one of the other system wide error codes.
       
   333         */
       
   334         IMPORT_C TInt GetLoggingFileL( TUint aProcessId, TDes8& aFileName );
       
   335      
       
   336         /**
       
   337 		* Check a memory allocation (memory address) from an internal array.
       
   338 		* @param aMemAddress The memory address to be check
       
   339 		* @return KErrNone, if memory address found in array; 
       
   340 		* 	KErrNotFound, if the requested memory address was not found.
       
   341 		*/
       
   342         IMPORT_C TInt IsMemoryAdded( TUint32 aMemAddress );
       
   343                
       
   344     protected: // New functions
       
   345     
       
   346         /**
       
   347         * Creates a new process for the server, if it does not already exist.
       
   348         * @return KErrNone, if successful; otherwise one of the other
       
   349         * system-wide error codes. 
       
   350         */
       
   351         TInt CreateProcess();
       
   352         
       
   353     private: // Internal functions
       
   354     
       
   355         /**
       
   356         * Creates two buffers: one for storing call stack memory addresses and one for
       
   357         * handle leaks. Internally used by this class. May leave, if there is 
       
   358         * insufficient memory.
       
   359         */
       
   360         void ConstructBuffersL();
       
   361         
       
   362     private: // Data
       
   363     
       
   364         /** A pointer to a buffer of call stack's memory addresses */
       
   365         CBufFlat* iStackBuf;
       
   366     };
       
   367 
       
   368 #endif      // ATSTORAGESERVERCLNT_H   
       
   369 
       
   370             
       
   371 // End of File