Commit bff0ba48 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup

parent 9dd80b75
......@@ -34,9 +34,6 @@
#include "udr-api-server.h"
#include "logger.hpp"
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <signal.h>
#include <unistd.h>
......
......@@ -44,6 +44,8 @@
#include <vector>
#endif
#define PISTACHE_SERVER_MAX_PAYLOAD 32768
#include "AMF3GPPAccessRegistrationDocumentApiImpl.h"
#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"
#include "AuthenticationStatusDocumentApiImpl.h"
......
......@@ -25,9 +25,6 @@
#include "logger.hpp"
#include "options.hpp"
#include "pid_file.hpp"
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#include "udr-api-server.h"
#include "udr_app.hpp"
#include "udr_config.hpp"
......
......@@ -31,15 +31,6 @@
#include <mysql/mysql.h>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/time_formatters.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <chrono>
#include "AccessAndMobilitySubscriptionData.h"
#include "AuthenticationSubscription.h"
#include "ProblemDetails.h"
......@@ -49,7 +40,6 @@
using namespace oai::udr::app;
using namespace oai::udr::model;
using namespace std::chrono;
using namespace config;
extern udr_app *udr_app_inst;
......
#include "udr_server.hpp"
#include "logger.hpp"
#ifdef __linux__
static void sigHandler [[noreturn]] (int sig) {
switch (sig) {
case SIGINT:
case SIGQUIT:
case SIGTERM:
case SIGHUP:
default:
// m_httpEndpoint->shutdown();
break;
}
exit(0);
}
static void setUpUnixSignals(std::vector<int> quitSignals) {
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals) sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = sigHandler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals) sigaction(sig, &sa, nullptr);
}
#endif
using namespace org::openapitools::server::api;
UDRApiServer::UDRApiServer(Pistache::Address address, MYSQL *mysql)
: m_httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(address)) {
m_router = std::make_shared<Pistache::Rest::Router>();
m_AuthenticationSubscriptionDocumentApiserver =
std::make_shared<AuthenticationSubscriptionDocumentApiImpl>(m_router,
mysql);
m_AuthenticationStatusDocumentApiserver =
std::make_shared<AuthenticationStatusDocumentApiImpl>(m_router, mysql);
m_AccessAndMobilitySubscriptionDataDocumentApiserver =
std::make_shared<AccessAndMobilitySubscriptionDataDocumentApiImpl>(
m_router, mysql);
m_SMFSelectionSubscriptionDataDocumentApiserver =
std::make_shared<SMFSelectionSubscriptionDataDocumentApiImpl>(m_router,
mysql);
m_SessionManagementSubscriptionDataApiserver =
std::make_shared<SessionManagementSubscriptionDataApiImpl>(m_router,
mysql);
m_AMF3GPPAccessRegistrationDocumentApiserver =
std::make_shared<AMF3GPPAccessRegistrationDocumentApiImpl>(m_router,
mysql);
m_SMFRegistrationDocumentApiserver =
std::make_shared<SMFRegistrationDocumentApiImpl>(m_router, mysql);
m_SMFRegistrationsCollectionApiserver =
std::make_shared<SMFRegistrationsCollectionApiImpl>(m_router, mysql);
m_SDMSubscriptionDocumentApiserver =
std::make_shared<SDMSubscriptionDocumentApiImpl>(m_router, mysql);
m_SDMSubscriptionsCollectionApiserver =
std::make_shared<SDMSubscriptionsCollectionApiImpl>(m_router, mysql);
}
void UDRApiServer::init(size_t thr) {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
auto opts = Pistache::Http::Endpoint::options().threads(thr);
opts.flags(Pistache::Tcp::Options::ReuseAddr);
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
m_httpEndpoint->init(opts);
m_AuthenticationSubscriptionDocumentApiserver->init();
m_AuthenticationStatusDocumentApiserver->init();
m_AccessAndMobilitySubscriptionDataDocumentApiserver->init();
m_SMFSelectionSubscriptionDataDocumentApiserver->init();
m_SessionManagementSubscriptionDataApiserver->init();
m_AMF3GPPAccessRegistrationDocumentApiserver->init();
m_SMFRegistrationDocumentApiserver->init();
m_SMFRegistrationsCollectionApiserver->init();
m_SDMSubscriptionDocumentApiserver->init();
m_SDMSubscriptionsCollectionApiserver->init();
Logger::udr_server().debug("Initiate UDR server endpoints done!");
}
void UDRApiServer::start() {
if (m_AuthenticationSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
if (m_AuthenticationStatusDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationStatusDocumentApiImpl");
if (m_AccessAndMobilitySubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AccessAndMobilitySubscriptionDataDocumentApiImpl");
if (m_SMFSelectionSubscriptionDataDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFSelectionSubscriptionDataDocumentApiImpl");
if (m_SessionManagementSubscriptionDataApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SessionManagementSubscriptionDataApiImpl");
if (m_AMF3GPPAccessRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AMF3GPPAccessRegistrationDocumentApiImpl");
if (m_SMFRegistrationDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SMFRegistrationsCollectionApiImpl");
if (m_SMFRegistrationsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionDocumentApiImpl");
if (m_SDMSubscriptionDocumentApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for SDMSubscriptionsCollectionApiImpl");
if (m_SDMSubscriptionsCollectionApiserver != nullptr)
Logger::udr_server().debug(
"UDR handler for AuthenticationSubscriptionDocumentApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve();
}
void UDRApiServer::shutdown() { m_httpEndpoint->shutdown(); }
#ifndef _UDR_SERVER_H_
#define _UDR_SERVER_H_
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include "pistache/router.h"
#ifdef __linux__
#include <signal.h>
#include <unistd.h>
#include <vector>
#endif
#include "AMF3GPPAccessRegistrationDocumentApiImpl.h"
#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"
#include "AuthenticationStatusDocumentApiImpl.h"
#include "AuthenticationSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionDocumentApiImpl.h"
#include "SDMSubscriptionsCollectionApiImpl.h"
#include "SMFRegistrationDocumentApiImpl.h"
#include "SMFRegistrationsCollectionApiImpl.h"
#include "SMFSelectionSubscriptionDataDocumentApiImpl.h"
#include "SessionManagementSubscriptionDataApiImpl.h"
#include <mysql/mysql.h>
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
using namespace org::openapitools::server::api;
class UDRApiServer {
public:
UDRApiServer(Pistache::Address address, MYSQL *mysql);
void init(size_t thr = 1);
void start();
void shutdown();
private:
std::shared_ptr<Pistache::Http::Endpoint> m_httpEndpoint;
std::shared_ptr<Pistache::Rest::Router> m_router;
std::shared_ptr<AuthenticationSubscriptionDocumentApiImpl>
m_AuthenticationSubscriptionDocumentApiserver;
std::shared_ptr<AuthenticationStatusDocumentApiImpl>
m_AuthenticationStatusDocumentApiserver;
std::shared_ptr<AccessAndMobilitySubscriptionDataDocumentApiImpl>
m_AccessAndMobilitySubscriptionDataDocumentApiserver;
std::shared_ptr<SMFSelectionSubscriptionDataDocumentApiImpl>
m_SMFSelectionSubscriptionDataDocumentApiserver;
std::shared_ptr<SessionManagementSubscriptionDataApiImpl>
m_SessionManagementSubscriptionDataApiserver;
std::shared_ptr<AMF3GPPAccessRegistrationDocumentApiImpl>
m_AMF3GPPAccessRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationDocumentApiImpl>
m_SMFRegistrationDocumentApiserver;
std::shared_ptr<SMFRegistrationsCollectionApiImpl>
m_SMFRegistrationsCollectionApiserver;
std::shared_ptr<SDMSubscriptionDocumentApiImpl>
m_SDMSubscriptionDocumentApiserver;
std::shared_ptr<SDMSubscriptionsCollectionApiImpl>
m_SDMSubscriptionsCollectionApiserver;
};
#endif
\ No newline at end of file
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