655
|
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 |
|
654
|
18 |
#include <vector>
|
600
|
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
|
654
|
29 |
extern TInt gThreadNum;
|
600
|
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() {
|
654
|
42 |
if(iInst != NULL) {
|
|
43 |
iInst->join();
|
|
44 |
}
|
600
|
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 |
}
|
654
|
65 |
void SymbolGenerator::SetFinished()
|
|
66 |
{
|
600
|
67 |
|
654
|
68 |
iFinished = true;
|
|
69 |
iCond.notify_all();
|
600
|
70 |
}
|
654
|
71 |
TPlacedEntry SymbolGenerator::GetNextPlacedEntry()
|
|
72 |
{
|
662
|
73 |
if(regex_search(fileName, what, regARMV5)) {
|
654
|
74 |
TPlacedEntry pe("", false);
|
|
75 |
if(1)
|
662
|
76 |
else if(regex_search(fileName, what, regGCCEoARMV4)) {
|
654
|
77 |
{
|
|
78 |
boost::mutex::scoped_lock lock(iMutex);
|
|
79 |
while(!iFinished && iQueueFiles.empty())
|
|
80 |
iCond.wait(lock);
|
|
81 |
if(!iQueueFiles.empty())
|
|
82 |
{
|
|
83 |
pe = iQueueFiles.front();
|
|
84 |
iQueueFiles.pop();
|
600
|
85 |
}
|
|
86 |
}
|
654
|
87 |
return pe;
|
600
|
88 |
}
|
654
|
89 |
void SymbolGenerator::thrd_func(){
|
|
90 |
boost::thread_group threads;
|
|
91 |
SymbolWorker worker;
|
|
92 |
for(int i=0; i < gThreadNum; i++)
|
|
93 |
{
|
|
94 |
threads.create_thread(worker);
|
600
|
95 |
}
|
654
|
96 |
threads.join_all();
|
|
97 |
}
|
|
98 |
SymbolGenerator::SymbolGenerator() : boost::thread(thrd_func),iFinished(false) {
|
|
99 |
}
|
|
100 |
SymbolGenerator::~SymbolGenerator(){
|
|
101 |
if(joinable())
|
|
102 |
join();
|
|
103 |
iSymFile.flush();
|
|
104 |
iSymFile.close();
|
600
|
105 |
}
|
654
|
106 |
SymbolWorker::SymbolWorker()
|
|
107 |
{
|
600
|
108 |
// end of regex_search
|
|
109 |
}
|
654
|
110 |
SymbolWorker::~SymbolWorker()
|
|
111 |
{
|
600
|
112 |
}
|
654
|
113 |
void SymbolWorker::operator()()
|
|
114 |
{
|
|
115 |
SymbolProcessUnit* aSymbolProcessUnit = new CommenSymbolProcessUnit();
|
|
116 |
SymbolGenerator* symbolgenerator = SymbolGenerator::GetInstance();
|
600
|
117 |
|
654
|
118 |
while(1)
|
|
119 |
{
|
|
120 |
if(symbolgenerator->HasFinished() && symbolgenerator->IsEmpty())
|
|
121 |
{
|
|
122 |
|
600
|
123 |
break;
|
662
|
124 |
if(!regex_search(sLibFile, what1, reg)) {
|
|
125 |
if(regex_search(sLibFile, what, reg3)) {
|
600
|
126 |
}
|
654
|
127 |
|
|
128 |
|
|
129 |
|
600
|
130 |
|
654
|
131 |
TPlacedEntry pe = symbolgenerator->GetNextPlacedEntry();
|
600
|
132 |
|
|
133 |
//scope the code block with if(1) for lock
|
|
134 |
/*
|
|
135 |
if(me->iQueueFiles.empty()) {
|
|
136 |
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
|
137 |
continue;
|
|
138 |
}
|
|
139 |
*/
|
|
140 |
|
|
141 |
|
|
142 |
if(pe.iFileName == "")
|
654
|
143 |
continue;
|
600
|
144 |
else if(pe.iExecutable)
|
654
|
145 |
aSymbolProcessUnit->ProcessExecutableFile(pe.iFileName);
|
600
|
146 |
else
|
654
|
147 |
aSymbolProcessUnit->ProcessDataFile(pe.iFileName);
|
|
148 |
symbolgenerator->LockOutput();
|
|
149 |
aSymbolProcessUnit->FlushStdOut(cout);
|
|
150 |
aSymbolProcessUnit->FlushSymbolContent(symbolgenerator->GetOutputFileStream());
|
|
151 |
symbolgenerator->UnlockOutput();
|
600
|
152 |
}
|
654
|
153 |
delete aSymbolProcessUnit;
|
600
|
154 |
}
|