tags:

views:

117

answers:

2

Hi, I am developing an application in GWT which needs to call a native C++ code in Directshow to do some multimedia processing.I am guessing that I cant use JNI because GWT converts code to javascript.I did have a look at similar posts on the forum(and on GWT site about JSNI) but cant find a example that specifically talks about calling C++ code from GWT(its mostly about calling Java code from Javascript).Can anyone throw some light on this or direct me to a tutorial?

+3  A: 

Where exactly is this code supposed run? Surely not on the client-side. Client-side native code is nowhere near mass adoption.

GWT can either interface with JSNI in order to write native JS code inside your GWT Java code, or to interface with Java back-ends, whilst the framework handles the RPC. Even without GWT you have no way to run native code from within the browser (at least in the near future).

Bottom line - if you can't do it in plain vanilla Javascript on the client side, you can't do it in GWT.

What you can do is use this native code in the back-end, and call it via classic JNI from your Java back-end classes (and then what difference does it make if it's part of a GWT project or not?), but it sounds like this is not the case.

Yuval A
Thanks for the prompt reply!I am developing a standalone application.I put all the code under the client folder in the GWT project and I run it in a browser on my own machine.What I am basically doing is ->1)using GWT to develop UI for application(Managed)2)using Directshow to develop functionality for video processing.(Native)Now I need to link these two and that is where I need help..I want this to be done in the easiest way possible so if there is any other way of doing this i'll be glad to try itP.S. from what I get are u suggesting that I use-> Javascript calling Java calling C++ code?
Manish
If you are developing a standalone application that is supposed to access hardware (GPU), GWT is hardly the best choice - it's meant for web applications running inside a browser and thus in a sandbox.
Igor Klimer
As Igor suggested, it sounds like you are on the wrong track.
Yuval A
So what do you suggest ? I already have entire UI coded in GWT and Video Clipper coded in C++ using Directshow ?I would hate to start again :(
Manish
For next time - consult with your colleagues and architects before making significant design decisions. For now - consult with them on how to make the best of the current situation.
Yuval A
+1  A: 

First of all, have a clear separation of Client (HTML / Javascript running in the browser) and server components (java service servlets).

If I understood your problem statement right, You need the UI to collect parameters for your transcoders and your transcoders need to run on a Windows box.

You can look up any simple GWT application to figure out how to serve a GWT application in any container (perhaps jetty for the time being) and process basic HTML form inputs. Once you have all the parameters on the server, you need to figure out how to delegate these parameters posted from the browser (your GWT application) from the service servlet (running within a web server) to your DirectShow application. This point onwards its a java application talking to a native process problem.

You can use various ways to communicate parameters to your native directshow application. Simplest solution is to initiate the application with the exec method passing command parameters inline. Otherwise you can communicate to a running native application via TCP sockets or integrate the native app using JNI. It all depends on your architectural design, which approach you wish to take.

Ashwin Prabhu
What I meant is that I run the application locally(the videos to be processed are on my computer) with App Engine Dev server(I use eclipse so I select -"Run as Web App")...Therefore collecting the data parameters from the UI(browser ) is not a problem.My point is that since GWT converts the code to Javascript I cant possibly use JNI?
Manish
No you can't use JNI. But If your dll is a ActiveX Object running within the browser sand box, and if you can control it with javascript interface, you can try JSNI
Ashwin Prabhu
I do not have much information about ActiveX.Could you shed some more light on this? Should I develop the Directshow app as a ActiveX project and then call it from Javascript within GWT?-Thanks
Manish
ActiveX was a wild guess, since you were persistant on using JSNI. If I were you I would do all my DirectShow business on the server side in a separate process outside the server.
Ashwin Prabhu
No ...I am not persistant on any one method ...GWT documentation mentions that I use native Javascript if I want to do something like this ..I hardly care about the approach as long as I can get it done .....my only concern is that since I am developing everything as a prototype on my own machine without the hassle of having client/ server deployment ..shouldnt there be an easy method to integrate this UI and Directshow app?
Manish
can you exec your directshow app .exe with command line params on the server on GWT RPC call for the time being? exec'ing your process on the server will be a much faster way of prototyping, sould be a 15 min job if you have an exe that takes command line args for params.
Ashwin Prabhu
Thanks Ashwin for your prompt replies! I modified the code and now I have the exe file which accepts command line args .Could you slightly elaborate on the next steps( GWT-RPC thing ?).
Manish
No probs :) Create a sample GWT application in Eclipse, and run it as is. You will notice a Web Starter project page with a button, on click of which a RPC call is made to the server. Use this as a starting base. Add a text field to the page just like the button is added, collect the input and send the string to the server, use the string as a param. You can extend this to have a POJO comprising all the params for data transfer. This is very basic and should be straight forward, google can help you here on. Please accept any one answer and close this question.
Ashwin Prabhu
I guess that would still involve calling a .exe file from native javascript.I tried to do that but it didnt work.Anyways , thanks a lot for all your suggestions.I appreciate your time.
Manish
I am afraid you still did not understand. Please learn GWT basics first before you try any project on GWT, it will save you a lot of time and effort.
Ashwin Prabhu
@Ashwin : I got it to work .Sorry for the silly conceptual error.Thanks a ton!!!!
Manish