-
Notifications
You must be signed in to change notification settings - Fork 410
RDKEMW-6086 : Integrate NativeJS Plugin #6331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gurpreet319
wants to merge
1
commit into
rdkcentral:sprint/25Q3
Choose a base branch
from
gurpreet319:topic/RDKEMW-6086
base: sprint/25Q3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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}) |
This file contains hidden or 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,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) |
This file contains hidden or 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,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 |
This file contains hidden or 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,8 @@ | ||
| autostart = "false" | ||
| precondition = ["Graphics"] | ||
| callsign = "org.rdk.jsruntime" | ||
| configuration = JSON() | ||
| root = JSON() | ||
| root.add("mode", "Local") | ||
| configuration.add("root", root) | ||
| configuration.add("clientidentifier", "test") | ||
This file contains hidden or 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,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}) |
This file contains hidden or 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,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 |
This file contains hidden or 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 @@ | ||
| /** | ||
| * 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> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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