Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ if(PLUGIN_STORAGE_MANAGER)
add_subdirectory(StorageManager)
endif()

if(PLUGIN_NATIVEJS)
add_subdirectory(NativeJS)
endif()

if(PLUGIN_DEVICE_PROVISIONING)
add_subdirectory(DeviceProvisioning)
endif()
Expand Down
24 changes: 24 additions & 0 deletions NativeJS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(PLUGIN_NAME NativeJS)
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(${NAMESPACE}Definitions REQUIRED)

add_library(${MODULE_NAME} SHARED
NativeJSPlugin.cpp
NativeJSImplementation.cpp
Module.cpp
)

set_target_properties(${MODULE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES)

target_include_directories(${MODULE_NAME} PRIVATE ../helpers $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/jsruntime ${CMAKE_CURRENT_SOURCE_DIR} )

target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}Definitions::${NAMESPACE}Definitions -L${CMAKE_CURRENT_SOURCE_DIR}/../../build/NativeJS -L$ENV{PKG_CONFIG_SYSROOT_DIR}/usr/lib/javascriptcore -lJSRuntimeJSC -lJavaScriptCore)

install(TARGETS ${MODULE_NAME}
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)

write_config(${PLUGIN_NAME})
22 changes: 22 additions & 0 deletions NativeJS/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2019 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#include "Module.h"

MODULE_NAME_DECLARATION(BUILD_REFERENCE)
29 changes: 29 additions & 0 deletions NativeJS/Module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2019 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#pragma once
#ifndef MODULE_NAME
#define MODULE_NAME NativeJS
#endif

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

#undef EXTERNAL
#define EXTERNAL
8 changes: 8 additions & 0 deletions NativeJS/NativeJS.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autostart = "false"
precondition = ["Graphics"]
callsign = "org.rdk.jsruntime"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make the callsign camel cased to match other plugins. So "org.rdk.JSRuntime". Pls refer to https://github.com/rdkcentral/RDKServices?tab=readme-ov-file#coding-guidelines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the callsign to camel case

configuration = JSON()
root = JSON()
root.add("mode", "Local")
configuration.add("root", root)
configuration.add("clientidentifier", "test")
17 changes: 17 additions & 0 deletions NativeJS/NativeJS.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set (autostart false)
set (preconditions Graphics)
set (callsign "org.rdk.JSRuntime")

map()
kv(outofprocess true)
end()
ans(rootobject)

map()
if(PLUGIN_NATIVEJS_CLIENTIDENTIFIER)
kv(clientidentifier ${PLUGIN_NATIVEJS_CLIENTIDENTIFIER})
endif()
end()
ans(configuration)

map_append(${configuration} root ${rootobject})
159 changes: 159 additions & 0 deletions NativeJS/NativeJSImplementation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#include "NativeJSImplementation.h"

using namespace std;

