How to call a Java method in a C/C++ file? - java-native-interface

Say I have a jar file, there is a class named A in the package of the jar. I have to call a method of the class A like:
A.getInstance->notifyState(int)
in a C/C++ file, how to solve this?

Related

How do I #include plugin source files in my custom Unreal Engine module?

I'm working with a C++ Unreal Engine project and made my own custom module called MyActor, Unreal Engine automatically created the .cpp and .h files for me. That much appears to be working.
So now I want to include classes or methods from the AppleARKit plugin then override and call them from my custom MyActor module.
First I tried using #include AppleARKitLiveLinkSourceFactory.h because it has theIARKitBlendShapePublisher::PublishBlendshapes method which I want to modify and use.
It didn't work at first with this error: E1696 Cannot open source file AppleARKitLiveLinkSourceFactory.h but I found out I could include them in Visual Studio using the "Include Directories" under Properties like this:
The AppleARKitLiveLinkSourceFactory.h lives in the Public folder but I included the Private folder as well, I don't know if I need to do that. This appeared to work at first but then I got the same error as before for every dependency inside the AppleARKitLiveLinkSourceFactory.h file.
Do I have to include the individual directories for every dependency down the entire chain? Is there an easier way?
When I ran into the issue of including files from a plugin, in my case LidarPointCloud, the following steps worked for me:
1) In my <project-name>.Build.cs file, I added the module name I wished to use (LidarPointCloudRuntime) to the public dependency list
PublicDependencyModuleNames.AddRange(new string[] { "LidarPointCloudRuntime", "Core", "CoreUObject", "Engine", "InputCore" });
I determined the module name by opening the .uplugin file in the plugin's folder, and looked at the Modules section. If multiple module names are listed, you should pick the one that contains the source for the classes you care about.
2) I then rebuilt the project, closed my editor, then right clicked my <project-name>.uproject file and regenerated project files.
After that, I was able to access the .h files in my code.
-Update-
It seems that AppleARKitFaceSupport has dependencies on other plugins that may need to be included. For example, ARSystems.h lives in AugmentedReality. When I add that to PublicDependencyModuleNames and perform the same steps, it can find ARSystem.h.

How to mock a module for only one test file with Jest?

I am using Jest and I want to mock some functions from another module (let's call it dependency).
I was able to mock dependency globally, putting it inside a __mocks__ folder inside my __tests__ folder.
Unfortunately, I need the actual dependecy for all the other tests. So, how can I specify that I want to require the mocked dependecy only when required in my file1.js, but not in all other files?
PS: I could create a __mocks__ folder inside my file1.js folder, but this file is in the root, so when dependency is required by any file it will be picked up from the __mocks__.
You need to use jest.mock:
jest.mock('path/to/dependency', () => 'someMockValue')
Note that the path is relative to the test file, not to the file you want test.

Is it possible to get file path from cpp file in IOS project

Hi I am developing an IOS app and I have cpp file in it that need to read a binary file. Sending the path from .mm file to cpp file via a function call is not an option unfortunately. The only way I see is the cpp file somehow should call a function in .mm file which would then return the exact path to the binary file. How may I do that?
Sounds like calling a ObjectiveC method (returning the file path from the application bundle) from C / C++ is what you want to achieve. This SO question has the answer How to call an Objective-C Method from a C Method?
To obtain the actual path of the binary file add it to your Xcode project and make sure to add it to "Build Phases" > "Copy Bundle Resources" phase inside the Xcode project setting.
Call
[[NSBundle mainBundle] resourcePath]
to get the path to the directory that should contain your binary file.
Don't forget to look up the helper methods like
[NSString stringByDeletingLastPathComponent];
when working with file paths.

Unable to find the class 'Common'

I am new to Sonic and am trying out Management API.
I took the program ShowQueues.java inside Sonic_Installation\MQ8.6\samples\Management\runtimeAPI\javaProxy and pasted it into eclipse, since I want to change the url (currently: tcp://localhost:2506).
It is showing an error near the class 'Common'. Can you please tell me which jar this 'Common' class is available in?
The Common class is part of the sample project and can be found in the sample directory.
SonicHome\MQ8.6\samples\Management\runtimeAPI\javaProxyCommon.java
-- utility methods used by the above samples
Otherwise the jars can be found in the lib directory.
The class path for the Mgmt api is :
MGMT_CLASSPATH=%SONICMQ_LIB%\mgmt_client.jar;%SONICMQ_LIB%\mgmt_config.jar;%SONICMQ_LIB%\mfcontext.jar;%SONICMQ_LIB%\xercesImpl.jar
The class path for the MQ api is :
SONICMQ_CLASSPATH=%SONICMQ_LIB%\sonic_Client.jar;%SONICMQ_LIB%\sonic_mgmt_client.jar
Regards

use dyn.load or library.dynam to call a C++ function in an R package

I am very new to R. I would like to build an R package which will call a C++ function using .Call().
I have a NAMESPACE file, with
useDynLib(mypkg)
where mypkg is also the function name of my c++ code.
It works if I use this line at the begining of the mypkg.R file:
dyn.load("src/mypkg.so")
but I want to use library.dynam instead, so in the zzz.R file, I put
.onLoad<-function(libname, pkgname)
{
library.dynam("mypkg", pkgname, libname)
}
It gives the error when checking the package:
...
Error in .Call("mypkg", PACKAGE = "mypkg") :
C symbol name "mypkg" not in DLL for package "mypkg".
Error : unable to load R code in package 'mypkg'
...
It looks like the *.so file is generated in the wrong place? Why there is not /libs folder generated?
I would like to build the package to be os independent, is there a way to do it with dyn.load?
And this may be a very silly question, where did pkgname and libname get their input from?
Thank you very much for your help.
You could look at one of the many existing packages (with compiled source code) on CRAN.
Smaller and simpler is easier to grok, so you could e.g. look at digest which uses a NAMESPACE to load the one shared library built from the handful of C source files, and uses .Call() to access the main entry point.
And then there is of course the manual...