Commit 10c9bccf authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup/polish

parent 709b6f4d
...@@ -32,7 +32,7 @@ NRF = ...@@ -32,7 +32,7 @@ NRF =
IPV4_ADDRESS = "read"; IPV4_ADDRESS = "read";
PORT = @NRF_INTERFACE_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE (default: 80) PORT = @NRF_INTERFACE_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE (default: 80)
HTTP2_PORT = @NRF_INTERFACE_HTTP2_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE HTTP2_PORT = @NRF_INTERFACE_HTTP2_PORT_FOR_SBI@; # YOUR NETWORK CONFIG HERE
API_VERSION = "@NRF_API_VERSION@"; # YOUR NRF API VERSION CONFIG HERE API_VERSION = "@NRF_API_VERSION@"; # YOUR NRF API VERSION CONFIG HERE
}; };
}; };
......
...@@ -14,23 +14,23 @@ ...@@ -14,23 +14,23 @@
* limitations under the License. * limitations under the License.
*/ */
#include "nrf_app.hpp" #include "logger.hpp"
#include "nrf-api-server.h" #include "nrf-api-server.h"
#include "nrf_app.hpp"
#include "nrf_client.hpp"
#include "options.hpp" #include "options.hpp"
#include "pid_file.hpp" #include "pid_file.hpp"
#include "logger.hpp"
#include "nrf_client.hpp"
#include "pistache/endpoint.h" #include "pistache/endpoint.h"
#include "pistache/http.h" #include "pistache/http.h"
#include "pistache/router.h" #include "pistache/router.h"
#include <iostream>
#include <thread>
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> // srand #include <stdlib.h> // srand
#include <unistd.h> // get_pid(), pause() #include <unistd.h> // get_pid(), pause()
#include <iostream>
#include <thread>
using namespace oai::nrf::app; using namespace oai::nrf::app;
using namespace util; using namespace util;
...@@ -42,7 +42,6 @@ NRFApiServer *api_server = nullptr; ...@@ -42,7 +42,6 @@ NRFApiServer *api_server = nullptr;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void my_app_signal_handler(int s) { void my_app_signal_handler(int s) {
std::cout << "Caught signal " << s << std::endl; std::cout << "Caught signal " << s << std::endl;
Logger::system().startup("exiting"); Logger::system().startup("exiting");
std::cout << "Freeing Allocated memory..." << std::endl; std::cout << "Freeing Allocated memory..." << std::endl;
...@@ -51,12 +50,14 @@ void my_app_signal_handler(int s) { ...@@ -51,12 +50,14 @@ void my_app_signal_handler(int s) {
delete api_server; delete api_server;
api_server = nullptr; api_server = nullptr;
} }
std::cout << "NRF API Server memory done" << std::endl;
std::cout << "NRF API Server memory done." << std::endl; if (nrf_app_inst) {
if (nrf_app_inst)
delete nrf_app_inst; delete nrf_app_inst;
nrf_app_inst = nullptr; nrf_app_inst = nullptr;
std::cout << "NRF APP memory done." << std::endl; }
std::cout << "NRF APP memory done" << std::endl;
std::cout << "Freeing allocated memory done" << std::endl; std::cout << "Freeing allocated memory done" << std::endl;
exit(0); exit(0);
...@@ -64,18 +65,17 @@ void my_app_signal_handler(int s) { ...@@ -64,18 +65,17 @@ void my_app_signal_handler(int s) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand (time(NULL)); srand(time(NULL));
// Command line options // Command line options
if ( !Options::parse( argc, argv ) ) if (!Options::parse(argc, argv)) {
{
std::cout << "Options::parse() failed" << std::endl; std::cout << "Options::parse() failed" << std::endl;
return 1; return 1;
} }
// Logger // Logger
Logger::init( "nrf" , Options::getlogStdout() , Options::getlogRotFilelog()); Logger::init("nrf", Options::getlogStdout(), Options::getlogRotFilelog());
Logger::nrf_app().startup( "Options parsed" ); Logger::nrf_app().startup("Options parsed");
struct sigaction sigIntHandler; struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_app_signal_handler; sigIntHandler.sa_handler = my_app_signal_handler;
...@@ -87,26 +87,28 @@ if ( !Options::parse( argc, argv ) ) ...@@ -87,26 +87,28 @@ if ( !Options::parse( argc, argv ) )
nrf_cfg.load(Options::getlibconfigConfig()); nrf_cfg.load(Options::getlibconfigConfig());
nrf_cfg.display(); nrf_cfg.display();
//Event subsystem // Event subsystem
nrf_event ev; nrf_event ev;
// NRF application layer // NRF application layer
nrf_app_inst = new nrf_app(Options::getlibconfigConfig(), ev); nrf_app_inst = new nrf_app(Options::getlibconfigConfig(), ev);
//Task Manager // Task Manager
task_manager tm(ev); task_manager tm(ev);
std::thread task_manager_thread(&task_manager::run, &tm); std::thread task_manager_thread(&task_manager::run, &tm);
// PID file // PID file
// Currently hard-coded value. TODO: add as config option. // Currently hard-coded value. TODO: add as config option.
string pid_file_name = get_exe_absolute_path("/var/run", nrf_cfg.instance); string pid_file_name = get_exe_absolute_path("/var/run", nrf_cfg.instance);
if (! is_pid_file_lock_success(pid_file_name.c_str())) { if (!is_pid_file_lock_success(pid_file_name.c_str())) {
Logger::nrf_app().error( "Lock PID file %s failed\n", pid_file_name.c_str()); Logger::nrf_app().error("Lock PID file %s failed\n", pid_file_name.c_str());
exit (-EDEADLK); exit(-EDEADLK);
} }
//NRF Pistache API server (HTTP1) // NRF Pistache API server (HTTP1)
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&nrf_cfg.sbi.addr4))) , Pistache::Port(nrf_cfg.sbi.port)); Pistache::Address addr(
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))),
Pistache::Port(nrf_cfg.sbi.port));
api_server = new NRFApiServer(addr, nrf_app_inst); api_server = new NRFApiServer(addr, nrf_app_inst);
api_server->init(2); api_server->init(2);
std::thread nrf_manager(&NRFApiServer::start, api_server); std::thread nrf_manager(&NRFApiServer::start, api_server);
......
...@@ -42,6 +42,7 @@ static std::size_t callback(const char *in, std::size_t size, std::size_t num, ...@@ -42,6 +42,7 @@ static std::size_t callback(const char *in, std::size_t size, std::size_t num,
out->append(in, totalBytes); out->append(in, totalBytes);
return totalBytes; return totalBytes;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool send_curl(std::string url) { bool send_curl(std::string url) {
long httpCode = {0}; long httpCode = {0};
...@@ -74,15 +75,12 @@ bool send_curl(std::string url) { ...@@ -74,15 +75,12 @@ bool send_curl(std::string url) {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, NF_CURL_TIMEOUT_MS); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, NF_CURL_TIMEOUT_MS);
std::unique_ptr<std::string> httpData(new std::string()); std::unique_ptr<std::string> httpData(new std::string());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length()); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
...@@ -90,6 +88,7 @@ bool send_curl(std::string url) { ...@@ -90,6 +88,7 @@ bool send_curl(std::string url) {
curl_global_cleanup(); curl_global_cleanup();
} }
//------------------------------------------------------------------------------
void send_curl_multi(std::string url, uint32_t n) { void send_curl_multi(std::string url, uint32_t n) {
int still_running = 0, numfds = 0, res = 0, msgs_left = 0; int still_running = 0, numfds = 0, res = 0, msgs_left = 0;
CURLMsg *curl_msg = nullptr; CURLMsg *curl_msg = nullptr;
...@@ -199,6 +198,7 @@ void send_curl_multi(std::string url, uint32_t n) { ...@@ -199,6 +198,7 @@ void send_curl_multi(std::string url, uint32_t n) {
curl_global_cleanup(); curl_global_cleanup();
curl_slist_free_all(headers); curl_slist_free_all(headers);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool cont = false; bool cont = false;
...@@ -208,7 +208,7 @@ int main(int argc, char *argv[]) { ...@@ -208,7 +208,7 @@ int main(int argc, char *argv[]) {
std::string type = "Content-Type: application/json"; std::string type = "Content-Type: application/json";
std::string url = "http://192.168.1.23:8080/nnrf-nfm/v1/subscriptions"; std::string url = "http://192.168.1.23:8080/nnrf-nfm/v1/subscriptions";
// send_curl(url); // send_curl(url);
uint32_t number_subscriptions = 200; uint32_t number_subscriptions = 100;
std::cout << "Number of subscriptions: " << number_subscriptions << std::endl; std::cout << "Number of subscriptions: " << number_subscriptions << std::endl;
std::cout << "Sending..." << std::endl; std::cout << "Sending..." << std::endl;
send_curl_multi(url, number_subscriptions); send_curl_multi(url, number_subscriptions);
......
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