namespace WPEFramework
{
namespace Plugin
{

std::string gPendingIdRequest("");
std::string gPendingIdOptionsRequest("");
std::string gPendingUrl("");
SERVICE_REGISTRATION(NativeJSImplementation, 1, 0);

NativeJSImplementation::NativeJSImplementation()
: mRunning(true)
{
TRACE(Trace::Information, (_T("Constructing NativeJSImplementation Service: %p"), this));
}

NativeJSImplementation::~NativeJSImplementation()
{
TRACE(Trace::Information, (_T("Destructing NativeJSImplementation Service: %p"), this));
mNativeJSRenderer = nullptr;
}

Core::hresult NativeJSImplementation::Initialize(string waylandDisplay)
{
std::cout << "initialize called on nativejs implementation " << std::endl;
mRenderThread = std::thread([=](std::string waylandDisplay) {
mNativeJSRenderer = std::make_shared<NativeJSRenderer>(waylandDisplay);
//if (!gPendingUrlRequest.empty())
//{
// ModuleSettings moduleSettings;
// moduleSettings.fromString(gPendingUrlOptionsRequest);
// mNativeJSRenderer->launchApplication(gPendingUrlRequest, moduleSettings);
// gPendingUrlRequest = "";
// gPendingUrlOptionsRequest = "";
//}

mNativeJSRenderer->run();

printf("After launch application execution ... \n"); fflush(stdout);
mNativeJSRenderer.reset();

}, waylandDisplay);
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::Deinitialize()
{
LOGINFO("deinitializing NativeJS process");
if (mNativeJSRenderer)
{
mNativeJSRenderer->terminate();
if (mRenderThread.joinable())
{
mRenderThread.join();
}
}
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::CreateApplication(const std::string options, uint32_t& id)
{
LOGINFO("createApplication invoked");
if(mNativeJSRenderer)
{
std::string optionsVal(options);
ModuleSettings moduleSettings;
moduleSettings.fromString(optionsVal);
id = mNativeJSRenderer->createApplication(moduleSettings);
}
else
{
gPendingIdOptionsRequest = options;
}
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::RunApplication(uint32_t id, const std::string url)
{
LOGINFO("runApplication invoked");
if(mNativeJSRenderer)
{
std::string Url(url);
mNativeJSRenderer->runApplication(id, Url);
}
else
{
gPendingUrl = url;
LOGINFO("runApplication Couldn't execute");
}
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::RunJavaScript(uint32_t id, const std::string code)
{
LOGINFO("runJavaScript invoked");
if(mNativeJSRenderer)
{
std::string Code(code);
mNativeJSRenderer->runJavaScript(id, Code);
}
else
{
LOGINFO("runJavaScript couldn't execute");
}
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::GetApplications()
{
LOGINFO("getApplication invoked");
if(mNativeJSRenderer)
{
mNativeJSRenderer->getApplications();
}
else
{
LOGINFO("getApplication couldn't execute");
}
return (Core::ERROR_NONE);
}

Core::hresult NativeJSImplementation::TerminateApplication(uint32_t id)
{
LOGINFO("terminateApplication invoked");
if(mNativeJSRenderer)
{
mNativeJSRenderer->terminateApplication(id);
}
else
{
LOGINFO("Application couldn't be terminated");
}
return (Core::ERROR_NONE);
}
} // namespace Plugin
} // namespace WPEFramework
61 changes: 61 additions & 0 deletions NativeJS/NativeJSImplementation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#pragma once

#include "Module.h"
#include "UtilsLogging.h"
#include <interfaces/INativeJS.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share interfaces/INativeJS.h source. Is this already part of https://github.com/rdkcentral/ThunderInterfaces/? Was this interface reviewed?

#include <interfaces/Ids.h>

#include <mutex>
#include "NativeJSRenderer.h"
#include <thread>
#include <vector>
using namespace JsRuntime;

namespace WPEFramework
{
namespace Plugin
{

class NativeJSImplementation : public Exchange::INativeJS
{
public:
NativeJSImplementation();
virtual ~NativeJSImplementation();
virtual Core::hresult Initialize(const string waylandDisplay) override;
virtual Core::hresult Deinitialize() override;
virtual Core::hresult CreateApplication(const std::string options, uint32_t& id) override;
virtual Core::hresult GetApplications() override;
virtual Core::hresult RunApplication(uint32_t id, const std::string url) override;
virtual Core::hresult RunJavaScript(uint32_t id, const std::string code) override;
virtual Core::hresult TerminateApplication(uint32_t id) override;

BEGIN_INTERFACE_MAP(NativeJSImplementation)
INTERFACE_ENTRY(Exchange::INativeJS)
END_INTERFACE_MAP

private:
std::thread mRenderThread;
bool mRunning;
std::shared_ptr<NativeJSRenderer> mNativeJSRenderer;
};
} // namespace Plugin
} // namespace WPEFramework
Loading
Loading