Play Scala - Native access - c++

I am developing an web application using the Play framework in Scala language. In my application I have to access the native methods which is written in C++ and converted into .so by using swig.
My aim is to call the native method which is in .so file from the Controller class. I have searched in the internet, but I didn't get any documentation for this.
I have seen some links which is used by scala language.
https://code.google.com/p/scala-native-access/
https://code.google.com/p/bridj/wiki/Download#Specialized_subsets_(smaller_JARs_!)
https://github.com/xudongyang/scala-native-access
But they didn't mention how exactly use this in the Play framework.
Can anybody have the documentation for Play scala native access?
Can anybody have the sample applcation for the same?

Like in any JVM language, JNA/JNI gives you native access. Be aware that because of Play's use of class loaders, you'll need to make sure you access from the same class. See fail to load a native library using activator (Play Framework)

This is hard to answer in general. Play! is just a Scala library and framework, some any tool that allows you to use native calls in Scala will work similarly with play. From the first link that you pointed to, there are instructions to integrate with SBT (the Scala Build Tool) which also manages your Play framework. You will need to make the changes they mention to your build.sbt file which you can find in the top level of your Play project folder.

Related

OpenCv and Ruby on Rails

Can I use OpenCV with Ruby on Rails? If so, how can I do that? Or, what resources do you recommend for that?
Thanks.
There is also an open CV gem, fwiw -- https://github.com/ruby-opencv/ruby-opencv.
Sure you can!
It just depends on what do you need as there is no "one" silver bullet.
If you want to create an online home surveillance, for example, then you would probably have least effort by writing:
C++ image-processing command-line application on top of OpenCV that would write the surveillance events and/or images to SQLite database.
Read the database directly from Rails.
For anything more complex, you'd need a more complex architecture.
Whatever you do, pick the best tools for the purpose:
Let OpenCV do what it is best at (image processing)
Let Rails to it's magic (simple, less demanding online access to some resources)
In order to link OpenCV and Ruby together, you could create a dedicated Ruby-to-C++ bridge because none of the existing ones can match diverse needs and most frameworks will do for a few specialized (i.e. designed by you) function-calls through your bridge.
This link would be a good start to pick a framework for a bridge - just go for one and see what comes out.
You could write a program using OpenCV in C++, and then just process your data with it, by using CGI (Common Gateway Interface http://en.wikipedia.org/wiki/Common_Gateway_Interface). I don't think you can bind native code to Ruby like you can do in Java (JNI)

Creating gui binding for c++ and YUI

I am planning to use yui or jquery ui as front end for native c++ applications. I found no bindings present for this purpose. Will it be feasible/possible to do this ? If it is so, then how shall i proceed? please suggest advice.thanks
#rwik - I can see your point and desire to do what you intend and I would presume it to be a wise move to be making at this point in time considering the vast facilities browsers bring to the table as well as other aspects... I know we are in September now and I have come across this pretty late, but this is also for others who have a similar problem...
As far as I know, descending from JavaScript in to C++ is pretty murky, mostly due to the heterogenous nature of Javascript engines [Rhino, Tracemonkey, Spidermonkey, V8, Caracan,Charka, etc] employed by different browsers. But there are indeed ways to do this - depending on how dirty you want to get your hands and, indeed, on your abilities...
If you were to go with Google as a browser, you should take a look at projects such as cproxyv8 - http://code.google.com/p/cproxyv8/ or v8-juice - http://code.google.com/p/v8-juice/ which both offer interesting facilities...
My preference however is with Mozilla - simply because of XML User-Interface Language (XUL) which, if you do not know, allows you to speedily create your own user interfaces by giving direct access to its layout engine. I.e., you can even do away with the browser look and have your own independent layout while still having all browser facilities at your disposal.
With respect to C++/Javascript interaction - projects should exist for all alternatives - it pays to check.
I wish you good luck if you haven't already solved this problem.
I'd recommend QT instead.
However since native C++ has nothing to do with GUI I'm going to assume you are making a library in C++. However Yui is basically just JavaScript as is jQuery. So if you're asking can a web page or script be a C++ application the answer is not really.
What you could do is create a web service which uses your C++ library and exposes an interface for your web based application to call it indirectly.
One way to accomplish this is to embed WebKit into your application and provide your custom C++ functionality via a plugin. Both the WebKit framework on OSX and the Chromium Embedded Framework on Windows allow this style of application development. This allows you to write a UI using local Javascript/HTML files without the need for a webserver.
There are no direct bindings in JQuery and YUI because these libraries run in a web browser. Thus unless you’re planning to write your own browser plugins, the integration with the C++ will happen at the webserver that serves the data to the browser.
You could feed the data from your C++ code directly into JQuery/YUI by building web services directly in C++. But you might want to build a web application that will be serving your JQuery/YUI pages and that act as user interface controller (like in the MVC pattern). Web application languages like Java, PHP, etc. all have ways to call native code. Java has JNDI and in PHP you build extensions that link to C++ code.

How does node.js/[my own library/plugin] run on v8?

Does it use any libraries like this:
http://code.google.com/p/v8-juice
http://ui.ajax.org/#o3
https://github.com/tsa/vu8
Or has it written its own libraries? If v8 is written for executing javascript, why do node.js libraries use C code? Just for the filesystem/event stuff? If so, why was that necessary, doesn't v8 need events and filesystem stuff itself?
If I want to work with a database that only supports a C api, how would I go about doing that? Right now I'd probably write a v8-juice plugin.
node.js includes its own embedded version of v8 (not sure if it is customized or not, but it could be).
Javascript itself provides no interface to things like file system I/O, so that you as the embedder (in this case node) have to provide native code objects to expose that functionality. The browser does the same thing for DOM and network features, by the way.
If I want to work with a database that only supports a C api, how would I go about doing that?
You'd need a node.js extension for this (a native code plugin). If you are lucky, someone has already made on for your database system, if not, look at the source code for a similar extension as to how those are written. And here is an introduction article. You'd need to be familiar with writing a v8 extension, because that is what a node extension basically is.
If you are talking to the database over a network connection, and feel like implementing the wire protocol yourself, you could also try to do that in pure Javascript, like someone did for MySQL.

What embedded browser for C++ project?

Is there any browser I could embedd in C++ application on Windows?
I need all features typical browser has (HTTP client, cookies support, DOM style HTML parser, JavaScript engine) except rendering.
Because I don't need rendering capability (and that's rather big part of a browser) I would prefer a browser with non monolithic design so I wouldn't have to include rendering stuff into my project.
It would be nice if it had C++ rather than C API.
I need this embedded browser mainly because I have much trouble finding C++ HTML parser which could handle broken HTML like browsers do.
If you know any, please answer Library Recommendation: C++ HTML Parser SO question or at least vote on it to increase a chance someone will give a good answer.
Sounds like all you need is something like libcurl which is an HTTP library and will let you do GET/POST/etc.
When I think browser I generally think rendering/JavaScript and not HTTP library.
Edit
In that case I'd look at WebKit (which I think has a C++ API) and hope you don't have to pull too much in.
Edit Again
On second thought (since rendering is such a big part of what browsers do), you might be better off using a stand-alone JS engine like SpiderMonkey and a stand-alone XML parser like Xerces-C (plus maybe tidy to make your HTML into XML).
I'm a bit confused by your question regarding embedding a web browser for which you don't need rendering capabilities. A web browser is rendering web pages by definition, unless you just need HTTP and XML with JavaScript capabilities which is a subset of a browser functionalities?
If you need a web browser to embed in your C++ application, I would suggest to consider Qt that comes with the WebKit plugin. It is C++, LGPL and has a very nice IDE (Qt Creator). I tried Qt with Qt Creator on unix (Ubuntu) and it was very impressive. The debugger is a bit light but it is just the first version. The adapter of Qt into visual c++ 2008 is now free.
You might also want to check out Awesomium-- it's free for non-commercial use and has all of the features you're looking for (if you don't need rendering, simply don't use it).
There is a project called CEF = The Chromium Embedded Framework - it is:
a simple framework for
embedding Chromium-based browsers in other applications. It is a
BSD-licensed open source project founded by Marshall Greenblatt in
2008 and based on the Google Chromium project. Unlike the Chromium
project itself, which focuses mainly on Google Chrome application
development, CEF focuses on facilitating embedded browser use cases in
third-party applications.
and yes:
The base CEF framework includes support for the C and C++ programming
languages.
Including javascript support and html parsing makes this non-trivial task - you have to use one of the available browsers.
IE is usable through its COM model - you can create instance of it in your window be it invisible or not and call its javascript/html capabilities.
It has been designed to be used like that since the beginning and certainly it is working fine.
The other options are:
Gecko/Mozilla - a couple of years ago it wasn't usable like this, currently I think it is.
WebKit/V8 - no public API has been released for chrome yet, you could use webkit itself, but it doesn't have javascript engine. Another option is to take a look at the Chrome codebase and see if you could get out of it what you need.
I would probably go for IE, since it is maybe the easiest option and I have already used it. The other options seem to me more like building a browser instead of just using it.
How about Gecko ? You may not need the entire engine but you may find some its components useful like SpiderMonkey which is a JavaScript engine written in C.
I'd recommend picking up Qt for C++ programming. It has a built-in library that embeds Webkit with all the bells'n'whistles, and Qt is a great C++ library in general.
Old question, I know, but take a look on
http://msdn.microsoft.com/en-us/library/ky29ffxd%28v=vs.94%29.aspx
IActiveScript and family COM interfaces allows script execution (not only JS, any language that registers as script interpeter, for that matter) in-memory.

