From a1609072d79d0e573761246e73fd4eab7937ce76 Mon Sep 17 00:00:00 2001 From: Kurtis Heimerl Date: Fri, 10 Feb 2012 01:45:41 +0000 Subject: [PATCH] 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 --- CLI/CLI.cpp | 3 +-- CLI/CLI.h | 2 +- Control/TMSITable.cpp | 6 ++++-- Control/TMSITable.h | 7 ++++++- Control/TransactionTable.cpp | 4 ++-- Control/TransactionTable.h | 5 ++--- GSM/GSMConfig.cpp | 9 +++++++-- GSM/GSMConfig.h | 6 ++---- GSM/PhysicalStatus.cpp | 6 ++++-- GSM/PhysicalStatus.h | 5 +++-- SR/SubscriberRegistry.cpp | 8 ++++++-- SR/SubscriberRegistry.h | 7 ++++++- apps/OpenBTS.cpp | 11 +++++++++-- 13 files changed, 53 insertions(+), 26 deletions(-) diff --git a/CLI/CLI.cpp b/CLI/CLI.cpp index c368d84..a6ddda3 100644 --- a/CLI/CLI.cpp +++ b/CLI/CLI.cpp @@ -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"); diff --git a/CLI/CLI.h b/CLI/CLI.h index f403282..8f4c126 100644 --- a/CLI/CLI.h +++ b/CLI/CLI.h @@ -51,7 +51,7 @@ class Parser { public: - Parser(); + void addCommands(); /** Process a command line. diff --git a/Control/TMSITable.cpp b/Control/TMSITable.cpp index aa93a85..dcb6452 100644 --- a/Control/TMSITable.cpp +++ b/Control/TMSITable.cpp @@ -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; } diff --git a/Control/TMSITable.h b/Control/TMSITable.h index 5d0eb3c..839991d 100644 --- a/Control/TMSITable.h +++ b/Control/TMSITable.h @@ -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(); diff --git a/Control/TransactionTable.cpp b/Control/TransactionTable.cpp index 0577b32..3c1bf05 100644 --- a/Control/TransactionTable.cpp +++ b/Control/TransactionTable.cpp @@ -550,10 +550,10 @@ bool TransactionEntry::terminationRequested() -TransactionTable::TransactionTable() +void TransactionTable::init() // This assumes the main application uses sdevrandom. - :mIDCounter(random()) { + mIDCounter = random(); } diff --git a/Control/TransactionTable.h b/Control/TransactionTable.h index 5d16bc6..d997575 100644 --- a/Control/TransactionTable.h +++ b/Control/TransactionTable.h @@ -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(); diff --git a/GSM/GSMConfig.cpp b/GSM/GSMConfig.cpp index 246b320..4c8743c 100644 --- a/GSM/GSMConfig.cpp +++ b/GSM/GSMConfig.cpp @@ -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(); } diff --git a/GSM/GSMConfig.h b/GSM/GSMConfig.h index 19d1da8..f8db5a0 100644 --- a/GSM/GSMConfig.h +++ b/GSM/GSMConfig.h @@ -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(); diff --git a/GSM/PhysicalStatus.cpp b/GSM/PhysicalStatus.cpp index e4dbe62..bddb30a 100644 --- a/GSM/PhysicalStatus.cpp +++ b/GSM/PhysicalStatus.cpp @@ -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() diff --git a/GSM/PhysicalStatus.h b/GSM/PhysicalStatus.h index a1d11b4..2945416 100644 --- a/GSM/PhysicalStatus.h +++ b/GSM/PhysicalStatus.h @@ -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(); diff --git a/SR/SubscriberRegistry.cpp b/SR/SubscriberRegistry.cpp index 82b79e1..541b566 100644 --- a/SR/SubscriberRegistry.cpp +++ b/SR/SubscriberRegistry.cpp @@ -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; } diff --git a/SR/SubscriberRegistry.h b/SR/SubscriberRegistry.h index b802758..e11e0e4 100644 --- a/SR/SubscriberRegistry.h +++ b/SR/SubscriberRegistry.h @@ -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 diff --git a/apps/OpenBTS.cpp b/apps/OpenBTS.cpp index 5947683..ff215bf 100644 --- a/apps/OpenBTS.cpp +++ b/apps/OpenBTS.cpp @@ -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;