JNI use in UMDF driver - java-native-interface

I have a umdf driver and I would like to call some functions in .jar files to establish a connection between my driver (PCSC Reader) and an eclipse plugin (JCOP).
I called some java functions (from .jar) in a c++ main using JNI but can we write JNI code in a UMDF driver ?
If yes, I would appreciate some guidelines or point of views about how to approach the subject ...
There aren't much info about the subject when you google it so any info is much appreciated !
Thank you.

I don't have any UMDF driver experience, however, after reading the over view I don't see any reason why JNI would not be able to communicate directly with the Reflector. I don't think it will be able to communicate with the device stack or manager. So, if I understand this correctly, you should probably have some driver you load independently of JNI and then use JNI to talk to the driver via the Reflector.
On a more general note, I would recommend keeping your JNI code as simple as possible. My JNI code usually only functions as a Java <=> Native translation layer. All of the complexity and processing is done in a backing library that can be run independently of Java. By doing that, you can debug your native code with gdb or visual studio without having to jump around an already running JVM. You can choose to either ship the stand alone library as a native dependency and add it the the systems library load path or you can simply link it to the JNI library statically. I have had very good results using LTO and static linking in that exact scenario.

Related

Jni layer in Android

I am confused with Jni layer, NDk LAYER and the C/C++ source code components LAYER in the Android system.
When writing feature on Android based platform, introducing new custom components:
Can I refer any component written in c/C++ as NDK component ?
What is jni, a file which helps loading c/C++ shared objects ?
I have refered below link: It talks about how to use it but not exactly clarifies the naming convention used in Android platform.
https://developer.android.com/training/articles/perf-jni.html
Can someone please clarify the distinction between JNI,NDK and c/c++components?
Here's a worlflow.
You have a class named NativeGoodAlgorithm written in C/C++.
Write a wrapper for NativeGoodAlgorithm called NativeGoodAlgorithmInterface(JNI).
Write a Android.mk that links your native code and wrapper to generate a library(.so).
In Android, you load the generated library and write a Java class named GoodAlgorithm.
Then you call GoodAlgorithm wherever you want.
The Java Native Interface (JNI) is a way for you to call C++ code from your Java code, and the other way around.
The Native Development Kit (NDK) uses JNI to let you call C++ from an Android application.
You will most likely have to do some work to call existing C/C++ from an Android app using NDK. For example, you'd have to make sure your C/C++ ran on the ARM CPU on the phones you want to support. You'll have to define the data structures you want to pass back and forth between the two layers. I'm not sure what the limitations on OS-level calls are for native code running in an app, but there probably are some.

How to differentiate between system calls and normal function calls

I am working on project which is trying to migrate some legacy application running on QNX neutrino operating system to other open source RTOS based on linux.
I have listed all the third party library and device drivers which must be ported and now analyzing design and source code which depends on some special QNX features like QNX IPC MsgSend, MsgReply, MsgSendPulse etc.
I want to know is there any tools which will help me to make a list of all QNX related system calls or functions which is getting used in code from normal user defined functions or functions provided by third party library and C++ library. Since code is written by other organisations we don't know much details about code except how to compiler and how to run it.
Thanks
Please refer link: https://sourceforge.net/projects/simpl/
You don't have direct API calls in linux which are equivalent to MsgSend, MsgReply etc.. but you can achieve it through using existing pipes/POSIX MQs (or) You can install above tgz package (Which is available in https://sourceforge.net/projects/simpl/).

Reg Executing C++ applications on U-Boot (No OS)

