libraries/qr3/src/openfilesListboxdata.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // openfilesListboxdata.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 #include "KernLbxModel.h"
       
    13 #include "Utils.h"
       
    14 #include <fshell/clogger.h>
       
    15 #include <fshell/memoryaccess.h>
       
    16 
       
    17 COpenFilesListBoxData::COpenFilesListBoxData(CKernListBoxModel* aModel)
       
    18 	: CKernListBoxData(aModel)
       
    19 	{
       
    20 	}
       
    21 
       
    22 void COpenFilesListBoxData::DoFormatL(TObjectKernelInfo* aInfo, RBuf& name, RBuf& more, TInt& /*itemId*/)
       
    23 	{
       
    24 	SOpenFile& info = *reinterpret_cast<SOpenFile*>(aInfo);
       
    25 
       
    26 	if (info.iNumThreads)
       
    27 		{
       
    28 		if (info.iNumThreads > 1)
       
    29 			{
       
    30 			more.Format(_L("(%i) "), info.iNumThreads);
       
    31 			}
       
    32 		
       
    33 		RThread t;
       
    34 		TInt err = Model().MemAccess().RThreadForceOpen(t, info.iThreadIds[0]);
       
    35 		if (err)
       
    36 			{
       
    37 			more.AppendFormat(_L("Thread Id: %i err: %i"), TUint(info.iThreadIds[0]), err);
       
    38 			}
       
    39 		else
       
    40 			{
       
    41 			name.Copy(t.FullName()); // Reuse 'name' here, saves allocating another buffer
       
    42 			t.Close();
       
    43 			PrettyName(EListThread, name);
       
    44 			more.Append(name);
       
    45 			}
       
    46 		}
       
    47 	name.Copy(info.iName);
       
    48 	}
       
    49 
       
    50 void COpenFilesListBoxData::DumpToCloggerL(RClogger& clogger, TInt i, TInt /*count*/)
       
    51 	{
       
    52 	_LIT(KFileDesc,"OpenFile;Name;ThreadId;ThreadName");
       
    53 	_LIT(KFileFmt, "OpenFile;%S;%i;%S");
       
    54 
       
    55 	if (i == 0) clogger.Log(KFileDesc);
       
    56 	SOpenFile& info = *reinterpret_cast<SOpenFile*>(iInfo);
       
    57 	RBuf val;
       
    58 	val.CreateL(256);
       
    59 	for (TInt j = 0; j < Min(info.iNumThreads, info.iThreadIds.Count()); j++)
       
    60 		{
       
    61 		val.Zero();
       
    62 		RThread t;
       
    63 		TInt err = t.Open(info.iThreadIds[j]);
       
    64 		if (err)
       
    65 			{
       
    66 			val.Format(_L("Err: %i"), err);
       
    67 			}
       
    68 		else
       
    69 			{
       
    70 			val.Copy(t.FullName());
       
    71 			}
       
    72 		t.Close();
       
    73 		clogger.Log(KFileFmt, &info.iName, TUint(info.iThreadIds[j]), &val);
       
    74 		}
       
    75 	val.Close();
       
    76 	}
       
    77 
       
    78 void COpenFilesListBoxData::DoInfoForDialogL(RBuf& aTitle, RBuf& inf, TDes* name)
       
    79 	{
       
    80 	inf.ReAllocL(1024); // Maybe need a bit more room for file list
       
    81 	SOpenFile& info = *reinterpret_cast<SOpenFile*>(iInfo);
       
    82 	_LIT(KInfo, "%i thread(s) using this file");
       
    83 	aTitle.Format(KInfo, info.iNumThreads);
       
    84 
       
    85 	inf.Append(info.iName);
       
    86 	inf.Append('\n');
       
    87 	inf.Append('\n');
       
    88 	for (TInt i = 0; i < Min(info.iNumThreads, info.iThreadIds.Count()); i++)
       
    89 		{
       
    90 		RThread t;
       
    91 		TInt err = t.Open(info.iThreadIds[i]);
       
    92 		if (err)
       
    93 			{
       
    94 			name->Format(_L("Couldn't open thread: %i"), err);
       
    95 			}
       
    96 		else
       
    97 			{
       
    98 			name->Copy(t.FullName());
       
    99 			}
       
   100 		t.Close();
       
   101 		inf.AppendFormat(_L("Thread ID: %i\n%S\n\n"), TUint(info.iThreadIds[i]), name);
       
   102 		}
       
   103 	TInt numTruncated = info.iNumThreads - info.iThreadIds.Count();
       
   104 	if (numTruncated > 0)
       
   105 		{
       
   106 		inf.AppendFormat(_L("And %i other thread(s)...\n\n"), numTruncated);
       
   107 		}
       
   108 	}