Porting C library to Java for Blackberry application - c

I need to port a C library to Java so it can run on the Blackberry platform (mobile, native application). The options I am considering are:
bytecode conversion (cibyl, etc)
Complete port
Wrap C code around Java using JNA (would this even work for Blackberry?)
Please let me know which option is best. thanks

Aha. Some quick googling says "No, JNI does not work for blackberry" source:
http://supportforums.blackberry.com/t5/Java-Development/Can-we-use-JNI-Java-Native-Interface-approach-in-Blackberry/m-p/365362
http://supportforums.blackberry.com/t5/Java-Development/JNI/m-p/41140.
So you're stuck with bytecode conversion and complete port. Since I have no idea what bytecode conversion is, I'd go with a complete port, so long as you are familiar with both languages. If you can define bytecode conversion for me, I might be able to give you a better answer.

We also have an in-house developed C library for core functionality of our iOS and Android apps.
I asked about using cibyl to run this on BlackBerry in the form of a .jar and the good news is that it's possible: https://twitter.com/#!/simonkagstrom/status/114581622833152000 [backup of the tweet: "Sure, that's how #waze on the blackberry works."]
You can also try MoSync: http://twitter.com/#!/MoSync/status/115088826430533632 [backup of this one: "Yup, you can use MoSync for BB. There's "experimental" Blackberry support in MoSync 2.6, already used in live apps!"]
And David A Roberts, developer of LLJVM sent me this: "I'm not familiar with BlackBerry development, but I see no obvious reason why LLJVM wouldn't work, so long as the library doesn't rely too much on things like the C POSIX library (e.g. dirent.h, etc) - I
never got around to implementing this fully. Otherwise LLJVM would need to be updated suitably..."
Side note: BlackBerry's new Tablet OS and planned BBX phones actually have a native SDK but this QNX based stuff is quite unpopular. We just need to wait if BBX is going to become a success since Java based solutions are just too much risks.

Related

Cloud9 IDE and C Programming

