1 /* |
|
2 * Copyright (c) 2010 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <vector> |
|
19 #include <boost/regex.hpp> |
|
20 #define MAX_LINE 65535 |
|
21 #include "symbolgenerator.h" |
|
22 #include "e32image.h" |
|
23 |
|
24 #if defined(__LINUX__) |
|
25 #define PATH_SEPARATOR '/' |
|
26 #else |
|
27 #define PATH_SEPARATOR '\\' |
|
28 #endif |
|
29 extern TInt gThreadNum; |
|
30 |
|
31 boost::mutex SymbolGenerator::iMutexSingleton; |
|
32 SymbolGenerator* SymbolGenerator::iInst = NULL; |
|
33 SymbolGenerator* SymbolGenerator::GetInstance(){ |
|
34 iMutexSingleton.lock(); |
|
35 if(iInst == NULL) { |
|
36 iInst = new SymbolGenerator(); |
|
37 } |
|
38 iMutexSingleton.unlock(); |
|
39 return iInst; |
|
40 } |
|
41 void SymbolGenerator::Release() { |
|
42 if(iInst != NULL) { |
|
43 iInst->join(); |
|
44 } |
|
45 iMutexSingleton.lock(); |
|
46 if(iInst != NULL) { |
|
47 delete iInst; |
|
48 iInst = NULL; |
|
49 } |
|
50 iMutexSingleton.unlock(); |
|
51 } |
|
52 void SymbolGenerator::SetSymbolFileName( const string& fileName ){ |
|
53 if(iSymFile.is_open()) |
|
54 iSymFile.close(); |
|
55 string s = fileName.substr(0,fileName.rfind('.'))+".symbol"; |
|
56 printf("* Writing %s - ROFS symbol file\n", s.c_str()); |
|
57 iSymFile.open(s.c_str()); |
|
58 } |
|
59 void SymbolGenerator::AddFile( const string& fileName, bool isExecutable ){ |
|
60 iMutex.lock(); |
|
61 iQueueFiles.push(TPlacedEntry(fileName,isExecutable)); |
|
62 iMutex.unlock(); |
|
63 iCond.notify_all(); |
|
64 } |
|
65 void SymbolGenerator::SetFinished() |
|
66 { |
|
67 |
|
68 iFinished = true; |
|
69 iCond.notify_all(); |
|
70 } |
|
71 TPlacedEntry SymbolGenerator::GetNextPlacedEntry() |
|
72 { |
|
73 TPlacedEntry pe("", false); |
|
74 if(1) |
|
75 { |
|
76 boost::mutex::scoped_lock lock(iMutex); |
|
77 while(!iFinished && iQueueFiles.empty()) |
|
78 iCond.wait(lock); |
|
79 if(!iQueueFiles.empty()) |
|
80 { |
|
81 pe = iQueueFiles.front(); |
|
82 iQueueFiles.pop(); |
|
83 } |
|
84 } |
|
85 return pe; |
|
86 } |
|
87 void SymbolGenerator::thrd_func(){ |
|
88 boost::thread_group threads; |
|
89 SymbolWorker worker; |
|
90 for(int i=0; i < gThreadNum; i++) |
|
91 { |
|
92 threads.create_thread(worker); |
|
93 } |
|
94 threads.join_all(); |
|
95 } |
|
96 SymbolGenerator::SymbolGenerator() : boost::thread(thrd_func),iFinished(false) { |
|
97 } |
|
98 SymbolGenerator::~SymbolGenerator(){ |
|
99 if(joinable()) |
|
100 join(); |
|
101 iSymFile.flush(); |
|
102 iSymFile.close(); |
|
103 } |
|
104 SymbolWorker::SymbolWorker() |
|
105 { |
|
106 // end of regex_search |
|
107 } |
|
108 SymbolWorker::~SymbolWorker() |
|
109 { |
|
110 } |
|
111 void SymbolWorker::operator()() |
|
112 { |
|
113 SymbolProcessUnit* aSymbolProcessUnit = new CommenSymbolProcessUnit(); |
|
114 SymbolGenerator* symbolgenerator = SymbolGenerator::GetInstance(); |
|
115 |
|
116 while(1) |
|
117 { |
|
118 if(symbolgenerator->HasFinished() && symbolgenerator->IsEmpty()) |
|
119 { |
|
120 |
|
121 break; |
|
122 } |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 TPlacedEntry pe = symbolgenerator->GetNextPlacedEntry(); |
|
128 |
|
129 //scope the code block with if(1) for lock |
|
130 /* |
|
131 if(me->iQueueFiles.empty()) { |
|
132 boost::this_thread::sleep(boost::posix_time::milliseconds(10)); |
|
133 continue; |
|
134 } |
|
135 */ |
|
136 |
|
137 |
|
138 if(pe.iFileName == "") |
|
139 continue; |
|
140 else if(pe.iExecutable) |
|
141 aSymbolProcessUnit->ProcessExecutableFile(pe.iFileName); |
|
142 else |
|
143 aSymbolProcessUnit->ProcessDataFile(pe.iFileName); |
|
144 symbolgenerator->LockOutput(); |
|
145 aSymbolProcessUnit->FlushStdOut(cout); |
|
146 aSymbolProcessUnit->FlushSymbolContent(symbolgenerator->GetOutputFileStream()); |
|
147 symbolgenerator->UnlockOutput(); |
|
148 } |
|
149 delete aSymbolProcessUnit; |
|
150 } |
|