imgtools/romtools/rofsbuild/symbolgenerator.cpp
author Ross Qin <ross.qin@nokia.com>
Fri, 29 Oct 2010 10:03:48 +0800
changeset 670 46ea84d14897
parent 664 44b0e894b7ab
permissions -rw-r--r--
remove migrated template meta data files (in DFS_MCL wk42)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     1
/*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     3
* All rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     4
* This component and the accompanying materials are made available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     6
* which accompanies this distribution, and is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     8
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
     9
* Initial Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    10
* Nokia Corporation - initial contribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    11
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    12
* Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    13
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    14
* Description: 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    15
*
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    16
*/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents: 600
diff changeset
    17
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    18
#include <vector>
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include <boost/regex.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#define MAX_LINE 65535
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "symbolgenerator.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include "e32image.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#if defined(__LINUX__)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#define PATH_SEPARATOR '/'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#define PATH_SEPARATOR '\\'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
#endif
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    29
extern TInt gThreadNum;
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
boost::mutex SymbolGenerator::iMutexSingleton;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
SymbolGenerator* SymbolGenerator::iInst = NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
SymbolGenerator* SymbolGenerator::GetInstance(){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
    iMutexSingleton.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
    if(iInst == NULL) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
        iInst = new SymbolGenerator();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
    iMutexSingleton.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
    return iInst;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
void SymbolGenerator::Release() {
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    42
    if(iInst != NULL) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    43
        iInst->join();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    44
    }
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
    iMutexSingleton.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
    if(iInst != NULL) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
        delete iInst;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
        iInst = NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
    iMutexSingleton.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
void SymbolGenerator::SetSymbolFileName( const string& fileName ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
    if(iSymFile.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
        iSymFile.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
    string s = fileName.substr(0,fileName.rfind('.'))+".symbol";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
    printf("* Writing %s - ROFS symbol file\n", s.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
    iSymFile.open(s.c_str());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
void SymbolGenerator::AddFile( const string& fileName, bool isExecutable ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
    iMutex.lock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
    iQueueFiles.push(TPlacedEntry(fileName,isExecutable));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
    iMutex.unlock();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
    iCond.notify_all();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
}
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    65
void SymbolGenerator::SetFinished() 
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    66
{ 
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    68
	iFinished = true; 
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    69
	iCond.notify_all();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    71
TPlacedEntry SymbolGenerator::GetNextPlacedEntry()
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    72
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    73
	TPlacedEntry pe("", false);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    74
	if(1)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    75
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    76
		boost::mutex::scoped_lock lock(iMutex);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    77
		while(!iFinished && iQueueFiles.empty())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    78
			iCond.wait(lock);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    79
		if(!iQueueFiles.empty())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    80
		{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    81
			pe = iQueueFiles.front();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    82
			iQueueFiles.pop();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    85
	return pe;
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
}
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    87
void SymbolGenerator::thrd_func(){
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    88
    	boost::thread_group threads;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    89
	SymbolWorker worker;
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    90
    	for(int i=0; i < gThreadNum; i++)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    91
    	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    92
    		threads.create_thread(worker);
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    94
    	threads.join_all();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    95
        }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    96
SymbolGenerator::SymbolGenerator() : boost::thread(thrd_func),iFinished(false) {
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    97
    }
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    98
SymbolGenerator::~SymbolGenerator(){
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
    99
    if(joinable())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   100
        join();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   101
    iSymFile.flush();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   102
    iSymFile.close();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
            }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   104
SymbolWorker::SymbolWorker()
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   105
{
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
        // end of regex_search
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   108
SymbolWorker::~SymbolWorker()
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   109
{
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   111
void SymbolWorker::operator()()
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   112
{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   113
	SymbolProcessUnit* aSymbolProcessUnit = new CommenSymbolProcessUnit();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   114
	SymbolGenerator* symbolgenerator = SymbolGenerator::GetInstance();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   116
	while(1)
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   117
	{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   118
		if(symbolgenerator->HasFinished() && symbolgenerator->IsEmpty())
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   119
		{
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   120
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
                break;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
                    }
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   123
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   124
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   125
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   127
		TPlacedEntry pe = symbolgenerator->GetNextPlacedEntry();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
            //scope the code block with if(1) for lock
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
            /*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
            if(me->iQueueFiles.empty()) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
                boost::this_thread::sleep(boost::posix_time::milliseconds(10));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
                continue;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
            }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
            */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
        if(pe.iFileName == "")
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   139
			continue;
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
        else if(pe.iExecutable) 
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   141
			aSymbolProcessUnit->ProcessExecutableFile(pe.iFileName);
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
        else
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   143
			aSymbolProcessUnit->ProcessDataFile(pe.iFileName);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   144
		symbolgenerator->LockOutput();
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   145
		aSymbolProcessUnit->FlushStdOut(cout);
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   146
		aSymbolProcessUnit->FlushSymbolContent(symbolgenerator->GetOutputFileStream());
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   147
		symbolgenerator->UnlockOutput();
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
}
654
7c11c3d8d025 romtools 13.2.0.1
Zheng Shen <zheng.shen@nokia.com>
parents: 600
diff changeset
   149
	delete aSymbolProcessUnit;
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
}