Skip to content

Commit

Permalink
Packager: syncup from rdkservices (#136)
Browse files Browse the repository at this point in the history
* Packager: syncup from rdkservices

* Packager: define JSON Contianer for MetaData, instead of using JsonObject
  • Loading branch information
HaseenaSainul authored Apr 29, 2022
1 parent 14236c8 commit 8dfe336
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 147 deletions.
79 changes: 78 additions & 1 deletion Packager/PackagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <opkg.h>
#endif
#include <opkg_download.h>

#include <pkg.h>

namespace WPEFramework {
namespace Plugin {
Expand Down Expand Up @@ -58,6 +58,10 @@ namespace Plugin {
uint32_t result = Core::ERROR_NONE;
Config config;

ASSERT(_service == nullptr);
_service = service;
_service->AddRef();

config.FromString(service->ConfigLine());

if ((config.ConfigFile.IsSet() == true) && (config.ConfigFile.Value().empty() == false)) {
Expand Down Expand Up @@ -118,6 +122,8 @@ namespace Plugin {
PackagerImplementation::~PackagerImplementation()
{
FreeOPKG();
_service->Release();
_service = nullptr;
}

void PackagerImplementation::Register(Exchange::IPackager::INotification* notification)
Expand Down Expand Up @@ -274,10 +280,77 @@ namespace Plugin {
if (progress->percentage == 100) {
self->_inProgress.Install->SetState(Exchange::IPackager::INSTALLED);
self->NotifyStateChange();
self->_inProgress.Install->SetAppName(progress->pkg->local_filename);
string callsign = self->GetCallsignFromMetaDataFile(self->_inProgress.Install->AppName());
if (!callsign.empty()) {
self->DeactivatePlugin(callsign);
}
}
}
#endif

string PackagerImplementation::GetCallsignFromMetaDataFile(const string& appName)
{
string callsign = "";
string metaDataFileName = (string(opkg_config->cache_dir) + "/" + appName + string(AppPath) + appName + string(PackageJSONFile));
TRACE(Trace::Information, (_T("[RDM]: Metadata is %s"), metaDataFileName.c_str()));
Core::File metaDataFile(metaDataFileName);
if (metaDataFile.Open()) {
MetaData metaData;
Core::OptionalType<Core::JSON::Error> error;
if (metaData.IElement::FromFile(metaDataFile, error)) {
if (error.IsSet() == true) {
TRACE(Trace::Error, (_T("Parsing failed with %s"), ErrorDisplayMessage(error.Value()).c_str()));
} else {
if ((metaData.Type.IsSet() == true) && (metaData.Type.Value() == PackagerImplementation::PackageType::PLUGIN)) {
if (metaData.Callsign.IsSet() == true) {
callsign = metaData.Callsign.Value();
} else {
TRACE(Trace::Information, (_T("[RDM]: callsign missing in metadata")));
}
} else {
TRACE(Trace::Information, (_T("[RDM]: MetaData file does not contain plugin type")));
}
}
}
} else {
TRACE(Trace::Error, (_T("[RDM]: Error in opening the file")));
}
return callsign;
}

void PackagerImplementation::DeactivatePlugin(const string& callsign)
{
ASSERT(_service != nullptr);
ASSERT(callsign.empty() == false);

TRACE(Trace::Information, (_T("[RDM]: callsign from metadata is %s"), callsign.c_str()));
PluginHost::IShell* plugin = _service->QueryInterfaceByCallsign<PluginHost::IShell>(callsign);

if (plugin != nullptr) {
PluginHost::IShell::state currentState(plugin->State());
if ((currentState == PluginHost::IShell::ACTIVATED) || (currentState == PluginHost::IShell::ACTIVATION) || (currentState == PluginHost::IShell::PRECONDITION)) {
TRACE(Trace::Information, (_T("[RDM]: Plugin %s is activated state, so deactivating"), callsign.c_str()));
uint32_t result = plugin->Deactivate(PluginHost::IShell::REQUESTED);
if (result == Core::ERROR_NONE) {
TRACE(Trace::Information, (_T("[RDM]: %s moved to Deactivated state"), callsign.c_str()));
}
else {
TRACE(Trace::Error, (_T("[RDM]: Failed to move %s to Deactivated state"), callsign.c_str()));
}
} else if (currentState == PluginHost::IShell::UNAVAILABLE) {
TRACE(Trace::Information, (_T("[RDM]: Plugin %s is unavailable"), callsign.c_str()));
}
else {
TRACE(Trace::Information, (_T("[RDM]: Plugin %s is already in deactivated state"), callsign.c_str()));
}

plugin->Release();
} else {
TRACE(Trace::Error, (_T("[RDM]: Plugin %s is not configured in this setup"), callsign.c_str()));
}
}

void PackagerImplementation::NotifyStateChange()
{
_adminLock.Lock();
Expand Down Expand Up @@ -350,4 +423,8 @@ namespace Plugin {
}

} // namespace Plugin
ENUM_CONVERSION_BEGIN(Plugin::PackagerImplementation::PackageType)
{ Plugin::PackagerImplementation::PackageType::NONE, _TXT("none") },
{ Plugin::PackagerImplementation::PackageType::PLUGIN, _TXT("plugin") },
ENUM_CONVERSION_END(Plugin::PackagerImplementation::PackageType);
} // namespace WPEFramework
56 changes: 53 additions & 3 deletions Packager/PackagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ namespace WPEFramework {
namespace Plugin {

class PackagerImplementation : public Exchange::IPackager {
private:
static constexpr const TCHAR* AppPath = _T("/etc/apps/");
static constexpr const TCHAR* PackageJSONFile = _T("_package.json");

public:
PackagerImplementation(const PackagerImplementation&) = delete;
PackagerImplementation& operator=(const PackagerImplementation&) = delete;
enum PackageType {
NONE,
PLUGIN
};

public:
class EXTERNAL Config : public Core::JSON::Container {
public:
Config()
Expand Down Expand Up @@ -66,6 +73,7 @@ namespace Plugin {
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;

public:
Core::JSON::String ConfigFile;
Core::JSON::String TempDir;
Core::JSON::String CacheDir;
Expand All @@ -76,6 +84,35 @@ namespace Plugin {
Core::JSON::Boolean AlwaysUpdateFirst;
};

class MetaData : public Core::JSON::Container {
public:
MetaData()
: Core::JSON::Container()
, Callsign()
, Type(NONE)
{
Add(_T("callsign"), &Callsign);
Add(_T("type"), &Type);
}
MetaData(const MetaData& copy)
: Core::JSON::Container()
, Callsign(copy.Callsign)
, Type(copy.Type)
{
Add(_T("callsign"), &Callsign);
Add(_T("type"), &Type);
}
~MetaData() override = default;

public:
Core::JSON::String Callsign;
Core::JSON::EnumType<PackageType> Type;
};

public:
PackagerImplementation(const PackagerImplementation&) = delete;
PackagerImplementation& operator=(const PackagerImplementation&) = delete;

PackagerImplementation()
: _adminLock()
, _configFile()
Expand All @@ -87,6 +124,7 @@ namespace Plugin {
, _alwaysUpdateFirst(false)
, _volatileCache(false)
, _opkgInitialized(false)
, _service(nullptr)
, _worker(this)
, _isUpgrade(false)
, _isSyncing(false)
Expand Down Expand Up @@ -179,7 +217,7 @@ namespace Plugin {

string AppName() const override
{
return (string());
return _appname;
}

uint32_t ErrorCode() const override
Expand All @@ -204,6 +242,14 @@ namespace Plugin {
_progress = progress;
}

void SetAppName(const TCHAR path[])
{
string pathName = Core::File::PathName(string(path));
if (pathName.empty() == false) {
_appname = Core::File::FileName(string(pathName.c_str(), pathName.size() - 1));
}
}

void SetError(uint32_t err)
{
TRACE(Trace::Information, (_T("Setting error to %d"), err));
Expand All @@ -214,6 +260,7 @@ namespace Plugin {
Exchange::IPackager::state _state = Exchange::IPackager::IDLE;
uint32_t _error = 0u;
uint8_t _progress = 0u;
string _appname;
};

struct InstallationData {
Expand Down Expand Up @@ -283,6 +330,8 @@ namespace Plugin {
#if !defined (DO_NOT_USE_DEPRECATED_API)
static void InstallationProgessNoLock(const _opkg_progress_data_t* progress, void* data);
#endif
string GetCallsignFromMetaDataFile(const string& appName);
void DeactivatePlugin(const string& callsign);
void NotifyStateChange();
void NotifyRepoSynced(uint32_t status);
void BlockingInstallUntilCompletionNoLock();
Expand All @@ -300,6 +349,7 @@ namespace Plugin {
bool _alwaysUpdateFirst;
bool _volatileCache;
bool _opkgInitialized;
PluginHost::IShell* _service;
std::vector<Exchange::IPackager::INotification*> _notifications;
InstallationData _inProgress;
InstallThread _worker;
Expand Down
128 changes: 0 additions & 128 deletions Packager/cmake/FindGLIB.cmake

This file was deleted.

7 changes: 0 additions & 7 deletions Packager/cmake/FindSqlite.cmake

This file was deleted.

8 changes: 0 additions & 8 deletions Packager/cmake/FindSqliteSee.cmake

This file was deleted.

0 comments on commit 8dfe336

Please sign in to comment.