serialserver/c32serialserver/SCOMM/CS_LOG.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-2009 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 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include "C32LOG.H"
       
    18 #include "cs_glob.h"
       
    19 
       
    20 #if (defined __FLOG_ACTIVE)
       
    21 
       
    22 #include <cflog.h>
       
    23 
       
    24 template <class T> void DoWrite(TBool aStatic, const TDesC8& aSubTag, T& aBuf);
       
    25 
       
    26 EXPORT_C void TC32Log::Printf(TBool aStatic, const TDesC8& aSubTag, TRefByValue<const TDesC8> aFmt, ...)
       
    27 	{
       
    28 	VA_LIST list;
       
    29 	VA_START(list,aFmt);
       
    30 	Printf(aStatic, aSubTag, aFmt, list);
       
    31 	VA_END(list);
       
    32 	}
       
    33 
       
    34 
       
    35 void TC32Log::Printf(TBool aStatic, const TDesC8& aSubTag, TRefByValue<const TDesC8> aFmt, VA_LIST& aList)
       
    36 	{
       
    37 	TBuf8<KLogBufferSize> buf;
       
    38 	CTLSRedirector* tls = CRedirectorInTls();
       
    39 	if ((tls) && tls->IsC32GlobalDataSet())
       
    40 		{
       
    41 		CC32WorkerThread* worker = tls->C32GlobalData()->SelfWorker();
       
    42 		if(worker)
       
    43 			{
       
    44 			_LIT8(KWorkerIdFormat, "W%d: ");
       
    45 			buf.Format(KWorkerIdFormat, worker->WorkerId());
       
    46 			}
       
    47 		}
       
    48 		
       
    49 	TLogIgnoreOverflow8 overflowHandler;
       
    50 	buf.AppendFormatList(aFmt, aList, &overflowHandler);
       
    51 	DoWrite<TDes8>(aStatic, aSubTag, buf);
       
    52 	}
       
    53 
       
    54 
       
    55 
       
    56 
       
    57 EXPORT_C void TC32Log::Printf(TBool aStatic, const TDesC8& aSubTag, TRefByValue<const TDesC> aFmt, ...)
       
    58 	{
       
    59 	VA_LIST list;
       
    60 	VA_START(list,aFmt);
       
    61 	Printf(aStatic, aSubTag, aFmt, list);
       
    62 	VA_END(list);
       
    63 	}
       
    64 
       
    65 
       
    66 
       
    67 
       
    68 void TC32Log::Printf(TBool aStatic, const TDesC8& aSubTag, TRefByValue<const TDesC> aFmt, VA_LIST& aList)
       
    69 /**
       
    70 Write a mulitple argument list to the log, trapping and ignoring any leave
       
    71 
       
    72 */
       
    73 	{
       
    74 	TBuf<KLogBufferSize> buf;
       
    75 	CTLSRedirector* tls = CRedirectorInTls();
       
    76 	if ((tls) && tls->IsC32GlobalDataSet())
       
    77 		{
       
    78 		CC32WorkerThread* worker = tls->C32GlobalData()->SelfWorker();
       
    79 		if(worker)
       
    80 			{
       
    81 			_LIT(KWorkerIdFormat, "W%d: ");
       
    82 			buf.Format(KWorkerIdFormat, worker->WorkerId());
       
    83 			}
       
    84 		}
       
    85 		
       
    86 	TLogIgnoreOverflow16 overflowHandler;
       
    87 	buf.AppendFormatList(aFmt, aList, &overflowHandler);
       
    88 	DoWrite<TDes>(aStatic, aSubTag, buf);
       
    89 	}
       
    90 
       
    91 template <class T> void DoWrite(TBool aStatic, const TDesC8& aSubTag, T& aBuf)
       
    92 	{
       
    93 	if(!aBuf.Length())
       
    94 		return;
       
    95 	
       
    96 	if(aStatic)
       
    97 		{
       
    98 		__FLOG_STATIC_VA ((KC32SubSystem, aSubTag, aBuf));
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		CCFLogIf::Write(KC32SubSystem, aSubTag, aBuf);
       
   103 		}
       
   104 	}
       
   105 
       
   106 
       
   107 _LIT8(KLitCommAccessExclusive,   "ECommExclusive");
       
   108 _LIT8(KLitCommAccessShared,      "ECommShared");
       
   109 _LIT8(KLitCommAccessPreemptable, "ECommPreemptable");
       
   110 _LIT8(KLitCommAccessUnsupported, "**Unsupported**");
       
   111 
       
   112 
       
   113 
       
   114 /**
       
   115 Returns a string for a comm access mode
       
   116 
       
   117 @param aMode Comm Access Mode
       
   118 @return String name representation of aMode
       
   119 */
       
   120 const TDesC8& TC32Log::CommAccessStr(const TCommAccess& aMode)
       
   121 	{
       
   122 	switch(aMode)
       
   123 		{
       
   124 	case ECommExclusive:
       
   125 		return KLitCommAccessExclusive;
       
   126 	case ECommShared:
       
   127 		return KLitCommAccessShared;
       
   128 	case ECommPreemptable:
       
   129 		return KLitCommAccessPreemptable;
       
   130 	default:
       
   131 		return KLitCommAccessUnsupported;
       
   132 		}
       
   133 	}
       
   134 
       
   135 _LIT(KLitCommAccessExclusive16,   "ECommExclusive");
       
   136 _LIT(KLitCommAccessShared16,      "ECommShared");
       
   137 _LIT(KLitCommAccessPreemptable16, "ECommPreemptable");
       
   138 _LIT(KLitCommAccessUnsupported16, "**Unsupported**");
       
   139 
       
   140 	
       
   141 const TDesC& TC32Log::CommAccessStr16(const TCommAccess& aMode)
       
   142 // in some cases it is nice to be able to have the mode with the name of the module/port.
       
   143 // However, to get it onto one log line without fuss the whole log string needs to be 16-bits
       
   144 // since the module/port is a TDesC, so instead we provide a 16-bit version of this function.
       
   145 	{
       
   146 	switch(aMode)
       
   147 		{
       
   148 	case ECommExclusive:
       
   149 		return KLitCommAccessExclusive16;
       
   150 	case ECommShared:
       
   151 		return KLitCommAccessShared16;
       
   152 	case ECommPreemptable:
       
   153 		return KLitCommAccessPreemptable16;
       
   154 	default:
       
   155 		return KLitCommAccessUnsupported16;
       
   156 		}
       
   157 	}
       
   158 	
       
   159 	
       
   160 _LIT8(KLitIntCommExclusive,			"EIntCommExclusive");
       
   161 _LIT8(KLitIntCommShared,			"EIntCommShared");
       
   162 _LIT8(KLitIntCommPreemptable,		"EIntCommPreemptable");
       
   163 _LIT8(KLitIntCommWaitUntilAvailable,"EIntCommWaitUntilAvailable");
       
   164 _LIT8(KLitIntCommUnsupported,		"**Unsupported**");
       
   165 
       
   166 
       
   167 
       
   168 /**
       
   169 Returns a string for a internal comm access mode
       
   170 
       
   171 @param aMode Internal Comm Access Mode
       
   172 @return readable string for aMode
       
   173 */
       
   174 const TDesC8& TC32Log::InternalCommAccessStr(TInternalCommAccess aMode)
       
   175 	{
       
   176 	switch(aMode)
       
   177 		{
       
   178 		case EIntCommExclusive:
       
   179 			return KLitIntCommExclusive;
       
   180 		case EIntCommShared:
       
   181 			return KLitIntCommShared;
       
   182 		case EIntCommPreemptable:
       
   183 			return KLitIntCommPreemptable;
       
   184 		case EIntCommWaitUntilAvailable:
       
   185 			return KLitIntCommWaitUntilAvailable;
       
   186 		default:
       
   187 			return KLitIntCommUnsupported;
       
   188 		}
       
   189 	}
       
   190 
       
   191 
       
   192 
       
   193 _LIT8(KLitCommRoleDTE,			"ECommRoleDTE");
       
   194 _LIT8(KLitCommRoleDCE,			"ECommRoleDCE");
       
   195 _LIT8(KLitCommRoleUnsupported,	"**Unsupported**");
       
   196 
       
   197 
       
   198 /**
       
   199 Returns a string for a comm role
       
   200 
       
   201 @param aRole Comm Role
       
   202 @return readable string for aRole
       
   203 */
       
   204 const TDesC8& TC32Log::CommRoleStr(TCommRole aRole)
       
   205 	{
       
   206 	switch(aRole)
       
   207 		{
       
   208 		case ECommRoleDTE:
       
   209 			return KLitCommRoleDTE;
       
   210 		case ECommRoleDCE:
       
   211 			return KLitCommRoleDCE;
       
   212 		default:
       
   213 			return KLitCommRoleUnsupported;
       
   214 		}
       
   215 	}
       
   216 
       
   217 
       
   218 _LIT(KLitCommRoleDTE16,			"ECommRoleDTE");
       
   219 _LIT(KLitCommRoleDCE16,			"ECommRoleDCE");
       
   220 _LIT(KLitCommRoleUnsupported16,	"**Unsupported**");
       
   221 
       
   222 
       
   223 /**
       
   224 Returns a string for a comm role
       
   225 
       
   226 @param aRole Comm Role
       
   227 @return readable string for aRole
       
   228 */
       
   229 const TDesC& TC32Log::CommRoleStr16(TCommRole aRole)
       
   230 	{
       
   231 	switch(aRole)
       
   232 		{
       
   233 		case ECommRoleDTE:
       
   234 			return KLitCommRoleDTE16;
       
   235 		case ECommRoleDCE:
       
   236 			return KLitCommRoleDCE16;
       
   237 		default:
       
   238 			return KLitCommRoleUnsupported16;
       
   239 		}
       
   240 	}
       
   241 
       
   242 
       
   243 _LIT8(KLitCommLoadCommModule,"ECommLoadCommModule");
       
   244 _LIT8(KLitCommCloseCommModule,"ECommCloseCommModule");
       
   245 _LIT8(KLitCommPortInfo, "ECommPortInfo");
       
   246 _LIT8(KLitCommPortInfoByName,"ECommPortInfoByName");
       
   247 _LIT8(KLitCommPortInfoByNumber,"ECommPortInfoByNumber");
       
   248 _LIT8(KLitCommNumPorts,"ECommNumPorts");
       
   249 
       
   250 _LIT8(KLitCommStartServerThread,"ECommStartServerThread");
       
   251 _LIT8(KLitCommOpen,"ECommOpen");
       
   252 _LIT8(KLitCommRead,"ECommRead");
       
   253 _LIT8(KLitCommReadCancel,"ECommReadCancel");
       
   254 _LIT8(KLitCommQueryReceiveBuffer,"ECommQueryReceiveBuffer");
       
   255 
       
   256 _LIT8(KLitCommResetBuffers,"ECommResetBuffers");
       
   257 _LIT8(KLitCommWrite,"ECommWrite");
       
   258 _LIT8(KLitCommWriteCancel,"ECommWriteCancel");
       
   259 _LIT8(KLitCommBreak,"ECommBreak");
       
   260 _LIT8(KLitCommBreakCancel,"ECommBreakCancel");
       
   261 _LIT8(KLitCommCancel,"ECommCancel");
       
   262 _LIT8(KLitCommConfig,"ECommConfig");
       
   263 _LIT8(KLitCommSetConfig,"ECommSetConfig");
       
   264 _LIT8(KLitCommCaps,"ECommCaps");
       
   265 _LIT8(KLitCommSetMode,"ECommSetMode");
       
   266 
       
   267 _LIT8(KLitCommGetMode,"ECommGetMode");
       
   268 _LIT8(KLitCommSignals,"ECommSignals");
       
   269 _LIT8(KLitCommSetSignalsToMark,"ECommSetSignalsToMark");
       
   270 _LIT8(KLitCommSetSignalsToSpace,"ECommSetSignalsToSpace");
       
   271 _LIT8(KLitCommReceiveBufferLength,"ECommReceiveBufferLength");
       
   272 _LIT8(KLitCommSetReceiveBufferLength,"ECommSetReceiveBufferLength");
       
   273 _LIT8(KLitCommClose,"ECommClose");
       
   274 _LIT8(KLitCommDbgMarkHeap,"ECommDbgMarkHeap");
       
   275 _LIT8(KLitCommDbgCheckHeap,"ECommDbgCheckHeap");
       
   276 _LIT8(KLitCommDbgMarkEnd,"ECommDbgMarkEnd");
       
   277 
       
   278 _LIT8(KLitCommDbgFailNext,"ECommDbgFailNext");
       
   279 _LIT8(KLitCommDbgSetDebugPrintMask,"ECommDbgSetDebugPrintMask");
       
   280 _LIT8(KLitCommDbgDoDumpDebugInfo,"ECommDbgDoDumpDebugInfo");
       
   281 
       
   282 _LIT8(KLitCommGetRole,"ECommGetRole");
       
   283 _LIT8(KLitCommNotifySignals,"ECommNotifySignals");
       
   284 _LIT8(KLitCommNotifySignalsCancel,"ECommNotifySignalsCancel");
       
   285 _LIT8(KLitCommNotifyFlowControl,"ECommNotifyFlowControl");
       
   286 _LIT8(KLitCommNotifyFlowControlCancel,"ECommNotifyFlowControlCancel");
       
   287 _LIT8(KLitCommGetFlowControl,"ECommGetFlowControl");
       
   288 _LIT8(KLitCommNotifyConfigChange,"ECommNotifyConfigChange");
       
   289 
       
   290 _LIT8(KLitCommNotifyConfigChangeCancel,"ECommNotifyConfigChangeCancel");
       
   291 _LIT8(KLitCommNotifyBreak,"ECommNotifyBreak");
       
   292 _LIT8(KLitCommNotifyBreakCancel,"ECommNotifyBreakCancel");
       
   293 _LIT8(KLitCommNotifyDataAvailable,"ECommNotifyDataAvailable");
       
   294 _LIT8(KLitCommNotifyDataAvailableCancel,"ECommNotifyDataAvailableCancel");
       
   295 _LIT8(KLitCommNotifyOutputEmpty,"ECommNotifyOutputEmpty");
       
   296 _LIT8(KLitCommNotifyOutputEmptyCancel,"ECommNotifyOutputEmptyCancel");
       
   297 
       
   298 _LIT8(KLitCommSetAccess,"ECommSetAccess");
       
   299 _LIT8(KLitCommDebugState,"ECommDebugState");
       
   300 _LIT8(KLitCommOpenWhenAvailable,"ECommOpenWhenAvailable");
       
   301 
       
   302 _LIT8(KLitCommReqUnsupported,		"**Unsupported**");
       
   303 
       
   304 /**
       
   305 Returns a string for C32 IPC Requests.
       
   306 
       
   307 @param aIPC IPC code
       
   308 @return readable string for IPC request name
       
   309 */
       
   310 const TDesC8& TC32Log::C32RequestStr(TInt aIPC)
       
   311 	{
       
   312 	switch(aIPC)
       
   313 		{
       
   314 		case ECommLoadCommModule:
       
   315 			return KLitCommLoadCommModule;
       
   316 		case ECommCloseCommModule:
       
   317 			return KLitCommCloseCommModule;
       
   318 		case ECommPortInfo:
       
   319 			return KLitCommPortInfo;
       
   320 		case ECommPortInfoByName:
       
   321 			return KLitCommPortInfoByName;
       
   322 		case ECommPortInfoByNumber:
       
   323 			return KLitCommPortInfoByNumber;
       
   324 		case ECommNumPorts:
       
   325 			return KLitCommNumPorts;
       
   326 		case ECommStartServerThread:
       
   327 			return KLitCommStartServerThread;
       
   328 		case ECommOpen:
       
   329 			return KLitCommOpen;
       
   330 		case ECommRead:
       
   331 			return KLitCommRead;
       
   332 		case ECommReadCancel:
       
   333 			return KLitCommReadCancel;
       
   334 		case ECommQueryReceiveBuffer:
       
   335 			return KLitCommQueryReceiveBuffer;
       
   336 		case ECommResetBuffers:
       
   337 			return KLitCommResetBuffers;
       
   338 		case ECommWrite:
       
   339 			return KLitCommWrite;
       
   340 		case ECommWriteCancel:
       
   341 			return KLitCommWriteCancel;
       
   342 		case ECommBreak:
       
   343 			return KLitCommBreak;
       
   344 		case ECommBreakCancel:
       
   345 			return KLitCommBreakCancel;
       
   346 		case ECommCancel:
       
   347 			return KLitCommCancel;
       
   348 		case ECommConfig:
       
   349 			return KLitCommConfig;
       
   350 		case ECommSetConfig:
       
   351 			return KLitCommSetConfig;
       
   352 		case ECommCaps:
       
   353 			return KLitCommCaps;
       
   354 		case ECommSetMode:
       
   355 			return KLitCommSetMode;
       
   356 		case ECommGetMode:
       
   357 			return KLitCommGetMode;
       
   358 		case ECommSignals:
       
   359 			return KLitCommSignals;
       
   360 		case ECommSetSignalsToMark:
       
   361 			return KLitCommSetSignalsToMark;
       
   362 		case ECommSetSignalsToSpace:
       
   363 			return KLitCommSetSignalsToSpace;
       
   364 		case ECommReceiveBufferLength:
       
   365 			return KLitCommReceiveBufferLength;
       
   366 		case ECommSetReceiveBufferLength:
       
   367 			return KLitCommSetReceiveBufferLength;
       
   368 		case ECommClose:
       
   369 			return KLitCommClose;
       
   370 		case ECommDbgMarkHeap:
       
   371 			return KLitCommDbgMarkHeap;
       
   372 		case ECommDbgCheckHeap:
       
   373 			return KLitCommDbgCheckHeap;
       
   374 		case ECommDbgMarkEnd:
       
   375 			return KLitCommDbgMarkEnd;
       
   376 		case ECommDbgFailNext:
       
   377 			return KLitCommDbgFailNext;
       
   378 		case ECommDbgSetDebugPrintMask:
       
   379 			return KLitCommDbgSetDebugPrintMask;
       
   380 		case ECommDbgDoDumpDebugInfo:
       
   381 			return KLitCommDbgDoDumpDebugInfo;
       
   382 		case ECommGetRole:
       
   383 			return KLitCommGetRole;
       
   384 		case ECommNotifySignals:
       
   385 			return KLitCommNotifySignals;
       
   386 		case ECommNotifySignalsCancel:
       
   387 			return KLitCommNotifySignalsCancel;
       
   388 		case ECommNotifyFlowControl:
       
   389 			return KLitCommNotifyFlowControl;
       
   390 		case ECommNotifyFlowControlCancel:
       
   391 			return KLitCommNotifyFlowControlCancel;
       
   392 		case ECommGetFlowControl:
       
   393 			return KLitCommGetFlowControl;
       
   394 		case ECommNotifyConfigChange:
       
   395 			return KLitCommNotifyConfigChange;
       
   396 		case ECommNotifyConfigChangeCancel:
       
   397 			return KLitCommNotifyConfigChangeCancel;
       
   398 		case ECommNotifyBreak:
       
   399 			return KLitCommNotifyBreak;
       
   400 		case ECommNotifyBreakCancel:
       
   401 			return KLitCommNotifyBreakCancel;
       
   402 		case ECommNotifyDataAvailable:
       
   403 			return KLitCommNotifyDataAvailable;
       
   404 		case ECommNotifyDataAvailableCancel:
       
   405 			return KLitCommNotifyDataAvailableCancel;
       
   406 		case ECommNotifyOutputEmpty:
       
   407 			return KLitCommNotifyOutputEmpty;
       
   408 		case ECommNotifyOutputEmptyCancel:
       
   409 			return KLitCommNotifyOutputEmptyCancel;
       
   410 		case ECommSetAccess:
       
   411 			return KLitCommSetAccess;
       
   412 		case ECommDebugState:
       
   413 			return KLitCommDebugState;
       
   414 		case ECommOpenWhenAvailable:
       
   415 			return KLitCommOpenWhenAvailable;
       
   416 		default:
       
   417 			return KLitCommReqUnsupported;
       
   418 		}
       
   419 	}
       
   420 #else
       
   421 EXPORT_C void TC32Log::Printf(TBool /* aStatic */, const TDesC8& /* aSubTag */, TRefByValue<const TDesC> /* aFmt */, ...)
       
   422 	{
       
   423 	
       
   424 	}
       
   425 EXPORT_C void TC32Log::Printf(TBool /* aStatic */, const TDesC8& /* aSubTag */, TRefByValue<const TDesC8> /* aFmt */, ...)
       
   426 	{
       
   427 	
       
   428 	}
       
   429 	
       
   430 #endif // __FLOG_ACTIVE
       
   431