Commit 6d3d788e authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update for support event inside MySQL class

parent e3ae3afc
......@@ -212,6 +212,16 @@ class database_wrapper : public database_wrapper_abstraction {
return derived->query_smf_select_data(ue_id, serving_plmn_id, json_data);
}
void start_event_connection_handling() {
auto derived = static_cast<DerivedT*>(this);
return derived->start_event_connection_handling();
}
void trigger_connection_handling_procedure(uint64_t ms) {
auto derived = static_cast<DerivedT*>(this);
return derived->trigger_connection_handling_procedure(ms);
}
protected:
};
} // namespace oai::udr::app
......
......@@ -41,15 +41,18 @@
#include "Snssai.h"
#include "logger.hpp"
#include "udr.h"
#include "udr_event.hpp"
namespace oai::udr::app {
class database_wrapper_abstraction {
public:
database_wrapper_abstraction(){};
database_wrapper_abstraction(udr_event& ev) : m_event_sub(ev){};
virtual ~database_wrapper_abstraction(){};
// virtual std::unique_ptr<database_wrapper_abstraction> clone() const = 0;
udr_event& m_event_sub;
/*
* Initialize the DB and establish the connection between UDR and the DB
* @param void
......@@ -289,6 +292,20 @@ class database_wrapper_abstraction {
virtual bool query_smf_select_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) = 0;
/*
* Start event connection handling procedure
* @param [void]
* @return void
*/
virtual void start_event_connection_handling() = 0;
/*
* Trigger connection handling procedure (kind of NF Heartbeat)
* @param [uint64_t] ms:
* @return void
*/
virtual void trigger_connection_handling_procedure(uint64_t ms) = 0;
};
} // namespace oai::udr::app
......
......@@ -42,10 +42,12 @@ using namespace oai::udr::config;
extern udr_config udr_cfg;
//------------------------------------------------------------------------------
mysql_db::mysql_db() : database_wrapper<mysql_db>() {}
mysql_db::mysql_db(udr_event& ev) : database_wrapper<mysql_db>(ev) {}
//------------------------------------------------------------------------------
mysql_db::~mysql_db() {}
mysql_db::~mysql_db() {
if (db_connection.connected()) db_connection.disconnect();
}
//------------------------------------------------------------------------------
bool mysql_db::initialize() {
......@@ -74,6 +76,42 @@ bool mysql_db::close_connection() {
return true;
}
//---------------------------------------------------------------------------------------------
void mysql_db::start_event_connection_manager() {
// get current time
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
struct itimerspec its;
its.it_value.tv_sec = DB_CONNECTION_TIMER; // seconds
its.it_value.tv_nsec = 0; // 100 * 1000 * 1000; //100ms
const uint64_t interval =
its.it_value.tv_sec * 1000 +
its.it_value.tv_nsec / 1000000; // convert sec, nsec to msec
db_connection = m_event_sub.subscribe_task_db_connection_manager(
boost::bind(
&mysql_db::trigger_connection_verification_procedure, this, _1),
interval, ms + interval);
}
//---------------------------------------------------------------------------------------------
void mysql_db::trigger_connection_verification_procedure(uint64_t ms) {
_unused(ms);
if (!mysql_real_connect(
&mysql_connector, udr_cfg.mysql.mysql_server.c_str(),
udr_cfg.mysql.mysql_user.c_str(), udr_cfg.mysql.mysql_pass.c_str(),
udr_cfg.mysql.mysql_db.c_str(), 0, 0, 0)) {
Logger::udr_mysql().error(
"An error occurred while connecting to MySQL DB: %s",
mysql_error(&mysql_connector));
// Reset the connection
close_connection();
initialize();
}
}
//------------------------------------------------------------------------------
bool mysql_db::insert_authentication_subscription(
const std::string& id,
......
......@@ -34,12 +34,13 @@
#include "Amf3GppAccessRegistration.h"
#include "database_wrapper.hpp"
#include "udr_event.hpp"
namespace oai::udr::app {
class mysql_db : public database_wrapper<mysql_db> {
public:
mysql_db();
mysql_db(udr_event& ev);
virtual ~mysql_db();
bool initialize();
......@@ -127,6 +128,7 @@ class mysql_db : public database_wrapper<mysql_db> {
private:
MYSQL mysql_connector;
bs2::connection db_connection;
};
} // namespace oai::udr::app
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment