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
This commit is contained in:
parent
c508a0ff0c
commit
51d6c4f5e0
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue