Friday, May 29, 2015

JNI (Java Native Interface)

The Java Native Interface (JNI) is a Java layer that allows Java code running in the Java Virtual Machine (JVM) to call and be called by native applications and libraries written in other languages, such as C, C++, and assembly. Developers use the JNI to write native methods to handle situations when an application cannot be written entirely in Java, such as when the standard Java class library does not support the platform-dependent features or program library. It is also used to modify an existing application, written in another programming language, to be accessible to Java applications.
Many of the standard library classes depend on the JNI to provide functionality to the developer and the user, e.g., I/O file reading and sound capabilities. The inclusion of performance- and platform-sensitive API implementations in the standard library allows all Java applications to access this functionality in a safe and platform-independent manner. Before resorting to using the JNI, developers should make sure the functionality is not already provided in the standard libraries. In this introductory article, I will cover how the JNI works and how native types are mapped to Java types and classes.

How the JNI works

In the JNI, native functions are implemented in a separate .c or .cpp file. (C++ provides a slightly cleaner interface with the JNI.) When the JVM invokes the function, it passes a JNIEnv pointer, a jobject pointer, and any Java arguments declared by the Java method. A JNI function may look like this:
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobjectobj)

{
    //Method native implemenation

}
The env pointer is a structure that contains the interface to the JVM. It includes all of the functions necessary to interact with the JVM and to work with Java objects. Example JNI functions are converting native arrays to and from Java arrays, converting native strings to and from Java strings, instantiating objects, throwing exceptions, etc. Basically, you can use JNIEnv to do anything that Java does, albeit with considerably less ease.
To be more formal, native code accesses JVM features by calling JNI functions, which are available through an interfacepointer (this is a pointer to a pointer). This pointer points to an array of pointers, each of which points to an interface function. Every interface function is at a predefined offset inside the array. Native methods receive the JNI interface pointer as an argument. The JVM is guaranteed to pass the same interface pointer to a native method when it makes multiple calls to the native method from the same Java thread. However, a native method can be called from different Java threads, and therefore may receive different JNI interface pointers.
Native methods are loaded with the System.loadLibrary method. In the following example, the class initialization method loads a platform-specific native library in which the native method f is defined:
packagepkg;  

class Cls { 
     native double f(inti, String s); 
     static { 
         System.loadLibrary(pkg_Cls"); 
     } 

}
The argument to System.loadLibrary is a library name chosen arbitrarily by the programmer. The system follows a standard, platform-specific approach to convert the library name to a native library name. For example, a Solaris system converts the name pkg_Cls to libpkg_Cls.so, while a Win32 system converts the same pkg_Cls name to pkg_Cls.dll.
Dynamic linkers resolve entries based on their names. A native method name is concatenated from components, which include: the prefix Java_, a mangled fully-qualified class name, and a mangled method name.
Note: Microsoft's implementation of a JVM has a similar mechanism for calling native Windows code from Java called the Raw Native Interface (RNI).

* Dynamic Linker : In computing, a dynamic linker is the part of an operating system that loads and links the shared libraries needed by an executable when it is executed (at "run time"), by copying the content of libraries from persistent storage to RAM, and filling jump tables and relocating pointers. The specific operating system and executable format determine how the dynamic linker functions and how it is implemented.
Linking is often referred to as a process that is performed when the executable is compiled, while a dynamic linker is a special part of an operating system that loads external shared libraries into a running process and then binds those shared libraries dynamically to the running process. This approach is also called dynamic linking or late linking.

* Jump Table : In computer programming, a branch table or jump table is a method of transferring program control (branching) to another part of a program (or a different program that may have been dynamically loaded) using a table of branch or jump instructions.

Data type mapping

Primitive types, such as integers, characters, and so on, are copied between Java and native code. Arbitrary Java objects, on the other hand, are passed by reference.
This table shows the mapping of types between Java and native code. These types are interchangeable. You can use jint where you normally use an int, and vice-versa without any typecasting required. However, mapping between Java Strings and arrays to native strings and arrays is different. If you use a jstring where a char * would be, your code could crash the JVM. This is an example of how you should work correctly with strings:
JNIEXPORT void JNICALL Java_ClassName_MethodName
  (JNIEnv *env, jobjectobj, jstringjavaString)

{
    //Get the native string from Java string
    const char *nativeString = env->GetStringUTFChars(env,javaString, 0);
    printf("%s", nativeString);
    env->ReleaseStringUTFChars(env,javaString, nativeString);

}
You always manipulate Java objects using the interface pointer env.

Thursday, May 28, 2015

Apache Subversion®

            
              Apache Subversion (often abbreviated SVN, after the command name svn) is a software versioning and revision control system distributed as free software under the Apache License. Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly compatible successor to the widely used Concurrent Versions System (CVS).             


