harvester/monitorplugins/fileplugin/inc/processoriginmapper.h
changeset 0 c53acadfccc6
child 19 82c0024438c8
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Maintains a list of process ids and matching origin*
       
    15 */
       
    16 
       
    17 
       
    18 #ifndef __PROCESSORIGINMAPPER_H__
       
    19 #define __PROCESSORIGINMAPPER_H__
       
    20 
       
    21 #include <e32cmn.h>
       
    22 #include <s32file.h>
       
    23 
       
    24 #include "mdeconstants.h"
       
    25 #include "processoriginmapperinterface.h"
       
    26 
       
    27 /**
       
    28  * @var Data transfer object used for process/origin
       
    29  * mapping table.
       
    30  */
       
    31 struct TProcessOriginPair
       
    32     {
       
    33     TUid iProcessId;
       
    34     TOrigin iOrigin;
       
    35     };
       
    36 
       
    37 /**
       
    38  * @var Maximum amount of items allowed in the mapping table.
       
    39  */
       
    40 const TInt KMaxMappingSize = 100;
       
    41 
       
    42 
       
    43 /**
       
    44  * Maintains a list of process ids and matching origin
       
    45  * values to be set for mde objects created by a process.
       
    46  * List is maintained in memory and in a text file.
       
    47  * 
       
    48  * API is provided to add and remove processes in the list
       
    49  * and to retrieve the matching origin by a process id (if any).
       
    50  * Mappings are read written to a file on request.
       
    51  */
       
    52 class CProcessOriginMapper : public CBase,
       
    53                              public MProcessOriginMapperInterface
       
    54     {
       
    55     public:
       
    56 
       
    57         /**
       
    58          * Creates and constructs a new instance of CLocationContextPlugin.
       
    59          * Two-phase construction.
       
    60          *
       
    61          * @return A pointer to the created instance.
       
    62          */
       
    63         static CProcessOriginMapper* NewL();
       
    64     
       
    65         /**
       
    66          * Destructor.
       
    67          */
       
    68         virtual ~CProcessOriginMapper();
       
    69 
       
    70     private:
       
    71 
       
    72         /**
       
    73          * Private constructor, called by NewL() only.
       
    74          */
       
    75         CProcessOriginMapper();
       
    76     
       
    77         /**
       
    78          * Second phase construction called by NewL().
       
    79          */
       
    80         void ConstructL();
       
    81 
       
    82     public:
       
    83 
       
    84         /**
       
    85          * Add a process to the list.
       
    86          * @param aProcessUid  Uid of the process to add.
       
    87          * @param aOrigin      Origin to which this process will mapped to.
       
    88          */
       
    89         void RegisterProcessL( const TUid& aProcessId,
       
    90                                const TOrigin& aOrigin );
       
    91         
       
    92         /**
       
    93          * Remove a process from the list.
       
    94          * @param aProcessId  Uid of the process to remove.
       
    95          */
       
    96         void UnregisterProcessL( const TUid& aProcessId );
       
    97 
       
    98         /**
       
    99          * Check a process from the list.
       
   100          * @param aProcessId  Uid of the process to check.
       
   101          * @return  Origin the given process is mapped to
       
   102          *          or KErrNotFound if not found.
       
   103          */
       
   104         TOrigin OriginL( const TUid& aProcessId );
       
   105 
       
   106         /**
       
   107          * Read process id mappings from a file.
       
   108          * This doesn't clear the list of currently registered mappings.
       
   109          * @param aFile  File name and path.
       
   110          * @return Count of mapping pairs read.
       
   111          */
       
   112         TInt ReadFileL( const TDesC& aFile );
       
   113 
       
   114         /**
       
   115          * Read process id mappings from the default file.
       
   116          * @return Count of mapping pairs read.
       
   117          */
       
   118         TInt ReadFileL();
       
   119 
       
   120         /**
       
   121          * Write process id mappings to a file.
       
   122          * @param aFile  File name and path.
       
   123          */
       
   124         void WriteFileL( const TDesC& aFile );
       
   125 
       
   126         /**
       
   127          * Write process id mappings to the default file.
       
   128          */
       
   129         void WriteFileL();
       
   130 
       
   131         /**
       
   132          * Clear mapping table in memory.
       
   133          */
       
   134         void Clear();
       
   135 
       
   136         /**
       
   137          * Count of registered mappings.
       
   138          * @return Count
       
   139          */
       
   140         TInt Count();
       
   141 
       
   142     private:
       
   143 
       
   144         /**
       
   145          * Find an index by process id.
       
   146          * @param aProcessId  Process id.
       
   147          * @return  Index or KErrNotFound if not found.
       
   148          */
       
   149         TInt FindProcess( const TUid& aProcessId );
       
   150         
       
   151         /**
       
   152          * Read one process id and origin pair from file.
       
   153          * @param aProcessUid  Uid of the process to add.
       
   154          * @param aOrigin      Origin to which this process will mapped to.
       
   155          */
       
   156         void ReadProcessOriginPairL( TUid& aProcessId, TOrigin& aOrigin );
       
   157 
       
   158         /**
       
   159          * Write one related process/origin pair to a file.
       
   160          * @param aProcessUid  Uid of the process to add.
       
   161          * @param aOrigin      Origin to which this process will mapped to.
       
   162          */
       
   163         void WriteProcessOriginPairL( TUid& aProcessId, TOrigin& aOrigin );
       
   164 
       
   165     private: // data
       
   166 
       
   167         /**
       
   168          * @var Mapping table. It holds pairs of
       
   169          * matching process ids and origins.
       
   170          * Content is loaded from and saved to a file.
       
   171          */
       
   172         RArray<TProcessOriginPair> iProcessOriginMap;
       
   173         
       
   174         /**
       
   175          * File system session.
       
   176          */
       
   177         RFs iFs;
       
   178         
       
   179         /**
       
   180          *  File stream used for reading the import file
       
   181          */
       
   182         RFileReadStream iReadStream;
       
   183 
       
   184         /**
       
   185          *  File stream used for writing the export file
       
   186          */
       
   187         RFileWriteStream iWriteStream;
       
   188 
       
   189         /**
       
   190          * A buffer used for reading lines from files.
       
   191          */
       
   192         HBufC8* iLineBuffer;
       
   193 
       
   194         /**
       
   195          * Indicates read defult origin map file.
       
   196          * No write process should occur.
       
   197          */
       
   198         TBool iDefaultFileRead;
       
   199     };
       
   200 
       
   201 #endif