Skip to content

Commit

Permalink
Packager: syncup from metro version
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Mar 15, 2024
1 parent 422b785 commit 25a7a3d
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 221 deletions.
49 changes: 25 additions & 24 deletions Packager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(PLUGIN_NAME Packager)
set(MODULE_NAME WPEFramework${PLUGIN_NAME})
project(Packager)

cmake_minimum_required(VERSION 3.3)

find_package(WPEFramework)

project_version(1.0.0)

set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME})

message("Setup ${MODULE_NAME} v${PROJECT_VERSION}")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand All @@ -30,6 +39,8 @@ if(PLUGIN_PACKAGER_OUTOFPROCESS STREQUAL "false")
unset(PLUGIN_PACKAGER_OUTOFPROCESS CACHE)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(libprovision QUIET)
find_package(LibOPKG REQUIRED)
Expand All @@ -40,38 +51,28 @@ add_library(${MODULE_NAME} SHARED
Packager.cpp
PackagerImplementation.cpp)

target_include_directories(${MODULE_NAME} PRIVATE
$<TARGET_PROPERTY:LibOPKG::LibOPKG,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>)

target_link_libraries(${MODULE_NAME} PRIVATE
CompileSettingsDebug::CompileSettingsDebug
${NAMESPACE}Plugins::${NAMESPACE}Plugins
LibOPKG::LibOPKG)

if (libprovision_FOUND)
target_link_libraries(${MODULE_NAME}
PRIVATE
CompileSettingsDebug::CompileSettingsDebug
${NAMESPACE}Plugins::${NAMESPACE}Plugins
libprovision::libprovision
LibOPKG::LibOPKG
)
else (libprovision_FOUND)
target_include_directories(${MODULE_NAME}
PRIVATE
${LIBOPKG_INCLUDE_DIRS}
)

target_link_libraries(${MODULE_NAME}
PRIVATE
CompileSettingsDebug::CompileSettingsDebug
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${LIBOPKG_LIBRARIES}
)
target_link_libraries(${MODULE_NAME} PRIVATE libprovision::libprovision)
endif (libprovision_FOUND)

string(TOLOWER ${NAMESPACE} STORAGENAME)
install(TARGETS ${MODULE_NAME}
install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGENAME}/plugins)

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/opkg.conf.in"
"${CMAKE_CURRENT_LIST_DIR}/opkg.conf.in"
"${CMAKE_CURRENT_BINARY_DIR}/opkg.conf"
@ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/opkg.conf
DESTINATION "/usr/share/${NAMESPACE}/${PLUGIN_NAME}")

write_config(${PLUGIN_NAME})
write_config()
1 change: 0 additions & 1 deletion Packager/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#define MODULE_NAME Plugin_Packager
#endif

#include <tracing/tracing.h>
#include <plugins/plugins.h>

#undef EXTERNAL
Expand Down
1 change: 0 additions & 1 deletion Packager/Packager.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ configuration = JSON()
rootobject = JSON()
rootobject.add("mode", "@PLUGIN_PACKAGER_MODE@")
configuration.add("root", rootobject)

75 changes: 51 additions & 24 deletions Packager/Packager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,79 @@ namespace {
ASSERT (service != nullptr);

_service = service;
_service->AddRef();
_skipURL = static_cast<uint8_t>(service->WebPrefix().length());
_service->Register(&_notification);

string result;
string result;
_implementation = _service->Root<Exchange::IPackager>(_connectionId, 2000, _T("PackagerImplementation"));
if (_implementation == nullptr) {
result = _T("Couldn't create package instance");
_service->Unregister(&_notification);
} else if (_implementation->Configure(_service) != Core::ERROR_NONE) {
result = _T("Couldn't initialize package instance");
_service->Unregister(&_notification);
result = _T("Couldn't create PACKAGER instance ");
} else {
Register<Params, void>(kInstallMethodName, [this](const Params& params) -> uint32_t {
return this->_implementation->Install(params.Package.Value(), params.Version.Value(),
params.Architecture.Value());
});
Register<void, void>(kSynchronizeMethodName, [this]() -> uint32_t {
return this->_implementation->SynchronizeRepository();
});

if (_implementation->Configure(_service) != Core::ERROR_NONE) {
result = _T("Couldn't initialize PACKAGER instance");
}
}

#ifndef USE_THUNDER_R4
if (result.length() != 0) {
Deinitialize(service);
}
#endif

return (result);
}