             Subversion is an open source version control system. Founded in 2000 by CollabNet, Inc., the Subversion project and software have seen incredible success over the past decade. Subversion has enjoyed and continues to enjoy widespread adoption in both the open source arena and the corporate world. Subversion is developed as a project of the Apache Software Foundation, and as such is part of a rich community of developers and users. We're always in need of individuals with a wide range of skills, and we invite you to participate in the development of Apache Subversion.

Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.
Following are the goals of a Version Control System.
  • Allow developers to work simultaneously.
  • Do not overwrite each other’s changes.
  • Maintain history of every version of everything.
A VCS is divided into two categories.
  • Centralized Version Control System (CVCS), and
  • Distributed/Decentralized Version Control System (DVCS).
In this tutorial, we will concentrate only on the Centralized Version Control System and especially Subversion. Subversion falls under centralized version control system, meaning that it uses central server to store all files and enables team collaboration.

Version Control Terminologies

Let us start by discussing some of the terms that we will be using in this tutorial.
  • Repository: A repository is the heart of any version control system. It is the central place where developers store all their work. Repository not only stores files but also the history. Repository is accessed over a network, acting as a server and version control tool acting as a client. Clients can connect to the repository, and then they can store/retrieve their changes to/from repository. By storing changes, a client makes these changes available to other people and by retrieving changes, a client takes other people's changes as a working copy.
  • Trunk: The trunk is a directory where all the main development happens and is usually checked out by developers to work on the project.
  • Tags : The tags directory is used to store named snapshots of the project. Tag operation allows to give descriptive and memorable names to specific version in the repository.
    For example, LAST_STABLE_CODE_BEFORE_EMAIL_SUPPORT is more memorable than
    Repository UUID: 7ceef8cb-3799-40dd-a067-c216ec2e5247 and
    Revision: 13
  • Branches: Branch operation is used to create another line of development. It is useful when you want your development process to fork off into two different directions. For example, when you release version 5.0, you might want to create a branch so that development of 6.0 features can be kept separate from 5.0 bug-fixes.
  • Working copy: Working copy is a snapshot of the repository. The repository is shared by all the teams, but people do not modify it directly. Instead each developer checks out the working copy. The working copy is a private workplace where developers can do their work remaining isolated from the rest of the team.
  • Commit changes: Commit is a process of storing changes from private workplace to central server. After commit, changes are made available to all the team. Other developers can retrieve these changes by updating their working copy. Commit is an atomic operation. Either the whole commit succeeds or is rolled back. Users never see half finished commit.


Reference link: 
http://en.wikipedia.org/wiki/Apache_Subversion
http://www.tutorialspoint.com/svn/svn_basic_concepts.htm

Friday, May 22, 2015

Visual voicemail

                 
                Visual voicemail is random-access voicemail with a visual interface. Such an interface presents a list of messages for playback and may include a transcript of each message. In 2007, Apple's iPhone was the first cell phone promoting this feature. Since then, several companies in the telecommunications space have integrated a visual element into their voicemail services, as Samsung's Instinct and the BlackBerry Storm and Torch.

               In 2007, YouMail was the first third-party, multi-platform visual voicemail service for mobile phones, storing voice mail in the cloud rather than the mobile carrier's network, and providing access to it through any web browser or by e-mail. In 2009, YouMail was the first to then extend this to also provide this functionality with an app for the BlackBerry, iPhone, and Android platforms, and an API that allowed others to build clients for Windows Phone 7 and WebOS.

              There are two options for managing voicemail on your LTE Android Smartphone: AT&T Basic Voicemail or Visual Voicemail.
  • Basic Voicemail: Basic voicemail is the standard voicemail answering service that is available on all AT&T wireless phones, and can be accessed even after setting up Visual Voicemail. Basic Voicemail allows you to dial into your voicemail box, and follow the voice prompts to listen to or manage voice messages. For additional information.
      
  • Visual Voicemail: Visual Voicemail allows you to play and manage your voicemail messages from an on-screen inbox, just as you would with an email account. Visual Voicemail is offered for select 4G LTE Android smartphones either as a free downloadable app, or a built-in application. 

             Visual voicemail, like traditional voicemail, forwards your unanswered calls to a voicemail box. Unlike traditional voicemail, the voicemails are delivered to your phone over the data network as a sound file. Because it is stored as a file on your phone, you can listen to your voicemail at any time once it has been downloaded. You can select an individual message to listen to without having to listen to all of your other new messages first.


Visual Voicemail App Screenshots 
 
  
                  Visual voicemail is a relatively new voicemail technology when compared with traditional phone based voicemail systems. In a few words: visual voicemail is a way to listen and interact with your voicemails through a graphical interface. VVM was first heavily publicised in 2007 with the release of the iPhone 2G which contained a native client to handle visual voicemail systems.

                   Being able to access your voicemail visually without the need of all the extra prompts and annoyances striked great support and today visual voicemail exists in most carriers around the world. However the introduction of visual voicemail in itself created a whole new surface area which could be targeted to gain access to someones voicemail.
                 
                   Under the hood, when visual voicemail is used, the visual voicemail client connects to an IMAP server in the background. The authentication process is done fairly seemlessly, and most of the times, no pin prompt is required.

                   Any voicemails ever left via the phone to you are then forwarded to the inbox of your personal email-like account and a two way relationship is formed. Actions made through visual voicemail are forwarded on to reflect changes on legacy voicemail servers.




Referance Link:
http://en.wikipedia.org/wiki/Visual_voicemail
https://support.solavei.com/en/mobile-service/visual-voicemail
http://www.att.com/devicehowto/index.jsp?id=stepbystep_KB419752&make=Samsung&model=GalaxyS5G900A
http://shubh.am/breaking-international-voicemail-security-via-vvm-exploitation/

Thursday, May 21, 2015

Augmented Reality 

                   Augmented reality (AR) is a live direct or indirect view of a physical, real-world environment whose elements are augmented (or supplemented) by computer-generated sensory input such as sound, video, graphics or GPS data. It is related to a more general concept called mediated reality, in which a view of reality is modified (possibly even diminished rather than augmented) by a computer. As a result, the technology functions by enhancing one’s current perception of reality. By contrast, virtual reality replaces the real world with a simulated one. Augmentation is conventionally in real-time and in semantic context with environmental elements, such as sports scores on TV during a match. With the help of advanced AR technology (e.g. adding computer vision and object recognition) the information about the surrounding real world of the user becomes interactive and digitally manipulable. Artificial information about the environment and its objects can be overlaid on the real world.


AndAR - Android Augmented Reality

AndAR is a project that enables Augmented Reality on the Android platform. The whole project is released under the GNU General Public License. This means you can freely use it in any of your projects, as long as you license them under the same license, this means the GPL. As it is a Open Source project any code contributions from you are welcome. ARToolworks offers commercial licensing for the underlying ARToolKit.


Download sample android app here.
Source code here.


Reference Link:
http://en.wikipedia.org/wiki/Augmented_reality
http://code.google.com/p/andar/
Install Turbo C, C++ in Ubuntu


Steps for installation....

Step 1) INSTALLATION

Download DOSBox Emulator from USC [Ubuntu Software Center].


download dosbox from ubuntu software centre

                                                OR

Run this command in terminal(Ctrl+Alt+T): 

code:


 
sudo apt-get install dosbox

When your done installing Dosbox you will now require the turbo C++ installation setup which could be downloaded from here(download).

Unzip the setup zip folder and place the files in home/your-user-name directory (* Necessary)

Now open up Dosbox and Type in the below code (in separate lines):


Code:

mount c ~
c:
cd setup
install.exe 


mount dosbox to run turbo c

     This will start the setup of  Turbo C++.


turbo c installation setup

     Here choose the destination drive as c and source path as setup in the next window.



source drive to use turbo c




   Select "Start Installation" in the below window.



start installation

Turbo C++ is now installed on Dosbox. 
To run the Turbo C++ every time run the following commands:


Code:
c:

cd TC\bin

tc.exe 



To enter into fullscreen mode press  Alt+Enter and press it again for window mode.

Step 2) Creating the configuration file

creating configuration file
Run this command in DOSBOX to generate the configuration file which will be stored as: /home/user-name/dosbox.conf.  Ensure you enter your system user-name in place of "your-username" in the below code: code: 

config -writeconf /home/your-username/dosbox.conf

Step 3) Creating auto-mount and emulating in fullscreen.

