diff --git a/services/tunnelbroker/rust-lib/src/lib.rs b/services/tunnelbroker/rust-lib/src/lib.rs --- a/services/tunnelbroker/rust-lib/src/lib.rs +++ b/services/tunnelbroker/rust-lib/src/lib.rs @@ -35,17 +35,12 @@ ) -> Result<()>; #[cxx_name = "sendNotifToAPNS"] fn send_notif_to_apns( - certificate_path: &str, - certificate_password: &str, device_token: &str, - topic: &str, message: &str, - sandbox: bool, ) -> Result; #[cxx_name = "sendNotifToFCM"] fn send_notif_to_fcm( - fcm_api_key: &str, device_registration_id: &str, message_title: &str, message_body: &str, @@ -82,31 +77,29 @@ } pub fn send_notif_to_apns( - certificate_path: &str, - certificate_password: &str, device_token: &str, - topic: &str, message: &str, - sandbox: bool, ) -> Result { + let notification_config = NOTIFICATIONS_CONFIG + .read() + .expect("Unable to open notifications configuration"); RUNTIME.block_on(notifications::apns::send_by_a2_client( - certificate_path, - certificate_password, + ¬ification_config.apns_certificate_path, + ¬ification_config.apns_certificate_password, device_token, - topic, + ¬ification_config.apns_topic, message, - sandbox, + notification_config.is_sandbox, )) } pub fn send_notif_to_fcm( - fcm_api_key: &str, device_registration_id: &str, message_title: &str, message_body: &str, ) -> Result { RUNTIME.block_on(notifications::fcm::send_by_fcm_client( - fcm_api_key, + &NOTIFICATIONS_CONFIG.read().unwrap().fcm_api_key, device_registration_id, message_title, message_body, diff --git a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp --- a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp +++ b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp @@ -173,16 +173,7 @@ typedef rust::notifications::apnsReturnStatus apnsReturnStatus; const apnsReturnStatus apnsResult = rust::notifications::sendNotifToAPNS( - config::ConfigManager::getInstance().getParameter( - config::ConfigManager::OPTION_NOTIFS_APNS_P12_CERT_PATH), - config::ConfigManager::getInstance().getParameter( - config::ConfigManager:: - OPTION_NOTIFS_APNS_P12_CERT_PASSWORD), - notifyToken, - config::ConfigManager::getInstance().getParameter( - config::ConfigManager::OPTION_NOTIFS_APNS_TOPIC), - notificationMessageText, - false); + notifyToken, notificationMessageText); if ((apnsResult == apnsReturnStatus::Unregistered || apnsResult == apnsReturnStatus::BadDeviceToken) && !database::DatabaseManager::getInstance() @@ -194,11 +185,7 @@ } else if (deviceOs == "Android" && !notifyToken.empty()) { typedef rust::notifications::fcmReturnStatus fcmReturnStatus; const fcmReturnStatus fcmResult = rust::notifications::sendNotifToFCM( - config::ConfigManager::getInstance().getParameter( - config::ConfigManager::OPTION_NOTIFS_FCM_SERVER_KEY), - notifyToken, - notificationMessageTitle, - notificationMessageText); + notifyToken, notificationMessageTitle, notificationMessageText); if ((fcmResult == fcmReturnStatus::InvalidRegistration || fcmResult == fcmReturnStatus::NotRegistered) && !database::DatabaseManager::getInstance() diff --git a/services/tunnelbroker/src/server.cpp b/services/tunnelbroker/src/server.cpp --- a/services/tunnelbroker/src/server.cpp +++ b/services/tunnelbroker/src/server.cpp @@ -1,9 +1,11 @@ #include "AmqpManager.h" #include "ConfigManager.h" +#include "GlobalConstants.h" #include "GlobalTools.h" #include "TunnelbrokerServiceImpl.h" -#include "GlobalConstants.h" +#include "rust-lib/src/lib.rs.h" +#include "rust/cxx.h" #include #include @@ -38,6 +40,18 @@ comm::network::tools::InitLogging("tunnelbroker"); comm::network::config::ConfigManager::getInstance().load(); comm::network::AmqpManager::getInstance().init(); + rust::notifications::init( + comm::network::config::ConfigManager::getInstance().getParameter( + comm::network::config::ConfigManager::OPTION_NOTIFS_FCM_SERVER_KEY), + comm::network::config::ConfigManager::getInstance().getParameter( + comm::network::config::ConfigManager:: + OPTION_NOTIFS_APNS_P12_CERT_PATH), + comm::network::config::ConfigManager::getInstance().getParameter( + comm::network::config::ConfigManager:: + OPTION_NOTIFS_APNS_P12_CERT_PASSWORD), + comm::network::config::ConfigManager::getInstance().getParameter( + comm::network::config::ConfigManager::OPTION_NOTIFS_APNS_TOPIC), + false); std::thread grpcThread(comm::network::RunServer); grpcThread.join(); return 0;