Skip to content

Commit

Permalink
Awc contenerization (#1509)
Browse files Browse the repository at this point in the history
* Rebased on top of latest master

* 21500-added-notifyserviceready-to-awclistener

* 33819-LISA-not-starting-up-properly

* adding license headers to AWCImplementation.cpp and AWCImplementation.h

* adding license headers to AWCImplementation.cpp, AWCImplementation.h, FindLibGio.cmake, FindLibGioUnix.cmake, FindLibGlib.cmake and FindLibGobject.cmake

* removing api.c and api.h

* removed cstdint from BaseRefCount.h

* added copyright of LibertyGlobal in NOTICE file, added modification header in BaseRefCount.h

* added copyright of LibertyGlobal in NOTICE file

* added ../Module.h i.s.o core/Sync.h in BaseRefCount.h
  • Loading branch information
shelmy-shabu-infosys authored Mar 14, 2024
1 parent 7988266 commit 9723f99
Show file tree
Hide file tree
Showing 22 changed files with 1,848 additions and 361 deletions.
5 changes: 5 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ listed below. Your use of this material within the component is also subject to
conditions of these licenses. The LICENSE file contains the text of all the licenses which apply
within this component.

Files under the implementations directory are:
Copyright Liberty Global B.V.
Licensed under the Apache License, Version 2.0
unless otherwise noted.

Copyright (c) 2008-2013 Kristian Hogsberg
Copyright © 2013 Rafael Antognolli
Copyright © 2013 Jasper St. Pierre
Expand Down
22 changes: 21 additions & 1 deletion Source/extensions/processcontainers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ elseif(PROCESSCONTAINERS_CLIB)
elseif(PROCESSCONTAINERS_DOBBY)
target_sources(${TARGET} PRIVATE implementations/DobbyImplementation/DobbyImplementation.cpp)
elseif(PROCESSCONTAINERS_AWC)
target_sources(${TARGET} PRIVATE implementations/AWCImplementation/AWCImplementation.cpp)
target_sources(
${TARGET} PRIVATE
implementations/AWCImplementation/AWC.cpp
implementations/AWCImplementation/AWCContainerAdministrator.cpp
implementations/AWCImplementation/AWCContainerBase.cpp
implementations/AWCImplementation/AWCImplementation.cpp
implementations/AWCImplementation/AWCProxyContainer.cpp
implementations/AWCImplementation/dbus/Client.cpp
implementations/AWCImplementation/dbus/api.c)
endif()

set(PUBLIC_HEADERS
Expand Down Expand Up @@ -116,15 +124,27 @@ elseif (PROCESSCONTAINERS_DOBBY)
elseif (PROCESSCONTAINERS_AWC)
find_package(LXC REQUIRED)
find_package(Slauncher REQUIRED)
find_package(LibGio REQUIRED)
find_package(LibGioUnix REQUIRED)
find_package(LibGlib REQUIRED)
find_package(LibGobject REQUIRED)
target_link_libraries(${TARGET}
PRIVATE
Slauncher::Slauncher
CompileSettingsDebug::CompileSettingsDebug
${LIBGIO_INCLUDE_LIBRARIES}
${LIBGIOUNIX_LIBRARIES}
${LIBGLIB_LIBRARIES}
${LIBGOBJECT_LIBRARIES}
)

target_include_directories( ${TARGET}
PRIVATE
Slauncher::Slauncher
${LIBGIO_INCLUDE_DIRS}
${LIBGIOUNIX_INCLUDE_DIRS}
${LIBGLIB_INCLUDE_DIRS}
${LIBGOBJECT_INCLUDE_DIRS}
)
endif()

Expand Down
9 changes: 9 additions & 0 deletions Source/extensions/processcontainers/common/BaseRefCount.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Modifications are Copyright 2024 Liberty Global B.V.
* Licensed under the Apache License, Version 2.0
*/

/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
Expand All @@ -19,6 +24,10 @@

#pragma once



#include "../Module.h"

namespace WPEFramework {
namespace ProcessContainers {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "AWC.h"

#include <algorithm>

#include "Tracing.h"


using namespace WPEFramework::ProcessContainers;


AWCStateChangeNotifier::AWCStateChangeNotifier() : _listeners(), _mutex() {};

void AWCStateChangeNotifier::addListener(AWCStateChangeListener * listener)
{
if (!listener) return;
std::lock_guard<std::mutex> lock(_mutex);
if (std::find(_listeners.begin(), _listeners.end(), listener) == _listeners.end())
{
_listeners.push_back(listener);
}
else
{
TRACE_L1("%s listener already registrered %p", __FUNCTION__, listener);
}
}

void AWCStateChangeNotifier::removeListener(AWCStateChangeListener * listener)
{
std::lock_guard<std::mutex> lock(_mutex);
_listeners.erase(std::remove(_listeners.begin(), _listeners.end(), listener), _listeners.end());
}

void AWCStateChangeNotifier::notify(int req_id, awc::awc_app_state_t app_state, int status, unsigned int pid)
{
std::lock_guard<std::mutex> lock(_mutex);
for (auto listener : _listeners)
{
listener->notifyStateChange(req_id, app_state, status, pid);
}
}

AWCListener::AWCListener(AWCStateChangeNotifier * notifier)
: _notifier(notifier)
{}

void AWCListener::notifyWindowChange(int window_id, awc::AWCClient::awc_window_state_t window_state, unsigned int pid)
{
// intentionally left empty
}

void AWCListener::notifyStateChange(int req_id, awc::awc_app_state_t app_state, int status, unsigned int pid)
{
TRACE_L3("%s req_id=%d app_state=%d status=%d pid=%u", _TRACE_FUNCTION_, req_id, app_state, status, pid);
_notifier->notify(req_id, app_state, status, pid);
}

void AWCListener::notifyServiceReady()
{
TRACE_L3("%s", _TRACE_FUNCTION_);
// no action
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <mutex>

#include <AWCClient.h>

namespace WPEFramework {
namespace ProcessContainers {


class AWCStateChangeListener {
public:
virtual void notifyStateChange(int req_id, awc::awc_app_state_t app_state, int status, unsigned int pid) = 0;
};

class AWCStateChangeNotifier {
public:
AWCStateChangeNotifier();
void addListener(AWCStateChangeListener * listener);
void removeListener(AWCStateChangeListener * listener);
void notify(int req_id, awc::awc_app_state_t app_state, int status, unsigned int pid);
private:
std::vector<AWCStateChangeListener *> _listeners;
std::mutex _mutex;
};

class AWCListener : public awc::AWCClient::Listener
{
public:
AWCListener(AWCStateChangeNotifier * notifier);
~AWCListener() {};
void notifyWindowChange(int window_id, awc::AWCClient::awc_window_state_t window_state, unsigned int pid) override;
void notifyStateChange(int req_id, awc::awc_app_state_t app_state, int status, unsigned int pid) override;
void notifyServiceReady();
private:
AWCStateChangeNotifier * _notifier;
};

} /* ProcessContainers */
} /* WPEFramework */
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <algorithm>

#include "AWCContainerAdministrator.h"
#include "AWCImplementation.h"
#include "AWCProxyContainer.h"
#include "processcontainers/Tracing.h"

using namespace WPEFramework::ProcessContainers;
using namespace WPEFramework::Core;


PluginConfig::PluginConfig(const std::string &path):
JSON::Container()
{
Core::JSON::String useProxyValue;
Core::JSON::DecUInt32 startTimeoutValue{10 * 1000};
Core::JSON::DecUInt32 stopTimeoutValue{10 * 1000};

Add(_T("awc_container"), &useProxyValue);
Add(_T("start_timeout"), &startTimeoutValue);
Add(_T("stop_timeout"), &stopTimeoutValue);

if(path.empty()) return;

OptionalType<JSON::Error> error;
FromString(path, error);

if(error.IsSet())
{
TRACE_L1(
"Parsing %s failed with %s",
path.c_str(), ErrorDisplayMessage(error.Value()).c_str());
}

using namespace std::chrono;

if(useProxyValue == _T("proxy")) useProxy = true;
startTimeout = milliseconds{startTimeoutValue.Value()};
stopTimeout = milliseconds{stopTimeoutValue.Value()};

Remove(_T("awc_container"));
Remove(_T("start_timeout"));
Remove(_T("stop_timeout"));
}

AWCContainerAdministrator::AWCContainerAdministrator()
: BaseContainerAdministrator()
{
TRACE_L1("%p", this);
awcClient_ = awc::AWCClient::getInstance();
if (awcClient_) {
awcClientListener_ = std::make_shared<AWCListener>(this);
awcClient_->setListener(awcClientListener_);
}
}

AWCContainerAdministrator::~AWCContainerAdministrator()
{
TRACE_L1("%p", this);
if (awcClient_ && awcClientListener_) {
awcClient_->removeListener(awcClientListener_);
}
}

IContainer* AWCContainerAdministrator::Container(
const string& name,
IStringIterator& searchpaths,
const string& containerLogDir,
const string& configuration)
{
std::string config = configuration;

// logs dont like multi line strings
std::replace_if(
std::begin(config), std::end(config),
[](char c){return '\n' == c;}, ' ');

TRACE_L1(
"(%p) callsign=%s, logDir=%s, config=%s",
this, name.c_str(), containerLogDir.c_str(), config.c_str());

const PluginConfig cfg{configuration};

IContainer* container = Get(name);
const auto append = !container;

if(!container && cfg.useProxy)
{
container = new AWCProxyContainer(name, cfg, &dbusClient_);
}
else if(!container)
{
container = new AWCContainer(name, awcClient_, this);
}
if(append)
{
this->InternalLock();
InsertContainer(container);
this->InternalUnlock();
}

if(!container) TRACE_L1("not supported container type: %s", name.c_str());
return container;
}

IContainerAdministrator& IContainerAdministrator::Instance()
{
static AWCContainerAdministrator& myAWCContainerAdministrator = Core::SingletonType<AWCContainerAdministrator>::Instance();
return myAWCContainerAdministrator;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <mutex>
#include <vector>


#include "AWC.h"
#include "dbus/Client.h"
#include "processcontainers/common/BaseAdministrator.h"
#include "core/JSON.h"

namespace WPEFramework {
namespace ProcessContainers {

struct PluginConfig: public Core::JSON::Container
{
bool useProxy{false};
std::chrono::milliseconds startTimeout;
std::chrono::milliseconds stopTimeout;

PluginConfig(const PluginConfig&) = delete;
PluginConfig& operator=(const PluginConfig&) = delete;
PluginConfig(const std::string &path);
};


class AWCContainerAdministrator:
public BaseContainerAdministrator<IContainer>,
public AWCStateChangeNotifier
{
friend class AWCContainer;
friend class Core::SingletonType<AWCContainerAdministrator>;
private:
awc::AWCClient * awcClient_;
std::shared_ptr<AWCListener> awcClientListener_;
dbus::Client dbusClient_;
AWCContainerAdministrator();
public:
AWCContainerAdministrator(const AWCContainerAdministrator&) = delete;
AWCContainerAdministrator& operator=(const AWCContainerAdministrator&) = delete;
~AWCContainerAdministrator() override;
IContainer* Container(const string& name, IStringIterator& searchpaths, const string& containerLogDir, const string& configuration) override;
void Logging(const string& globalLogDir, const string& loggingOptions) override {};
};

} /* ProcessContainers */
} /* WPEFramework */
Loading

0 comments on commit 9723f99

Please sign in to comment.