|
1 // friendlynames.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 |
|
13 #include <fshell/ltkutils.h> |
|
14 |
|
15 EXPORT_C void LtkUtils::GetFriendlyThreadName(RThread aThread, TFullName& aFriendly) |
|
16 { |
|
17 aFriendly = aThread.FullName(); |
|
18 MakeThreadNameFriendly(aFriendly); |
|
19 } |
|
20 |
|
21 _LIT(KDoubleColon, "::"); |
|
22 _LIT(KMain, "main"); |
|
23 _LIT(KExtExe, ".exe"); |
|
24 |
|
25 const static TInt KProcessUidLength = 8; |
|
26 const static TInt KProcessSequenceLength = 4; |
|
27 const static TInt KProcessSuffixLength = 2+KProcessUidLength+KProcessSequenceLength; // including [] |
|
28 |
|
29 EXPORT_C void LtkUtils::MakeThreadNameFriendly(TFullName& aFullThreadName) |
|
30 { |
|
31 TInt colonPos = aFullThreadName.Find(KDoubleColon); |
|
32 TBool removeThreadName = EFalse; |
|
33 TBool haveExeExt = EFalse; |
|
34 |
|
35 if (colonPos==KErrNotFound) return; |
|
36 if (colonPos < KProcessSuffixLength) return; |
|
37 if (aFullThreadName[colonPos-KProcessSuffixLength] != '[') return; |
|
38 if (aFullThreadName[colonPos-KProcessSequenceLength-1] != ']') return; |
|
39 |
|
40 TPtrC sequenceNoStr(aFullThreadName.Mid(colonPos-KProcessSequenceLength, KProcessSequenceLength)); |
|
41 TLex lex(sequenceNoStr); |
|
42 TInt sequenceNo; |
|
43 if (lex.Val(sequenceNo)!=KErrNone) return; |
|
44 if (lex.Remainder().Length()!=0) return; |
|
45 |
|
46 // see if the thread name is 'main' |
|
47 TPtrC threadName(aFullThreadName.Mid(colonPos+2)); |
|
48 if (threadName.CompareF(KMain)==0) |
|
49 { |
|
50 removeThreadName = ETrue; |
|
51 } |
|
52 |
|
53 // see if we have a .exe extension on the process |
|
54 TPtrC processName(aFullThreadName.Left(colonPos - KProcessSuffixLength)); |
|
55 if (processName.Right(KExtExe().Length()).CompareF(KExtExe)==0) |
|
56 { |
|
57 haveExeExt = ETrue; |
|
58 processName.Set(processName.Left(processName.Length() - KExtExe().Length())); |
|
59 } |
|
60 if (processName.CompareF(threadName)==0) |
|
61 { |
|
62 removeThreadName = ETrue; |
|
63 } |
|
64 |
|
65 // we have now finished examining the name - remove from things from it |
|
66 // starting from the end, so that we don't screw up the indices we're |
|
67 // about to use. |
|
68 |
|
69 if (removeThreadName) |
|
70 { |
|
71 aFullThreadName.SetLength(colonPos); // remove :: and thread name |
|
72 } |
|
73 |
|
74 // delete the process suffix |
|
75 aFullThreadName.Delete(colonPos-KProcessSuffixLength, KProcessSuffixLength); |
|
76 if (sequenceNo>1) |
|
77 { |
|
78 TBuf<7> sequenceStr; |
|
79 sequenceStr.AppendFormat(_L("(%d)"), sequenceNo); |
|
80 aFullThreadName.Insert(colonPos-KProcessSuffixLength, sequenceStr); |
|
81 } |
|
82 |
|
83 if (haveExeExt) |
|
84 { |
|
85 aFullThreadName.Delete(colonPos-KProcessSuffixLength-KExtExe().Length(), KExtExe().Length()); |
|
86 } |
|
87 } |
|
88 |
|
89 EXPORT_C void LtkUtils::GetFriendlyProcessName(const RProcess& aProcess, TDes& aFriendly) |
|
90 { |
|
91 aFriendly = aProcess.FullName(); |
|
92 MakeProcessNameFriendly(aFriendly); |
|
93 } |
|
94 |
|
95 |
|
96 EXPORT_C void LtkUtils::MakeProcessNameFriendly(TDes& aFullProcessName) |
|
97 { |
|
98 TInt colonPos = aFullProcessName.Length(); |
|
99 TBool haveExeExt = EFalse; |
|
100 |
|
101 if (colonPos==KErrNotFound) return; |
|
102 if (colonPos < KProcessSuffixLength) return; |
|
103 if (aFullProcessName[colonPos-KProcessSuffixLength] != '[') return; |
|
104 if (aFullProcessName[colonPos-KProcessSequenceLength-1] != ']') return; |
|
105 |
|
106 TPtrC sequenceNoStr(aFullProcessName.Mid(colonPos-KProcessSequenceLength, KProcessSequenceLength)); |
|
107 TLex lex(sequenceNoStr); |
|
108 TInt sequenceNo; |
|
109 if (lex.Val(sequenceNo)!=KErrNone) return; |
|
110 if (lex.Remainder().Length()!=0) return; |
|
111 |
|
112 // see if we have a .exe extension on the process |
|
113 TPtrC processName(aFullProcessName.Left(colonPos - KProcessSuffixLength)); |
|
114 if (processName.Right(KExtExe().Length()).CompareF(KExtExe)==0) |
|
115 { |
|
116 haveExeExt = ETrue; |
|
117 processName.Set(processName.Left(processName.Length() - KExtExe().Length())); |
|
118 } |
|
119 |
|
120 // we have now finished examining the name - remove from things from it |
|
121 // starting from the end, so that we don't screw up the indices we're |
|
122 // about to use. |
|
123 |
|
124 // delete the process suffix |
|
125 aFullProcessName.Delete(colonPos-KProcessSuffixLength, KProcessSuffixLength); |
|
126 if (sequenceNo>1) |
|
127 { |
|
128 TBuf<7> sequenceStr; |
|
129 sequenceStr.AppendFormat(_L("(%d)"), sequenceNo); |
|
130 aFullProcessName.Insert(colonPos-KProcessSuffixLength, sequenceStr); |
|
131 } |
|
132 |
|
133 if (haveExeExt) |
|
134 { |
|
135 aFullProcessName.Delete(colonPos-KProcessSuffixLength-KExtExe().Length(), KExtExe().Length()); |
|
136 } |
|
137 } |