From 51d6c4f5e0fbed3475133f193b6e8243b2a4c5af 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/subscriberRegistry/trunk@3165 19bc5d8c-e614-43d4-8b26-e1612bc8e597 --- SubscriberRegistry.cpp | 9 +++++++-- SubscriberRegistry.h | 7 ++++++- sipauthserve.cpp | 1 + srmanager.cpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/SubscriberRegistry.cpp b/SubscriberRegistry.cpp index cb6580e..e03ed74 100644 --- a/SubscriberRegistry.cpp +++ b/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,23 +160,28 @@ 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; } if (!getCLIDLocal("IMSI001010000000000")) { // This is a test SIM provided with the BTS. if (addUser("IMSI001010000000000", "2100") != SUCCESS) { LOG(EMERG) << "Cannot insert test SIM"; + return 1; } } + return 0; } diff --git a/SubscriberRegistry.h b/SubscriberRegistry.h index 17bd978..94c5812 100644 --- a/SubscriberRegistry.h +++ b/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/sipauthserve.cpp b/sipauthserve.cpp index d8e377a..8c1415d 100644 --- a/sipauthserve.cpp +++ b/sipauthserve.cpp @@ -213,6 +213,7 @@ main(int argc, char **argv) LOG(ALERT) << argv[0] << " (re)starting"; srand ( time(NULL) + (int)getpid() ); my_udp_port = gConfig.getNum("SubscriberRegistry.Port"); + gSubscriberRegistry.init(); // init osip lib osip_t *osip; diff --git a/srmanager.cpp b/srmanager.cpp index 83a56a4..e1587ab 100755 --- a/srmanager.cpp +++ b/srmanager.cpp @@ -237,7 +237,7 @@ void endHtml() int main(int argc, char **argv) { gLogInit("srmanager",gConfig.getStr("Log.Level").c_str(),LOG_LOCAL7); - gSubscriberRegistry = SubscriberRegistry(); + gSubscriberRegistry.init(); // start the html return initHtml(); // read the config file