We have developed an application which has so many C++ files. On Linux we were able to execute it.
We have an U-Boot for the MPC8548E based custom board.
Now we decided to go without OS. So, I tried two methods to execute the C++ applications on U-Boot.
1.) Compiled the C++ application with the g++ (C++ cross-compiler) and tried to link with the U-Boot, which is compiled using gcc (The C-Compiler). But I am unable to do that:
The error message I am seeing is:
/ToolChain/host/usr/powerpc-buildroot-linux-uclibcspe/bin/ld: failed to merge target specific data of file...
2.) Tried to compile my application along with U-Boot in the same way the standalone examples are done. I created a separate directory in the U-Boot and tried to compile it. C++ applications are not getting built, but I am able to build C-Applications.
My main intention is to execute C++ applications directly on U-Boot.
Please help me how to do that?
Sorry, I believe it would be more work to get C++ on U-Boot than it would be for you to e.g. go with OS.
The short answer, from U-Boot tech lead:
> Does u-boot support C++ example programs and if so, how can I build one?
U-Boot does not support C++.
Some of the technical background for this: U-Boot runs on bare metal. A U-Boot standalone application would link to U-Boot's exported functions which the application needs. For example, your C++ application would use 'new', your C++ library needs to perform calls to malloc, which in this case would mean going to the u-boot exported function interface (refer to doc/README.standalone).
For the general topic of C++ on bare metal, I have not done that, but found Miro Samek tutorial that may shed light. I think it would be difficult. Porting linux starts to look good in comparison.

C++ Reads/Writes XML without CLR

I know this is a very stupid question and I'm very new to C++.
I'm developing Starcraft AI, it is DLL file. I'm trying to use XML to gather some data to the bot, however whenever I build the DLL with /clr option. The bot doesn't load properly. So, my question is what is CLR and is there a way to read/write XML without using /clr build option.
Thanks so much.
The /clr compiler option enables the
use of Managed Extensions for C++ and
creates an output file that will
require the .NET Framework common
language runtime at run time.
(from MSDN)
Starcraft is probably not developed under CLR (.NET Framework runtime).
I've used the free tinyxml library from C++ code - it was quick to get running and reasonably efficient. Well, about as efficient as it's possible for XML to be, anyway.
Starcraft probably won't run .NET binaries. You would have to either write your own XML parser, which probably isn't for you seeing as you are new to C++, or find a C++ library that can do it for you.
Example of one:
http://sourceforge.net/projects/tinyxml/

What API/SDK to use for this Windows Application?

I'm going to create a utility with GUI that will run on Windows operating systems.
It should require minimum (or zero!) amount of additional libraries, files or DLLs to run because it will be executed from an installer. Because of this, i don't want to use .NET for it will require user to install .NET Framework. I know today, most of Windows installed system come with .NET Framework but in my case i cannot be sure.
The utility will...
send some data to a web site and
parse the returning data,
collect some hardware info, like MAC address,
CPU type and make, hard-disk serial
number
I suppose native Win32 API could be used for all of those above, but instead of hassling with Win32, i'd prefer using a more developer friendly API, or SDK.
Thanks in advance.
Win32 API is the only way, and of course there are standard API - for sending data over the internet, you could use WinInet.lib/dll, to obtain information about the MAC, you could use the GetAdaptersInfo by using Iphlpapi.lib/dll,(here's a link on how to use it) for the Hard disk serial number you could use GetVolumeInformation by using kernel32.lib/dll. For the CPU Id, you might look into GetSystemInfomation
Edit: There's a C++ code, but you can easily derive a wrapper from this site Unfortunately, with WinAPI is not easy, no such thing as RAD with WinAPI but what you gain out of it is lightweight code instead of relying on SDK's, frameworks and dragging buggy dll's around with your application.
Hope this helps,
Best regards,
Tom.
You can statically link most C++ GUI libraries - even MFC. Personally, I recommend WTL, wihich is very light and header-only.
If what you want is minimum dependency with external files or DLLs you could statically compile all the required DLLs with the tool exe. Then you could use something like Visual C++ to develop such tool.
WTL is perfect for this sort of application and I am surprised more people aren't recommending it. You can also statically link with the CRT and hey presto - no dependencies and a very small EXE.
Delphi (now by Embarcadero) would do the job, creating a .exe file with no dependencies, and it is much easier to work with than the raw Win32 API.
If you don't like Object Pascal, you could try C++ Builder instead.
For the GUI you can either build your application with MFC (statically linked) or use a HTML based dialog that you can interact with using COM. (It is even possible to interact with javascript present in the page displayed by the dialog).
For the specific requirement that you do have, I feel Win32 API is the only way out.
Use MFC and statically link to it. No runtime dependancies need to be installed.