auto mount in full screen
Open dosbox.conf that we created earlier in any text editor, which you will find it under home/your-username, and configure DOSBOX for auto-mount.
Add the following lines at the end of the configuration file as shown in the above highlight. code: 
mount c ~ /home/your-username/
C:
CD TC
CD BIN
TC
Now to set the default screen size to full-screen, find the word fullscreen in the same file (dosbox.conf)  and change its value to true:
Now you are done setting up the configuration file for Dosbox to auto-mount and emulate in fullscreen. Save the file and close it. Step 4)  Deleting Ctrl+F9 key to avoid shutdown of Dosbox And in the end you will have to delete a key from the Dosbox keymapper : Ctrl+F9 Since Ctrl+F9 is a Shutdown key in Dosbox you may feel very irritated with it, as the same key is used to compile a program in Turbo C++. To work-around this issue, open dosbox and hold Ctrl+F1. Now in the window, select the shutdown option on the right hand side bottom, click on delete and then save and exit. This should remove the keymap to Shutdown DOSBOX.
dosbox key mapping

Step 5) Creating Launcher

To make things more convenient, we will create a launcher so that you can run your compiler just by double clicking on it. Here's how you can do it:  Right click on the desktop and select create launcher. Name: Turbo c++ command: dosbox -c TC.EXE -c EXIT
If there is no option for create launcher:
gnome-desktop-item-edit --create-new ~/Desktop
This will launch the old GUI Dialog and create a launcher on your Desktop:
enter image description here
Prerequisites
gnome-desktop-item-edit is installed automatically if you have installed gnome-shell/gnome-fallback. It is also installed automatically if you have previously installed gnome-tweak-tool.
Alternatively, you can install the old gnome-panel without much of the bulk:
sudo apt-get install --no-install-recommends gnome-panel
Reference Link:

Wednesday, May 20, 2015

SDK vs NDK

                  
                SDK is the main development kit for Android apps - it contains tools for Java and resources (png, xml) compiling, packaging to apk file, installing, running and debugging them on a device, an emulator, documentation, etc., etc. NDK is a set of tools to compile C code to shared lib, which you could use in your app - and that's all.

                  You could create an app using SDK only - most of apps does that. However you can't do it using NDK only, because you can't run or publish .so library just like that - you have to use SDK to integrate your library with the rest of an app.

                 Java is the main language for Android development, so it has access to all APIs, also OS requires you to use Java in some places, e.g. when using Android UI. But NDK gets more and more APIs, so it's now possible to develop nearly whole app in C.

                 Java is a VM based based programming lang. c++ is a native language. the difference is that java gets compiled to VM byte code. These byte codes are the same for every android phone out there. the VM takes the byte codes and executes them (there is more, just a quick overview). since every phone has an implementation of the Dalvik VM (the one used for Android) then every application written in java can be run essentially the same on all devices.

                  C++ is compiled for specific hardware in mind. it gets compiled to cpu instructions. if you compile a c++ binary for a x86 machine its not going to run on an ARM based platform. since there are soo many different ARM based platforms, TI OMAP, snapdragon, tegra 2, etc, each with a slightly different implementation of the ARM standard there is an amount of incompatibility in compiled binaries.

                It’s important to know the NDK which is a powerful tool in the development of mobile applications. Especially if you want to develop a multiplatform application, the NDK is unbeatable in this domain. Since the same code written in C + + for Android can be easily ported and run the same way on the iOS, Windows or any other platform without changing the original code. Which actually save a lot of time in the development of applications which are developed for being run on multiple platforms; as games and other classic applications. Thing you cannot do with the SDK.

                 The Android software development kit (SDK) includes a comprehensive set of development tools. These include adebuggerlibraries, a handset emulator based on QEMU, documentation, sample code, and tutorials. Currently supported development platforms include computers running Linux (any modern desktop Linux distribution), Mac OS X 10.5.8 or later, and Windows XP or later. As of March 2015, the SDK is not available on Android itself, but the software development is possible by using specialized Android applications.

                  Libraries written in CC++ and other languages can be compiled to ARMMIPS or x86 native code and installed using the Android Native Development Kit (NDK). Native classes can be called from Java code running under the Dalvik VM using theSystem.loadLibrary call, which is part of the standard Android Java classes. The ADB debugger gives a root shell under the Android Emulator which allows ARM, MIPS or x86 native code to be uploaded and executed. Native code can be compiled using GCC or the Intel C++ Compiler on a standard PC.

Reference link:
Generate project theme on-line to reduce programming affort

1) Generate Theme: 

2) Action Bar Style:

3) Custom Button Theme:

4) Launcher Icon Generator:

5) Menu Icon Generator: