mirror of
https://github.com/RangeNetworks/openbts.git
synced 2025-11-03 21:33:15 +00:00
Brandon Creighton's patch: A lot of refactoring, but separates global object creation from initialization. Allows for logging of database initialization failures.
git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@3165 19bc5d8c-e614-43d4-8b26-e1612bc8e597
This commit is contained in:
@@ -734,9 +734,8 @@ int noise(int argc, char** argv, ostream& os, istream& is)
|
||||
|
||||
|
||||
|
||||
Parser::Parser()
|
||||
void Parser::addCommands()
|
||||
{
|
||||
// The constructor adds the commands.
|
||||
addCommand("uptime", uptime, "-- show BTS uptime and BTS frame number.");
|
||||
addCommand("help", showHelp, "[command] -- list available commands or gets help on a specific command.");
|
||||
addCommand("exit", exit_function, "[wait] -- exit the application, either immediately, or waiting for existing calls to clear with a timeout in seconds");
|
||||
|
||||
@@ -51,7 +51,7 @@ class Parser {
|
||||
|
||||
public:
|
||||
|
||||
Parser();
|
||||
void addCommands();
|
||||
|
||||
/**
|
||||
Process a command line.
|
||||
|
||||
@@ -63,18 +63,20 @@ static const char* createTMSITable = {
|
||||
|
||||
|
||||
|
||||
TMSITable::TMSITable(const char* wPath)
|
||||
int TMSITable::open(const char* wPath)
|
||||
{
|
||||
int rc = sqlite3_open(wPath,&mDB);
|
||||
if (rc) {
|
||||
LOG(EMERG) << "Cannot open TMSITable database at " << wPath << ": " << sqlite3_errmsg(mDB);
|
||||
sqlite3_close(mDB);
|
||||
mDB = NULL;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if (!sqlite3_command(mDB,createTMSITable)) {
|
||||
LOG(EMERG) << "Cannot create TMSI table";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,12 @@ class TMSITable {
|
||||
|
||||
public:
|
||||
|
||||
TMSITable(const char*wPath);
|
||||
/**
|
||||
Open the database connection.
|
||||
@param wPath Path to sqlite3 database file.
|
||||
@return 0 if the database was successfully opened and initialized; 1 otherwise
|
||||
*/
|
||||
int open(const char* wPath);
|
||||
|
||||
~TMSITable();
|
||||
|
||||
|
||||
@@ -550,10 +550,10 @@ bool TransactionEntry::terminationRequested()
|
||||
|
||||
|
||||
|
||||
TransactionTable::TransactionTable()
|
||||
void TransactionTable::init()
|
||||
// This assumes the main application uses sdevrandom.
|
||||
:mIDCounter(random())
|
||||
{
|
||||
mIDCounter = random();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -305,10 +305,9 @@ class TransactionTable {
|
||||
public:
|
||||
|
||||
/**
|
||||
Create a transaction table.
|
||||
@param path Path fto sqlite3 database file.
|
||||
Initialize thetransaction table with a random mIDCounter value.
|
||||
*/
|
||||
TransactionTable();
|
||||
void init();
|
||||
|
||||
~TransactionTable();
|
||||
|
||||
|
||||
@@ -37,11 +37,16 @@ using namespace GSM;
|
||||
|
||||
|
||||
GSMConfig::GSMConfig()
|
||||
:mBand((GSMBand)gConfig.getNum("GSM.Radio.Band")),
|
||||
:
|
||||
mSI5Frame(UNIT_DATA),mSI6Frame(UNIT_DATA),
|
||||
mT3122(gConfig.getNum("GSM.Timer.T3122Min")),
|
||||
mStartTime(::time(NULL))
|
||||
{
|
||||
}
|
||||
|
||||
void GSMConfig::init()
|
||||
{
|
||||
mBand = (GSMBand)gConfig.getNum("GSM.Radio.Band");
|
||||
mT3122 = gConfig.getNum("GSM.Timer.T3122Min");
|
||||
regenerateBeacon();
|
||||
}
|
||||
|
||||
|
||||
@@ -117,10 +117,8 @@ class GSMConfig {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/** All parameters come from gConfig. */
|
||||
GSMConfig();
|
||||
/** Initialize with parameters from gConfig. */
|
||||
void init();
|
||||
|
||||
/** Start the internal control loops. */
|
||||
void start();
|
||||
|
||||
@@ -62,18 +62,20 @@ static const char* createPhysicalStatus = {
|
||||
")"
|
||||
};
|
||||
|
||||
PhysicalStatus::PhysicalStatus(const char* wPath)
|
||||
int PhysicalStatus::open(const char* wPath)
|
||||
{
|
||||
int rc = sqlite3_open(wPath, &mDB);
|
||||
if (rc) {
|
||||
LOG(EMERG) << "Cannot open PhysicalStatus database at " << wPath << ": " << sqlite3_errmsg(mDB);
|
||||
sqlite3_close(mDB);
|
||||
mDB = NULL;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if (!sqlite3_command(mDB, createPhysicalStatus)) {
|
||||
LOG(EMERG) << "Cannot create TMSI table";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PhysicalStatus::~PhysicalStatus()
|
||||
|
||||
@@ -56,10 +56,11 @@ private:
|
||||
public:
|
||||
|
||||
/**
|
||||
Create a physical status reporting table.
|
||||
Initialize a physical status reporting table.
|
||||
@param path Path fto sqlite3 database file.
|
||||
@return 0 if the database was successfully opened and initialized; 1 otherwise
|
||||
*/
|
||||
PhysicalStatus(const char*wPath);
|
||||
int open(const char*wPath);
|
||||
|
||||
~PhysicalStatus();
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ static const char* createSBTable = {
|
||||
};
|
||||
|
||||
|
||||
SubscriberRegistry::SubscriberRegistry()
|
||||
int SubscriberRegistry::init()
|
||||
{
|
||||
string ldb = gConfig.getStr("SubscriberRegistry.db");
|
||||
int rc = sqlite3_open(ldb.c_str(),&mDB);
|
||||
@@ -160,17 +160,21 @@ SubscriberRegistry::SubscriberRegistry()
|
||||
LOG(EMERG) << "Cannot open SubscriberRegistry database: " << sqlite3_errmsg(mDB);
|
||||
sqlite3_close(mDB);
|
||||
mDB = NULL;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
if (!sqlite3_command(mDB,createRRLPTable)) {
|
||||
LOG(EMERG) << "Cannot create RRLP table";
|
||||
return 1;
|
||||
}
|
||||
if (!sqlite3_command(mDB,createDDTable)) {
|
||||
LOG(EMERG) << "Cannot create DIALDATA_TABLE table";
|
||||
return 1;
|
||||
}
|
||||
if (!sqlite3_command(mDB,createSBTable)) {
|
||||
LOG(EMERG) << "Cannot create SIP_BUDDIES table";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,9 +46,14 @@ class SubscriberRegistry {
|
||||
|
||||
public:
|
||||
|
||||
SubscriberRegistry();
|
||||
~SubscriberRegistry();
|
||||
|
||||
/**
|
||||
Initialize the subscriber registry using parameters from gConfig.
|
||||
@return 0 if the database was successfully opened and initialized; 1 otherwise
|
||||
*/
|
||||
int init();
|
||||
|
||||
typedef enum {
|
||||
SUCCESS=0, ///< operation successful
|
||||
FAILURE=1, ///< operation not successful
|
||||
|
||||
@@ -75,13 +75,13 @@ const char* gDateTime = __DATE__ " " __TIME__;
|
||||
// be declared here.
|
||||
|
||||
// The TMSI Table.
|
||||
Control::TMSITable gTMSITable(gConfig.getStr("Control.Reporting.TMSITable").c_str());
|
||||
Control::TMSITable gTMSITable;
|
||||
|
||||
// The transaction table.
|
||||
Control::TransactionTable gTransactionTable;
|
||||
|
||||
// Physical status reporting
|
||||
GSM::PhysicalStatus gPhysStatus(gConfig.getStr("Control.Reporting.PhysStatusTable").c_str());
|
||||
GSM::PhysicalStatus gPhysStatus;
|
||||
|
||||
// The global SIPInterface object.
|
||||
SIP::SIPInterface gSIPInterface;
|
||||
@@ -148,6 +148,13 @@ int main(int argc, char *argv[])
|
||||
LOG(ALERT) << "OpenBTS starting, ver " << VERSION << " build date " << __DATE__;
|
||||
|
||||
COUT("\n\n" << gOpenBTSWelcome << "\n");
|
||||
gTMSITable.open(gConfig.getStr("Control.Reporting.TMSITable").c_str());
|
||||
gTransactionTable.init();
|
||||
gPhysStatus.open(gConfig.getStr("Control.Reporting.PhysStatusTable").c_str());
|
||||
gBTS.init();
|
||||
gSubscriberRegistry.init();
|
||||
gParser.addCommands();
|
||||
|
||||
COUT("\nStarting the system...");
|
||||
|
||||
Thread transceiverThread;
|
||||
|
||||
Reference in New Issue
Block a user