How can I write a C program in the IDE, cloud9? Whenever I start to write its showing errors, I even tried to change the file extension to ".C", but it doesn't work.
Does the cloud9 IDE support C programming?
Short answer
Yes Cloud9 does support C and C++ programming
Long Answer
Cloud9 has a varying level of support for different programming languages and frameworks.
Cloud9's ACE editor currently supports highlighting for about 60 programming languages including C/C++. The list is growing and you can get the full list from the "View -> Syntax" menu.
The editor has extensive support for JavaScript with error highlighting and code completion. It also has live syntax error checks for CSS, CoffeeScript, PHP, Python, JSON and Lua.
The run menu supports running
JavaScript (node.js)
Python
Ruby
PHP (using apache)
Each project is a unix sandbox with the standard tools like bash, make, gcc, vim, java SDK or perl installed. The terminal in Cloud9 is a full xterm compatible terminal emulator and you can use this to compile and run your C programs.
Cloud9 also has a package manager called c9pm which currently has about 120 packages. These packages include e.g. different versions of python and ruby, mono, lua or groovy.
In case you still need additional tools or libraries you can always download them to your workspace and compile and install them there.
As you see it is hard to draw the line of what is actually supported but usually you will have at least syntax highlighting in the editor and running from the console.
It claims support on the web page for "Javascript and Node.js applications as well as HTML, CSS, PHP, Java, Ruby and 23 other languages".
Yet it's very light on regarding details of those other languages. It does state that the editor, ACE, supports many different languages although whether that's natural languages or computer languages it doesn't specify. Additionally, an editor supporting a language is not the same as an IDE supporting it. It makes little sense having syntax coloring for C but no compiler.
Certainly C++ is possible as shown here but the fact that you simply use the editor then switch to a terminal session to compile the code seems to reduce the attractiveness of the so-called "IDE". It doesn't seem to give you anything you can't get from vim/gcc under Linux, or MinGW under Windows. It certainly isn't integrated in the sense that Visual Studio (even Express) or Code::Blocks is.
Regardless, the proper place for this sort of query is most likely on their support page here. I suspect they'd know more about what's supported than anyone here on SO.
Though I wouldn't be hopeful for a response. There's a very similar question asked back on Feb 28 which has still had no response. You have to wonder whether you want to entrust your precious code to a company that takes over four months to answer a simple support query.
In fact, to be brutally honest, I'm not sure I see the value proposition in using such a service. Given that you can get very good local IDEs already (for zero cost), the only possible advantage that springs to mind is collaboration. And, if you're working in a shop that has geographically dispersed developers, they'd probably have a fit if you told them you wanted to store your code where someone outside the company can get at it :-)
I'm not trying to turn you off the idea, just stating that (based on my experience), it doesn't seem as good as a substantial number of other solutions.
Cloud 9 does support C ( and C++ ) using gcc and g++
gcc --version
(GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
You can use their integrated editor, but the run button still acts like it trying to execute Javascript, which is the default, and seems to be their the target audience.
They have a fine C hello world example -- http://support.cloud9ide.com/entries/23541348-C-hello-Cloud9
Typically I just maximize the terminal, and run vim ( they have 7.2 installed ), and it works just like any passable unix terminal. They also have gdb installed, if you need a debugger.
There are comparisons against installed compiler solutions, but that isn't what Cloud9 is competing against. Their own description is Google Docs for code, and that seems to pretty fairly accurate. It certainly isn't all things to all people, but it is a pretty amazing service.
With Cloud9 I can write code on my Chromebook without having to install a bunch of stuff to almost make Linux run on it. This would be a good solution for students, since it would allow them to work in a computer lab without needing any software installed. I have found that using github and c9, I can easily switch back and forth between c9 while I am remote, and a local setup when I am on a real computer.

Developing IN an iPod touch

I am thinking about buying an iPod touch and I Wonder if there is Java and c++ editor to install in the iPod, something like having netbeans in the IPod. I want this because I would like to advance in my home-works on my way college-home while I'm on the bus or waiting for someone, etc. Is there anything?
Don't even consider trying to write code on an iPod, or even an iPad.
iPod is the wrong type of device for any sort of development. There are some ergonomic factors which are really important when it comes to writing code:
You should have a decent keyboard - i-devices only have touch-screens. A laptop keyboard is OK but not great.
You need the screen at a reasonable height and angle if you're going to be looking at it for a long time. You need to be able to type with both hands at the same time.
You need as much screen space as you can get.
I could come up with a lot more reasons for not using an i-device for development, but I think they are too obvious to bother listing.
If you really want to do your homework on the bus, you are better off getting yourself a decent laptop.
The iTunes App Store restrictions explicitly prohibit any compilers or interpreters from running on approved iOS apps.
That said, you could make a simple Javascript interpreter in a webpage, and then save it for offline use, without much trouble.
For that matter, any language that's implemented in Javascript and can work in an offline webpage could be used. For example, if you had a compiler written in Javascript, which compiled C++ to Javascript, then you could use that to write C++ on your iPod. I do not know of any such compilers offhand, but there's no theoretical reason they couldn't exist, as the App Store restrictions don't apply to HTML pages you browse to yourself.
A far more practical solution would be to just get a text editor (of which the App Store has many). Write your code on the bus, and then compile it when you get home. It will still be faster than the compilers we had when I was a kid!
(Or just get an SRS and spend the time studying rather than programming, since you're not going to be very effective at programming on a small touchscreen device, anyway.)
There's always an option to jailbreak your device and install GCC toolchain: iphone-gcc in Cydia and instruction here. Netbook would be a much better option though.
You can do some basic HTML and Latex but no Java or C++.
But I found something that could be interesting:
Processing is quite like Java and can be programmed on this site, with every iDevice.
http://jepstone.net/HiperPad/editor.php/HiPad4d113f1595b4c#home

How do I "break out" of the browser's sandbox?

I need to create a web-controlled application (that lives in the browser) that can connect to and read data from devices connected via USB or the serial port.
At the moment, I'm using an ActiveX control to do this. However, I'm like to re-write this system to make it cross-browser (support Firefox) and eventually cross-platform (support Safari on Mac). ActiveX is neither cross-browser or cross-platform, so I'm looking for an alternative technology.
My first inclination would have been to use Silverlight, because Silverlight 4 grants access to COM Automation. Unfortunately, this only works with OOB (Out of browser) Silverlight applications - in-browser systems are still bound in a sandbox and do not have access.
So, what technologies exist (frameworks, browser plug-ins, etc) that will allow me to interface with a USB/Serial device from within a browser-based web application? What are the pros/cons of each?
I think your best bet is probably Java in this case. USB, though an industry standard in terms of protocol is definitely not standardised in terms of bare-metal implementation. For this reason, you will still need a different Java USB implementation for each distinct platform (windows, linux, osx, bsd) that you intend to support. Of course you will also have to pay for code-signing certificates so you can try to convince people to grant your application the kind of access it requires; something that browsers try very hard to deny access to and most people in this day and age are very unwilling to grant. That said, there's an old IBM article here on the various Java USB projects that makes a good read. Good luck.
http://www.ibm.com/developerworks/library/j-usb.html
-Oisin
It might be painful, but you could use a signed Java applet. Signed Java applets can have full access to the user's system.
Java does not have built in USB support, so you would probably need to roll your own JNI interface to native USB APIs.
Using JNI in an applet can be tricky. I've done it before. If you Google the topic, most results say "don't do it" or "you can't do it." Well, you can do it.
This is how I did: I packaged the native libraries (DLL, so, etc) inside the applet's JAR, and then read the native libraries out of the JAR using e.g. getResourceAsStream. I then wrote the libraries out to an appropriate location on disk (e.g. ${user.home}/.myapp/.) I then used System.load to load the JNI DLL.
There can be some ClassLoader issues with JNI libraries and applets. The issues are subtle and difficult to explain. They basically have to do with the fact that a JVM can only load and bind a given JNI library once per VM instance, but applets get instantiated a lot, often with their own new ClassLoader, which can be problematic. The work that Sun did on process separation in the Next Generation Browser Plugin may have relieved some of these issues, but your users will only have this if they are using Java 1.6.0_10 or later.
It is also possible to use JNA within a signed applet. I would not recommend using JNA to access USB APIs directly. But JNA can sometimes be a big time saver for accessing simple native functions. Although once you've set up your JNI infrastructure, JNA probably has less value.
Here are a few other random thoughts:
Java WebStart - Can be launched from browser, but runs outside the browser
Microsoft ClickOnce - Can be launched from browser, but runs outside the browser
Flash / AIR - Can't escape its sandbox
The best solution I've come across thus far is the cross-browser/cross-platform plug-in system called FireBreath. This is a framework built in C++ that allows you to generate plug-ins for both ActiveX and NPAPI from the same codebase.
So build it once, make it work, and it compiles to one DLL that you can deploy in either environment: ActiveX for IE, NPAPI for everyone else.

Extending PythonCE to Access gsm/camera/gps Easily from PythonCE

As it seems there is no scripting language for Windows mobile devices that gives access to phone (sms, mms, make a call, take photo). I wonder how complex it would be to make a Python library that would enable that (write something in C, compile, and import in PythonCE).
Question: Where shall start to understand how to compile a PythonCE module that will give additional functionality to Python on Windows mobile. Also, what is the required toolkit. Is it at all possible on Mac (Leopard)?
As the first step, you should try to create executable programs that invoke the functions you want. For example, to send SMS, it appears you need to call MailSwitchToAccount, passing "SMS", and so on - familiarize yourself with the C API on the platform.
To create executables, you need Visual Studio, and the Windows Mobile SDK. Those run on Windows. For cross-compilation, there is CeGCC (http://cegcc.sourceforge.net/docs/using.html), but using it probably makes things more complicated than using the Microsoft tools.
When you have executables that perform the functions you desire, creating Python extension modules out of them should be easy. Just follow the extending-and-embedding tutorials.
MSDN has plenty of samples for C++ development on Windows Mobile, and the SDK comes with several sample application. Unfortunately VS Express editions (the free ones) do not come with compilers for Smart Devices. The only free option is the older eMbedded Visual C++ (eVC), which is now something like 8 years old and not supported (though it can still create apps for devices at least up through CE 5.0).
just tried establishing an environment to get pythonce modules compiled (http://pythonce.sourceforge.net/Wikka/SConsBuild) but seems that I can only use 2003 PPC SDK and it has no recent functions available. Even when I followed all the steps in tutorial, sample spammodule.c does not compile :(
Is there any good tutorial I can utilize to startup C (C++) programming for Windows Mobile?
Also is it possible using free version of VisualStudio (Express version)?

Writing cross-platform apps in C

What things should be kept most in mind when writing cross-platform applications in C? Targeted platforms: 32-bit Intel based PC, Mac, and Linux. I'm especially looking for the type of versatility that Jungle Disk has in their USB desktop edition ( http://www.jungledisk.com/desktop/download.aspx )
What are tips and "gotchas" for this type of development?
I maintained for a number of years an ANSI C networking library that was ported to close to 30 different OS's and compilers. The library didn't have any GUI components, which made it easier. We ended up abstracting out into dedicated source files any routine that was not consistent across platforms, and used #defines where appropriate in those source files. This kept the code that was adjusted per platform isolated away from the main business logic of the library. We also made extensive use of typedefs and our own dedicated types so that we could easily change them per platform if needed. This made the port to 64-bit platforms fairly easy.
If you are looking to have GUI components, I would suggest looking at GUI toolkits such as WxWindows or Qt (which are both C++ libraries).
Try to avoid platform-dependent #ifdefs, as they tend to grow exponentially when you add new platforms. Instead, try to organize your source files as a tree with platform-independent code at the root, and platform-dependent code on the "leaves". There is a nice book on the subject, Multi-Platform Code Management. Sample code in it may look obsolete, but ideas described in the book are still brilliantly vital.
Further to Kyle's answer, I would strongly recommend against trying to use the Posix subsystem in Windows. It's implemented to an absolute bare minimum level such that Microsoft can claim "Posix support" on a feature sheet tick box. Perhaps somebody out there actually uses it, but I've never encountered it in real life.
One can certainly write cross-platform C code, you just have to be aware of the differences between platforms, and test, test, test. Unit tests and a CI (continuous integration) solution will go a long way toward making sure your program works across all your target platforms.
A good approach is to isolate the system-dependent stuff in one or a few modules at most. Provide a system-independent interface from that module. Then build everything else on top of that module, so it doesn't depend on the system you're compiling for.
XVT have a cross platform GUI C API which is mature 15+ years and sits on top of the native windowing toollkits. See WWW.XVT.COM.
They support at least LINUX, Windows, and MAC.
Try to write as much as you can with POSIX. Mac and Linux support POSIX natively and Windows has a system that can run it (as far as I know - I've never actually used it). If your app is graphical, both Mac and Linux support X11 libraries (Linux natively, Mac through X11.app) and there are numerous ways of getting X11 apps to run on Windows.
However, if you're looking for true multi-platform deployment, you should probably switch to a language like Java or Python that's capable of running the same program on multiple systems with little or no change.
Edit: I just downloaded the application and looked at the files. It does appear to have binaries for all 3 platforms in one directory. If your concern is in how to write apps that can be moved from machine to machine without losing settings, you should probably write all your configuration to a file in the same directory as the executable and not touch the Windows registry or create any dot directories in the home folder of the user that's running the program on Linux or Mac. And as far as creating a cross-distribution Linux binary, 32-bit POSIX/X11 would probably be the safest bet. I'm not sure what JungleDisk uses as I'm currently on a Mac.
There do exist quite few portable libraries just examples I've worked within the past
1) glib and gtk+
2) libcurl
3) libapr
Those cover nearly every platform and so they are extremly useful tool.
Posix is fine on Unices but well I doubt it's that great on windows, besides we do not have any stuff for portable GUIs there.
I also second the recommendation to separate code for different platforms into different modules/trees instead of ifdefs.
Also I recommend to check beforehand what are the differences in you platforms and how you could abstract them. E.g. this is some OS related stuff (e.g. the annoying CR,CRLF,LF in text files), or hardware stuff. E.g. the previous mentioned posix compability doesnt stop you from
int c;
fread(&c, sizeof(int), 1, file);
But on different hardware platforms the internal memory layout can be complete different (endianess), forcing you to use conversion functions on some of the target platforms.
You can use NAppGUI for both console and desktop apps. The SDK uses ANSI-C and your code will work on Windows/macOS/Linux.
https://www.nappgui.com
It's free and OpenSource.

Resources