webservices/wslogger/src/senlogger.cpp
branchRCL_3
changeset 15 32ab7ae9ec94
parent 0 62f9d29f7211
equal deleted inserted replaced
14:9e96e2676219 15:32ab7ae9ec94
    23 
    23 
    24 
    24 
    25 
    25 
    26 
    26 
    27 #include "senlogger.h"
    27 #include "senlogger.h"
    28 //#include <flogger.h>
       
    29 #include <f32file.h>
    28 #include <f32file.h>
    30 #include <s32file.h> 
    29 #include <s32file.h> 
    31 #include <versit.h>
       
    32 
    30 
    33 namespace
    31 namespace
    34     {
    32     {
    35     const TInt KColumnWidth = 100; // used in WriteAll() methods.
    33     const TInt KColumnWidth = 100; // used in WriteAll() methods.
    36      _LIT(KPath,"C:\\SenLogConfig.txt");
    34      _LIT(KPath,"C:\\SenLogConfig.txt");
    47 	 return CreateL( aChannel, aLevel, aLogDir, aLogFileName, EFileLoggingModeOverwrite );
    45 	 return CreateL( aChannel, aLevel, aLogDir, aLogFileName, EFileLoggingModeOverwrite );
    48      }
    46      }
    49 EXPORT_C TInt CSenLogger::CreateL(TInt aChannel, TInt aLevel, const TDesC& aLogDir, const TDesC& aLogFileName, TFileLoggingMode aMode)
    47 EXPORT_C TInt CSenLogger::CreateL(TInt aChannel, TInt aLevel, const TDesC& aLogDir, const TDesC& aLogFileName, TFileLoggingMode aMode)
    50     {
    48     {
    51     TInt index(KErrNotFound);
    49     TInt index(KErrNotFound);
    52     //	  CSenLogger* pSenLogger = (CSenLogger*)Dll::Tls();
       
    53     CSenLogger* pSenLogger = NULL;
    50     CSenLogger* pSenLogger = NULL;
    54     TWsTls* tls = (TWsTls*)Dll::Tls();
    51     TWsTls* tls = (TWsTls*)Dll::Tls();
    55     if( !tls )
    52     if( !tls )
    56         {
    53         {
    57         tls = new (ELeave) TWsTls();
    54         tls = new (ELeave) TWsTls();
    63 	if ( !pSenLogger )
    60 	if ( !pSenLogger )
    64   		{
    61   		{
    65   		pSenLogger = new (ELeave) CSenLogger();
    62   		pSenLogger = new (ELeave) CSenLogger();
    66         if ( pSenLogger )
    63         if ( pSenLogger )
    67             {
    64             {
    68             //      		  Dll::SetTls(pSenLogger);
       
    69             tls->iLogger = pSenLogger;
    65             tls->iLogger = pSenLogger;
    70       		pSenLogger->iCount = 0;
    66       		pSenLogger->iCount = 0;
    71       		//reading the configuration file for the logging levels!!!
    67       		//reading the configuration file for the logging levels!!!
    72       		
    68       		
    73       		/*the file has the  following format
    69       		/*the file has the  following format (IN ANSI)
    74       		* ==============================================================================
    70       		* ==============================================================================
    75       		  * LogChannel LogLevel
    71       		  * LogChannel LogLevel
    76       		    1000 0
    72       		    1000 0
    77       		    2000 1
    73       		    2000 1
    78       		      .
    74       		      .
    90       
    86       
    91       		TInt res;
    87       		TInt res;
    92       	    RFs fs;
    88       	    RFs fs;
    93       	    res=fs.Connect();
    89       	    res=fs.Connect();
    94       	      if(res==KErrNone)
    90       	      if(res==KErrNone)
       
    91 			{
       
    92 			RFileReadStream readStream;
       
    93 	      	res=readStream.Open(fs, KPath, EFileRead|EFileStreamText);
       
    94 			if(res == KErrNone)
    95 				{
    95 				{
    96       	     
    96 				TInt error;
    97                 RFileReadStream readStream;
    97 				TInt retVal;
    98       	        res=readStream.Open(fs,KPath,EFileRead|EFileStreamText);
    98 				do
    99       	   		if(res==KErrNone)
    99 					{
   100       	     		{
   100 					TBuf8<128> readLineBuf;
   101       	      		TInt error;
   101 					TRAP(error, readStream.ReadL(readLineBuf, (TChar)'\n'));
   102       	      		TBool result;
   102 					if(error == KErrNone)
   103       	      		TInt retVal;
   103 						{      
   104       	      		
   104 						TInt32 length(0);
   105       	      		CLineReader *readLine = CLineReader::NewL(readStream);
   105 						length = readLineBuf.Length() ;
   106                     CleanupStack::PushL(readLine);
   106 						TInt *key = new (ELeave) TInt;
   107       	    		
   107 						TLex8 lexBuf(readLineBuf);
   108                 	do
   108 						retVal = lexBuf.Val(*key);
   109       	    		    {
   109 
   110       	      		    result=readLine->ReadLineL(0,error);
   110 						if(retVal!=0)
   111       	      		    
   111 							{
   112       	       	        if(result==CLineReader::ELineHasContent)
   112 							delete key;
   113       	       			    {
   113 							continue;
   114       	       			    
   114 							}
   115               	      		TInt *key = new (ELeave) TInt;
   115 						else
   116               	      	
   116 							{
   117           	      		
   117 							TInt *value = new (ELeave) TInt;
   118       	       			    TLex8 lexBuf(readLine->iBufPtr);
   118 							lexBuf.SkipSpace();
   119       	     			    retVal = lexBuf.Val(*key);
   119 							retVal=lexBuf.Val(*value);
   120       	     			    
   120 							if(retVal==0)
   121       	     			    if(retVal!=0)
   121 								{
   122       	     			        {
   122 								retVal = pSenLogger->iMap.Append(key,value);
   123       	     			        delete key;
   123 								if(retVal != KErrNone)
   124                              
   124 									{
   125       	     			        continue;
   125 									delete key;
   126       	     			        }
   126 									delete value;
   127       	     			    else
   127 									}
   128       	     			        {
   128 								}
   129                   	      		TInt *value = new (ELeave) TInt;
   129 							else
   130                   	      
   130 								{
   131       	      		
   131 								delete key;
   132   	     			            lexBuf.SkipSpace();
   132 								delete value;
   133   	     			            retVal=lexBuf.Val(*value);
   133 								}
   134   	     			            if(retVal==0)
   134 							}
   135 	  	     			            {
   135 						}
   136   	     			    	        retVal = pSenLogger->iMap.Append(key,value);
   136 					}while(error == KErrNone);
   137   	     			    	        if(retVal != KErrNone)
   137 				readStream.Close();
   138   	     			    	            {
   138 				}
   139   	     			    	            delete key;
   139 			fs.Close();
   140   	     			    	            delete value;
   140 			}
   141       	    		                   
       
   142   	     			    	            }
       
   143   	     			    	   
       
   144   		     			            }
       
   145   		     			         else
       
   146   		     			            {
       
   147   		     			              delete key;
       
   148   	     			    	          delete value;
       
   149   		     			                
       
   150   		     			            }
       
   151       	     			    	
       
   152       	     			        }
       
   153       	       			    }
       
   154       	       			 
       
   155       	    		    }while(error!=KErrEof);
       
   156       	    		 
       
   157       	    		 CleanupStack::PopAndDestroy(readLine);
       
   158       	      	     readStream.Close();
       
   159       	     		}
       
   160       	     
       
   161       	      	fs.Close();
       
   162       	      	}
       
   163             }
   141             }
   164         else
   142         else
   165             {
   143             {
   166             return KErrGeneral;
   144             return KErrGeneral;
   167             }
   145             }