Skip to content
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

Added JNI Related changes in PubSub #6128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jchirantan
Copy link

@jchirantan jchirantan commented Nov 15, 2023

Hi @jpfr
Following files were modified and added to integrate SDK with java based OPC UA client, that uses PubSub APIs of SDK using JNI Calls:
Modified Files:

  • CMakeLists.txt:
  • Line 508-513: Added a line to link OPENSSL Library statically.
  • Line 857-858: Added newly created ua_jni_pubsub.c file to be built with project
  • Line 1336-1340: Added JNI related directories' path(User needs to provide this path according to their system)
  • /src/pubsub/ua_pubsub_reader.c:
  • Line 885-901: Added some flags and structure to process received message and transfer the message to Java code through JNI.
  • Line 908-912: Halted processing of new messages till the earlier messages are transferred through JNI as we are modifying the same array to store and transfer the messages.
  • Line 980-1720: Logic to parse the newly incoming message based on it's type(metadata), then convert that message into string format and store it into array. So that, we can pass on these messages to java code, based on JNI calls.
  • Capacity of array is 300 messages, so overflow detection/handling mechanism is also provided.(Line 1707-1720)
  • Line 2021-2147: Logic to access the java class containing the required fields to be transferred, create object of that class and assign values to the required fields from C code (JNI).

Newly created files in /src/pubsub folder:

  • jni_pubsub_PubSubMain.h:
  • Header file of java class containing native method getMessage()
  • jni_pubsub_PubSubConnect.h:
  • Header file of java class containing native methods- createServer(), connect(), teardownConnection(), runServer() and stopServer()
  • ua_jni_pubsub.c:
  • This file contains the logic of creating the Pubsub connection and configure server based on the parameters provided by user from Java based OPC UA Client.
  • Referred /examples/tutorial_pubsub_ubscribe.c and /examples/pubsub_subscribe_encrypted.c files to create this file.
  • Also added JNI methods to receive the parameters from Java based OPC UA Client and configure the server.
  • I have added support for multiple connections as well, so same server will be having multiple PubSub connections and will subscribe messages from multiple publishers at the same time.

Note:
I am using this code change on tagged version 1.3.6 with following build configurations:

cmake.exe .. -G "Visual Studio 17 2022" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_PUBSUB=ON -DUA_ENABLE_PUBSUB_MQTT=OFF -DUA_ENABLE_JSON_ENCODING=ON -DUA_ENABLE_DEBUG_SANITIZER=OFF -DUA_ENABLE_DISCOVERY_SEMAPHORE=OFF -DUA_ENABLE_HARDENING=OFF -DUA_ENABLE_NODEMANAGEMENT=OFF -DUA_ENABLE_NODESET_COMPILER_DESCRIPTIONS=OFF -DUA_ENABLE_PARSING=OFF -DUA_ENABLE_PUBSUB_DELTAFRAMES=OFF -DUA_ENABLE_PUBSUB_INFORMATIONMODEL=ON -DUA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS=OFF -DUA_ENABLE_STATUSCODE_DESCRIPTIONS=OFF -DUA_ENABLE_SUBSCRIPTIONS=OFF -DUA_ENABLE_SUBSCRIPTIONS_EVENTS=OFF -DUA_ENABLE_TYPEDESCRIPTION=ON -DUA_FORCE_WERROR=OFF -DUA_MSVC_FORCE_STATIC_CRT=OFF -DUA_ENABLE_ENCRYPTION_TPM2=OFF -DUA_LOGLEVEL=400 -DUA_ENABLE_ENCRYPTION=OPENSSL -DUA_ENABLE_PUBSUB_ENCRYPTION=ON -DCMAKE_TOOLCHAIN_FILE= -DVCPKG_TARGET_TRIPLET=

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2023

CLA assistant check
All committers have signed the CLA.

@jpfr
Copy link
Member

jpfr commented Nov 15, 2023

Hi there,

Thanks for making the PR.
Though I don't think we can merge that one.

  • We don't have experience with JNI on our side for the continued maintenance going forward
  • There is no test coverage. So we don't even see when things break

So this can either live in the PR as-is or you open a dedicated repo.
We can talk about merging at a later pointer. But for that we need to be sure that we don't pull in code that immediately starts to rot because nobody can work with it.

Regards, Julius

@jchirantan
Copy link
Author

Thanks @jpfr for your insights on the PR.
I have created my own repo for maintaining the JNI related changes, so I am not closing the PR and keeping it open as you have suggested.
Thanks again!!

@jchirantan
Copy link
Author

Hi @jpfr,

  • I Can see some test cases written under /tests/ folder.
  • Can you guide me how to execute these test cases and find the code coverage?
  • Any help/documentation on writing test cases for newly added code would be appreciated

Thanks!
Chirantan

@jchirantan
Copy link
Author

jchirantan commented Nov 21, 2023

Hi @jpfr,
any updates on above query?

@jpfr
Copy link
Member

jpfr commented Nov 22, 2023

Hey there,

please move your code to /tools/jni-binding and create tests under /tests/jni-binding.
You can simply add your test case to /tests/CMakeLists.txt.
Any of the existing tests can be used as a template.

@jpfr
Copy link
Member

jpfr commented Nov 22, 2023

If you need a java installation to test as the counterpart you can propose a solution.
We can make a test that is wrapped in a bash script. See /tools/ci.sh.

@jchirantan
Copy link
Author

jchirantan commented Nov 23, 2023

Hi @jpfr,
Thanks for your suggestions.

  • I just wanted to ask if you have any documentation which demonstrates writing test cases with check library to cover JNI methods?
  • Actually I am new to the concept of testing c code and "check" library, so any lead on this will be helpful.

Thanks!!
Chirantan

@jchirantan
Copy link
Author

Hi @jpfr,
any updates on above query?

Thanks!!

@jpfr
Copy link
Member

jpfr commented Nov 27, 2023

I don't have any experience with JNI.
Probably the best approach is to create the unit tests in Java and not in C.

The ci.sh executes line by line. It fails whenever one of the commands returns a non-null value.
You can do the same with Java and define a dedicated test environment in ci.sh and the Github Actions:
https://github.com/open62541/open62541/blob/master/.github/workflows/build_linux.yml

There you also have to add a java sdk as installation dependency.

@jchirantan
Copy link
Author

jchirantan commented Dec 1, 2023

Hi @jpfr,
Thanks for your suggestions.

  • I am writing test cases in java itself, but to call the JNI function written in C, we need to create dll/so file of SDK and load it in java code.
  • So, to run these test cases I have to create dll/so file of Code and store it to some location in code base.
  • This cannot provide the code coverage in C code. We will just get to know if test cases are passed or failed.
  • Also, each time new version is updated, new dll/so file needs to be manually created and stored at same location.
  • So, is there any other process we can follow to automate this?

Thanks!!

@jchirantan
Copy link
Author

Hi @jpfr,
any updates?

@jchirantan
Copy link
Author

Hi @jpfr,
Any update on the above query?

Thanks,
Chirantan

@jchirantan
Copy link
Author

Hi @jpfr,
Any updates on comment #6128 (comment) ?

@jpfr
Copy link
Member

jpfr commented Jan 6, 2024

CMake can be configured to produce a DLL/so shared library.
So it is possible to define a requirement that builds the library and the union bindings together.
We should not store binary blobs in the source repository.

@jchirantan
Copy link
Author

Hi @jpfr,
Thanks for your suggestion.

But can you share the lines to be added to CMakeLists file for creating shared so/dll files as I am new to this environment and this code base?

Thanks,
Chirantan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants