-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
7988266
commit 9723f99
Showing
22 changed files
with
1,848 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Source/extensions/processcontainers/implementations/AWCImplementation/AWC.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
40 changes: 40 additions & 0 deletions
40
Source/extensions/processcontainers/implementations/AWCImplementation/AWC.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
110 changes: 110 additions & 0 deletions
110
...ensions/processcontainers/implementations/AWCImplementation/AWCContainerAdministrator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
47 changes: 47 additions & 0 deletions
47
...xtensions/processcontainers/implementations/AWCImplementation/AWCContainerAdministrator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
Oops, something went wrong.