Skip to content

Commit

Permalink
Merge pull request #3 from dev-gh/am_policy_buildable
Browse files Browse the repository at this point in the history
Makes Application Manager and Policy buildable
Related-issues: APPLINK-22713, APPLINK-22716
  • Loading branch information
anosach-luxoft committed Apr 13, 2016
2 parents c93351b + 57e6b54 commit 1af193d
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 105 deletions.
76 changes: 37 additions & 39 deletions src/appMain/life_cycle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ LifeCycle::LifeCycle()
}

bool LifeCycle::StartComponents() {
LOG4CXX_AUTO_TRACE(logger_);
LOGGER_AUTO_TRACE(logger_);
DCHECK(!last_state_);
profile::Profile* profile = profile::Profile::instance();
last_state_ = new resumption::LastState(profile->app_storage_folder(),
Expand Down Expand Up @@ -124,7 +124,7 @@ bool LifeCycle::StartComponents() {

media_manager_ = new media_manager::MediaManagerImpl(*app_manager_, *profile);
if (!app_manager_->Init(*last_state_, media_manager_)) {
LOG4CXX_ERROR(logger_, "Application manager init failed.");
LOGGER_ERROR(logger_, "Application manager init failed.");
return false;
}

Expand All @@ -144,7 +144,7 @@ bool LifeCycle::StartComponents() {

app_manager_->AddPolicyObserver(crypto_manager_);
if (!crypto_manager_->Init()) {
LOG4CXX_ERROR(logger_, "CryptoManager initialization fail.");
LOGGER_ERROR(logger_, "CryptoManager initialization fail.");
return false;
}
#endif // ENABLE_SECURITY
Expand Down Expand Up @@ -189,7 +189,7 @@ bool LifeCycle::InitMessageSystem() {
DCHECK(!message_broker_)
message_broker_ = NsMessageBroker::CMessageBroker::getInstance();
if (!message_broker_) {
LOG4CXX_FATAL(logger_, " Wrong pMessageBroker pointer!");
LOGGER_FATAL(logger_, " Wrong pMessageBroker pointer!");
return false;
}

Expand All @@ -198,27 +198,27 @@ bool LifeCycle::InitMessageSystem() {
profile::Profile::instance()->server_port(),
message_broker_);
if (!message_broker_server_) {
LOG4CXX_FATAL(logger_, " Wrong pJSONRPC20Server pointer!");
LOGGER_FATAL(logger_, " Wrong pJSONRPC20Server pointer!");
return false;
}
message_broker_->startMessageBroker(message_broker_server_);
if (!networking::init()) {
LOG4CXX_FATAL(logger_, " Networking initialization failed!");
LOGGER_FATAL(logger_, " Networking initialization failed!");
return false;
}

if (!message_broker_server_->Bind()) {
LOG4CXX_FATAL(logger_, "Message broker server bind failed!");
LOGGER_FATAL(logger_, "Message broker server bind failed!");
return false;
} else {
LOG4CXX_INFO(logger_, "Message broker server bind successful!");
LOGGER_INFO(logger_, "Message broker server bind successful!");
}

if (!message_broker_server_->Listen()) {
LOG4CXX_FATAL(logger_, "Message broker server listen failed!");
LOGGER_FATAL(logger_, "Message broker server listen failed!");
return false;
} else {
LOG4CXX_INFO(logger_, " Message broker server listen successful!");
LOGGER_INFO(logger_, " Message broker server listen successful!");
}

mb_adapter_ = new hmi_message_handler::MessageBrokerAdapter(
Expand All @@ -228,11 +228,11 @@ bool LifeCycle::InitMessageSystem() {

hmi_handler_->AddHMIMessageAdapter(mb_adapter_);
if (!mb_adapter_->Connect()) {
LOG4CXX_FATAL(logger_, "Cannot connect to remote peer!");
LOGGER_FATAL(logger_, "Cannot connect to remote peer!");
return false;
}

LOG4CXX_INFO(logger_, "Start CMessageBroker thread!");
LOGGER_INFO(logger_, "Start CMessageBroker thread!");
mb_thread_ = new System::Thread(
new System::ThreadArgImpl<NsMessageBroker::CMessageBroker>(
*message_broker_,
Expand All @@ -243,7 +243,7 @@ bool LifeCycle::InitMessageSystem() {
// thread doesn't have valid Id to associate name with
NameMessageBrokerThread(*mb_thread_, "MessageBroker");

LOG4CXX_INFO(logger_, "Start MessageBroker TCP server thread!");
LOGGER_INFO(logger_, "Start MessageBroker TCP server thread!");
mb_server_thread_ =
new System::Thread(new System::ThreadArgImpl<NsMessageBroker::TcpServer>(
*message_broker_server_,
Expand All @@ -252,7 +252,7 @@ bool LifeCycle::InitMessageSystem() {
mb_server_thread_->Start(false);
NameMessageBrokerThread(*mb_server_thread_, "MB TCPServer");

LOG4CXX_INFO(logger_, "StartAppMgr JSONRPC 2.0 controller receiver thread!");
LOGGER_INFO(logger_, "StartAppMgr JSONRPC 2.0 controller receiver thread!");
mb_adapter_thread_ = new System::Thread(
new System::ThreadArgImpl<hmi_message_handler::MessageBrokerAdapter>(
*mb_adapter_,
Expand All @@ -277,13 +277,13 @@ bool LifeCycle::InitMessageSystem() {
hmi_message_handler::HMIMessageHandlerImpl::instance()->AddHMIMessageAdapter(
dbus_adapter_);
if (!dbus_adapter_->Init()) {
LOG4CXX_FATAL(logger_, "Cannot init DBus service!");
LOGGER_FATAL(logger_, "Cannot init DBus service!");
return false;
}

dbus_adapter_->SubscribeTo();

LOG4CXX_INFO(logger_, "Start DBusMessageAdapter thread!");
LOGGER_INFO(logger_, "Start DBusMessageAdapter thread!");
dbus_adapter_thread_ = new System::Thread(
new System::ThreadArgImpl<hmi_message_handler::DBusMessageAdapter>(
*dbus_adapter_,
Expand All @@ -310,35 +310,33 @@ namespace {
void sig_handler(int sig) {
switch (sig) {
case SIGINT:
LOG4CXX_DEBUG(logger_, "SIGINT signal has been caught");
LOGGER_DEBUG(logger_, "SIGINT signal has been caught");
break;
case SIGTERM:
LOG4CXX_DEBUG(logger_, "SIGTERM signal has been caught");
LOGGER_DEBUG(logger_, "SIGTERM signal has been caught");
break;
case SIGSEGV:
LOG4CXX_DEBUG(logger_, "SIGSEGV signal has been caught");
LOGGER_DEBUG(logger_, "SIGSEGV signal has been caught");
FLUSH_LOGGER();
// exit need to prevent endless sending SIGSEGV
// http://stackoverflow.com/questions/2663456/how-to-write-a-signal-handler-to-catch-sigsegv
abort();
default:
LOG4CXX_DEBUG(logger_, "Unexpected signal has been caught");
LOGGER_DEBUG(logger_, "Unexpected signal has been caught");
exit(EXIT_FAILURE);
}
}
} // namespace

void LifeCycle::Run() {
LOG4CXX_AUTO_TRACE(logger_);
// Register signal handlers and wait sys signals
// from OS
if (!utils::WaitTerminationSignals(&sig_handler)) {
LOG4CXX_FATAL(logger_, "Fail to catch system signal!");
}
LOGGER_AUTO_TRACE(logger_);
::utils::CreateSdlEvent();
::utils::SubscribeToTerminationSignals();
::utils::WaitForSdlExecute();
}

void LifeCycle::StopComponents() {
LOG4CXX_AUTO_TRACE(logger_);
LOGGER_AUTO_TRACE(logger_);

DCHECK_OR_RETURN_VOID(hmi_handler_);
hmi_handler_->set_message_observer(NULL);
Expand All @@ -352,56 +350,56 @@ void LifeCycle::StopComponents() {
DCHECK_OR_RETURN_VOID(app_manager_);
app_manager_->Stop();

LOG4CXX_INFO(logger_, "Stopping Protocol Handler");
LOGGER_INFO(logger_, "Stopping Protocol Handler");
DCHECK_OR_RETURN_VOID(protocol_handler_);
protocol_handler_->RemoveProtocolObserver(media_manager_);

#ifdef ENABLE_SECURITY
protocol_handler_->RemoveProtocolObserver(security_manager_);
if (security_manager_) {
security_manager_->RemoveListener(app_manager_);
LOG4CXX_INFO(logger_, "Destroying Crypto Manager");
LOGGER_INFO(logger_, "Destroying Crypto Manager");
delete crypto_manager_;
LOG4CXX_INFO(logger_, "Destroying Security Manager");
LOGGER_INFO(logger_, "Destroying Security Manager");
delete security_manager_;
}
#endif // ENABLE_SECURITY
protocol_handler_->Stop();

LOG4CXX_INFO(logger_, "Destroying Media Manager");
LOGGER_INFO(logger_, "Destroying Media Manager");
DCHECK_OR_RETURN_VOID(media_manager_);
media_manager_->SetProtocolHandler(NULL);
delete media_manager_;
media_manager_ = NULL;

LOG4CXX_INFO(logger_, "Destroying Transport Manager.");
LOGGER_INFO(logger_, "Destroying Transport Manager.");
DCHECK_OR_RETURN_VOID(transport_manager_);
transport_manager_->Visibility(false);
transport_manager_->Stop();
transport_manager::TransportManagerDefault::destroy();

LOG4CXX_INFO(logger_, "Stopping Connection Handler.");
LOGGER_INFO(logger_, "Stopping Connection Handler.");
DCHECK_OR_RETURN_VOID(connection_handler_);
connection_handler_->Stop();

LOG4CXX_INFO(logger_, "Destroying Protocol Handler");
LOGGER_INFO(logger_, "Destroying Protocol Handler");
DCHECK(protocol_handler_);
delete protocol_handler_;
protocol_handler_ = NULL;

LOG4CXX_INFO(logger_, "Destroying Connection Handler.");
LOGGER_INFO(logger_, "Destroying Connection Handler.");
delete connection_handler_;
connection_handler_ = NULL;

LOG4CXX_INFO(logger_, "Destroying Last State");
LOGGER_INFO(logger_, "Destroying Last State");
DCHECK(last_state_);
delete last_state_;
last_state_ = NULL;

LOG4CXX_INFO(logger_, "Destroying Application Manager.");
LOGGER_INFO(logger_, "Destroying Application Manager.");
application_manager::ApplicationManagerImpl::destroy();

LOG4CXX_INFO(logger_, "Destroying HMI Message Handler and MB adapter.");
LOGGER_INFO(logger_, "Destroying HMI Message Handler and MB adapter.");

#ifdef DBUS_HMIADAPTER
if (dbus_adapter_) {
Expand Down Expand Up @@ -438,7 +436,7 @@ void LifeCycle::StopComponents() {
delete hmi_handler_;
hmi_handler_ = NULL;

LOG4CXX_INFO(logger_, "Destroying Message Broker");
LOGGER_INFO(logger_, "Destroying Message Broker");
if (mb_server_thread_) {
mb_server_thread_->Stop();
mb_server_thread_->Join();
Expand Down
23 changes: 20 additions & 3 deletions src/appMain/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ bool InitHmi() {
return utils::System(kStartHmi).Execute();
}
#endif // QT_HMI

bool UnsibscribeFromTermination() {
// Disable some system signals receiving in thread
// by blocking those signals
// (system signals processes only in the main thread)
// Mustn't block all signals!
// See "Advanced Programming in the UNIX Environment, 3rd Edition"
// (http://poincare.matf.bg.ac.rs/~ivana//courses/ps/sistemi_knjige/pomocno/apue.pdf,
// "12.8. Threads and Signals".
sigset_t signal_set;
sigemptyset(&signal_set);
sigaddset(&signal_set, SIGINT);
sigaddset(&signal_set, SIGTERM);

return !pthread_sigmask(SIG_BLOCK, &signal_set, NULL);
}


}

/**
Expand All @@ -118,7 +136,7 @@ bool InitHmi() {
*/
int32_t main(int32_t argc, char** argv) {
// Unsibscribe once for all threads
if (!utils::UnsibscribeFromTermination()) {
if (!UnsibscribeFromTermination()) {
// Can't use internal logger here
exit(EXIT_FAILURE);
}
Expand All @@ -131,8 +149,7 @@ int32_t main(int32_t argc, char** argv) {
}

// Logger initialization
INIT_LOGGER("log4cxx.properties",
profile::Profile::instance()->logs_enabled());
INIT_LOGGER(profile::Profile::instance()->logs_enabled());

threads::Thread::SetNameForId(threads::Thread::CurrentId(), "MainThread");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CommandImpl : public Command {
bool allowed_to_terminate_;
#ifdef ENABLE_LOG
#if defined(OS_POSIX)
static logger::LoggerPtr logger_;
static log4cxx::LoggerPtr logger_;
#elif defined(OS_WINDOWS)
static std::string logger_;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "interfaces/MOBILE_API.h"
#include "json/json.h"
#include "utils/macro.h"
#include "utils/json_utils.h"

#include "application_manager/hmi_language_handler.h"

Expand Down Expand Up @@ -430,7 +431,7 @@ class HMICapabilities {
* @param languages - the converted object
*
*/
void convert_json_languages_to_obj(Json::Value& json_languages,
void convert_json_languages_to_obj(utils::json::JsonValueRef json_languages,
smart_objects::SmartObject& languages);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ DeviceTypes devicesType = {
std::make_pair(std::string("WIFI"), hmi_apis::Common_TransportType::WIFI)};
}

CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager")

uint32_t ApplicationManagerImpl::corelation_id_ = 0;
const uint32_t ApplicationManagerImpl::max_corelation_id_ = UINT_MAX;

Expand Down Expand Up @@ -2365,15 +2363,15 @@ void ApplicationManagerImpl::HeadUnitReset(
GetPolicyHandler().UnloadPolicyLibrary();

resume_controller().StopSavePersistentDataTimer();
file_system::remove_directory_content(
file_system::RemoveDirectoryContent(
profile::Profile::instance()->app_storage_folder());
break;
}
case mobile_api::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS: {
GetPolicyHandler().ClearUserConsent();

resume_controller().StopSavePersistentDataTimer();
file_system::remove_directory_content(
file_system::RemoveDirectoryContent(
profile::Profile::instance()->app_storage_folder());
break;
}
Expand Down Expand Up @@ -3127,7 +3125,7 @@ mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary(
uint64_t file_size = file_system::FileSize(full_file_path);
std::ofstream* file_stream;
if (offset != 0) {
if (file_size != offset) {
if (file_size != static_cast<uint64_t>(offset)) {
LOGGER_DEBUG(logger_,
"ApplicationManagerImpl::SaveBinaryWithOffset offset"
<< " does'n match existing file size");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void HMILanguageHandler::set_language_for(
LOGGER_DEBUG(logger_,
"Setting language " << language << " for interface "
<< interface);
last_state_->dictionary[LanguagesKey][key] = language;
last_state_->dictionary()[LanguagesKey][key] =
static_cast<utils::json::JsonValue::Int>(language);
return;
}

Expand All @@ -103,10 +104,10 @@ hmi_apis::Common_Language::eType HMILanguageHandler::get_language_for(
return Common_Language::INVALID_ENUM;
}

if (last_state_->dictionary.isMember(LanguagesKey)) {
if (last_state_->dictionary[LanguagesKey].isMember(key)) {
if (last_state_->dictionary().HasMember(LanguagesKey)) {
if (last_state_->dictionary()[LanguagesKey].HasMember(key)) {
Common_Language::eType language = static_cast<Common_Language::eType>(
last_state_->dictionary[LanguagesKey][key].asInt());
last_state_->dictionary()[LanguagesKey][key].AsInt());
return language;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ std::pair<std::string, VehicleDataType> kVehicleDataInitializer[] = {

const VehicleData MessageHelper::vehicle_data_(
kVehicleDataInitializer,
kVehicleDataInitializer + ARRAYSIZE(kVehicleDataInitializer));
kVehicleDataInitializer + GETARRAYSIZE(kVehicleDataInitializer));

#ifdef HMI_DBUS_API
namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ bool PolicyHandler::LoadPolicyLibrary() {
return NULL;
}

policy_library_.Load(kPolicyLibraryName);
policy_library_.Load(kLibrary.c_str());
if (policy_library_.IsLoaded()) {
if (CreateManager()) {
policy_manager_->set_listener(this);
event_observer_ = utils::MakeShared<PolicyEventObserver>(this);
}
} else {
LOGGER_ERROR(logger_, error);
LOGGER_ERROR(logger_, "Policy library loading error");
}
return policy_manager_.valid();
}
Expand Down
Loading

0 comments on commit 1af193d

Please sign in to comment.