void Packager::Deinitialize(PluginHost::IShell* service)
{
ASSERT(_service == service);

_service->Unregister(&_notification);
if (_service != nullptr) {
ASSERT(_service == service);

if (_implementation->Release() != Core::ERROR_DESTRUCTION_SUCCEEDED) {

ASSERT(_connectionId != 0);

RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));

// The process can disappear in the meantime...
if (connection != nullptr) {
_service->Unregister(&_notification);

// But if it did not dissapear in the meantime, forcefully terminate it. Shoot to kill :-)
connection->Terminate();
connection->Release();
if (_implementation != nullptr) {
Unregister(kInstallMethodName);
Unregister(kSynchronizeMethodName);

RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));

uint32_t result = _implementation->Release();
_implementation = nullptr;
// It should have been the last reference we are releasing,
// so it should end up in a DESCRUCTION_SUCCEEDED, if not we
// are leaking ...
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);

// If this was running in a (container) process ...
if (connection != nullptr) {
// Lets trigger the cleanup sequence for
// out-of-process code. Will will guard
// that unwilling processes, get shot if
// not stopped friendly :~)
connection->Terminate();
connection->Release();
}
}
_service->Release();
_service = nullptr;
_connectionId = 0;
}

_service = nullptr;
_implementation = nullptr;
}

string Packager::Information() const
{
return (string());
}

void Packager::Inbound(Web::Request& request)
void Packager::Inbound(Web::Request&)
{
}

Expand Down Expand Up @@ -154,6 +180,7 @@ namespace {

void Packager::Deactivated(RPC::IRemoteConnection* connection)
{
ASSERT(connection != nullptr);
if (connection->Id() == _connectionId) {
ASSERT(_service != nullptr);
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service,
Expand Down
26 changes: 8 additions & 18 deletions Packager/Packager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "Module.h"
Expand All @@ -29,7 +29,9 @@ namespace {
constexpr auto* kSynchronizeMethodName = _T("synchronize");
}

class Packager : public PluginHost::IPlugin, public PluginHost::IWeb, public PluginHost::JSONRPC {
class Packager : public PluginHost::IPlugin,
public PluginHost::IWeb,
public PluginHost::JSONRPC {
public:
struct Params : public Core::JSON::Container {
Params& operator=(const Params& other) = delete;
Expand All @@ -51,29 +53,20 @@ namespace {
Core::JSON::String Version;
};

// We do not allow this plugin to be copied !!
Packager(const Packager&) = delete;
Packager& operator=(const Packager&) = delete;

Packager()
: _skipURL(0)
, _connectionId(0)
, _service(nullptr)
, _implementation(nullptr)
, _notification(this)
{
Register<Params, void>(kInstallMethodName, [this](const Params& params) -> uint32_t {
return this->_implementation->Install(params.Package.Value(), params.Version.Value(),
params.Architecture.Value());
});
Register<void, void>(kSynchronizeMethodName, [this]() -> uint32_t {
return this->_implementation->SynchronizeRepository();
});
}

~Packager() override
{
Unregister(kInstallMethodName);
Unregister(kSynchronizeMethodName);
}
~Packager() override = default;

BEGIN_INTERFACE_MAP(Packager)
INTERFACE_ENTRY(PluginHost::IPlugin)
Expand All @@ -100,10 +93,7 @@ namespace {
ASSERT(parent != nullptr);
}

~Notification() override
{
}

~Notification() override = default;
Notification() = delete;
Notification(const Notification&) = delete;
Notification& operator=(const Notification&) = delete;
Expand Down
Loading

0 comments on commit 25a7a3d

Please sign in to comment.