script for actionscript/flash and c++

I havent used flash or action script much. I am planning a small project that i'd like to be online via flash but i'd like to reuse the code in my c/c++ projects
Is there a script language i can use? i am thinking lua or python. After googling i found flua which is incomplete and jython. Can i use java in flash? would it be a good idea to use python in java which is ran with flash?
Have you taken a look at Alchemy?
With Alchemy, Web application developers can now reuse hundreds of millions of lines of existing open source C and C++ client or server-side code on the Flash Platform. Alchemy brings the power of high performance C and C++ libraries to Web applications with minimal degradation on AVM2. The C/C++ code is compiled to ActionScript 3.0 as a SWF or SWC that runs on Adobe Flash Player 10 or Adobe AIR 1.5.
Have you looked at Haxe? http://www.haxe.org
The Haxe compiler can produce swf files, JavaScripts and other, with a language that resembles ActionScript or JavaScript more or less, depending on what language details you care about.
Here's this nice teaser from the haxe site: "Currently in testing, with the right build of Haxe from Hugh Sanderson, you can now output your Haxe applications to pure C++ source code, complete with makefiles."
But no, I don't know about using Java inside a Flash. You mean the Flash app executing Java while it's running? or using Java to create a Flash app?
There's no way to embed Java within a Flash movie. If you're creating a SWF that will display in a browser then you're restricted to Actionscript. You could create a Java applet, load it in the same page, and use javascript to communicate between the two, though I wouldn't recommend that.
If you're using a projector to create an EXE then you may be able to load and use C++ dlls, though I've never attempted this.