Wednesday, 25 September 2013

Intentional or Unintentional Unplugging of Ethernet cable or USB cable while on read or recv linux calls

   A very typical scenario when you are coding on a real-time project which requires high stability and sustainability and in the middle someone comes and pulls your ethernet cable or usb cable (in case of mobile devices). At that time your read / recv calls gets blocked and returns after a very long time.

In Linux or Ubuntu, whenever that happens, you should call two functions which would make your read / recv to come out with an error code and they are as follows:
  • shutdown - API of Linux
  • closesocket - API of Linux.

Tuesday, 17 September 2013

Build Project using NDK

Please follow the below guidelines:
  1. Consider the $PROJECT as the Project Directory, say SampleApplication as my Project.
  2. Create two Directories inside the Project Directory, namely
    1. jni\
    2. code\
  3. Place the Android.mk inside the jni\ directory.
  4. Place the entire code inside the code\ directory.
  5. Open command prompt and go to the $Project directory, then run %NDK_BUILD%, provided you are in windows and you have created an Environment Variable named NDK_BUILD which will be as follows: eg: D:\Backups\Android-NDK\ndk-build.
  6. Build the code in windows by giving %NDK_BUILD%.

Sample Android.mk File

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE            :=     libvncclient
LOCAL_SRC_FILES            :=     <source file names, current directory will be jni>
LOCAL_C_INCLUDES        :=  $(LOCAL_PATH)/include/
LOCAL_CFLAGS            :=    <MACRO DEFINITIONS>
LOCAL_LDLIBS            :=   
LOCAL_SHARED_LIBRARIES     :=   
include $(BUILD_SHARED_LIBRARY)

TADA.......................

Sunday, 15 September 2013

Create JNI File from Java Class file

Create a Simple Java Project as given below

package com.example.helloworld;

public class HelloWorldActivity {

    static {
        System.loadLibrary("hello-jni");
    }
   
    public native String stringFromJNI();

}

Compile it. Say the directory is "D:\Project\J2SE Workspace\HelloWorld\bin\classes", then go to this directory where the package starts for the class file, then give

javah com.example.helloworld.HelloWorldActivity

It will create a JNI class for you with the required functions provided in the Java file.

Thursday, 12 September 2013

Install CDT and ADT for Eclipse

Install the choice of Eclipse you need from the eclipse site.

Currently I had Eclipse Keplar

CDT
Use the Repository as below for getting the CDT plugin.
http://download.eclipse.org/tools/cdt/releases/kepler

Use the above repository URL in
Help -> Install New Software
in the Work With text box paste the above URL and press enter, it will search the site for available plugin and install.

ADT

Use the Repository as below for getting the ADT Plugin.
https://dl-ssl.google.com/android/eclipse/

Use the above repository URL in
Help -> Install New Software
in the Work With text box paste the above URL and press enter, it will search the site for available plugin and install.