Wednesday, July 20, 2011

Cloud To Device Messaging

C2DM -  Cloud To Device Messaging.



    what is the Requirment?
  • We want to keep the data on the device fresh.

    What is Cloud to Device Messaging?
  • To push infromation from intrenet to android phone.This is called C2DM.

    When was it Intrduced?
  • From Android2.2 or API 8

    Why was this introduced?
  • The standard mechanism of application which requiers information from internet requires to poll periodically. which involves consumtion unnessary usage of bandwidth and battary use.

    How it works?
  • To use C2DM on your Android device you have to write an Android application.
  • This application should be registered with Google server to able to recive push messages from Google server.
  • Your server registers with the Google server and authenticates himself. Then your server can push messages to Google Server in turn push messages to the infromation to the devices.
  • For this authentication you reqire a Google user.

    what are the device Requirments?
  • C2DM only works only on Android2.2
  • Requires Android Market application is installed on the device.
  • To use C2DM on the Android emultor you also need to use a google device with API 8 or higher (Android 2.2 or above) and to register with a Google account on the emulator via the settings.
    What are C2DM Limitations?
  • Still in Labs
  • Message payload limited to 1024 bytes
  • Message be get last or be delivered out of order
  • No Support for TTL's - i cannot say that message expires if the devices is not avaiable in 2min .. but it will develiver the messages even the message is outdated
  • Quota limits are not clear

    How does the Information Flow?
  • In a C2DM you have three parties involved.
            1. The server which wants to push messages to the Android Device - Application server
            2. Google C2DM Server
            3. Android Application

  • To enable C2DM for an Android application, your application must register with the Google C2DM servers. After registration it receives a registration ID from Google C2DM Servers.
  • The Android Applicatoin must then send the registration ID to its application server.
  • When the application server needs to push a message to the Android application, it sends the message via HTTP GET to Google C2DM servers.
  • The C2DM servers route the message to the device once the device is available, and an intent broadcast is sent to the Android application.

    How the registration process takes place?
  • To register your application for the C2DM service your application needs fire an registration intent "com.google.android.c2dm.intent.REGISTER" to C2DM server.
    This intent includes a Google mail address and the application ID.
  • Upon successful registration the C2DM server broadcast a REGISTRATION intent to the application which includes a registration ID. Each registration ID represents
          a particular device, e.g. every Android phone will recive its own registration code.

Open GL Concepts


OpenGLES From the Ground Up, Part 1: Basic Concepts

OpenGL Data Types:
  •  OpenGL is a cross-platform API, and the size of data types can vary depending on the programming language being used as well as the underlying processor (64bit, 32bit,16bit).
  •  OpenGL maintains in own custom data types. When passing data to the OpenGL you need thru the OpenGL Data types.
Here are OpenGL ES Data types:-

GLenum: An unsigned integer used for GL-specific enumerations. Most commonly used to tell OpenGL the type of data stored in an array passed by pointer to indicate that the array is made up GLfloats.

GLboolean: Used to hold a single Boolean value.  OpenGLES also declares its own true and false values (GL_TRUE and GL_FALSE) to avoid platform and language differences. You can also pass YES or NO it won't heart you but it is good to following the GL defined values.

GLbitfield: These are four-byte integers used to pack multiple Boolean values (up to 32) into single variables using bitwise operators.

GLbyte: A Signed, one-byte integer capable of holding a value from -128 to 127

GLShort: A Signed, two-byte integer capable of holding a value between -32,768 to 32,767

GLint: A Signed four-byte integer capable of holding a value between -2,147,483,648 and 2,147,483,647

GLsizei: A signed, four-byte integer used to represent the size of data, similar to size_t in C.

GLubyte: An unsigned, two-byte integer capable of holding a value between 0 and 255

GLushort: A unsigned, two-byte integer capable of holding a value between 0  and 65,535

GLuint: An unsigned, fout-byte integer capable of holding value between 0 and 4,294,967,295

GLfloat:

GLclampf:

GLvoid:

GLfixed:

GLclampx:


The Point or Vertex:    
  • The atomic unit in 3D graphics is called the point or vertex.
  • These represent a single spot in three dimensional space and are used to build more complex objects.
            Definition of Polygon: In geometry polygon is a  plane figure that is bounded by a closed path or circuit, composed of finite sequence of straight line segments.
  • Polygons are prepared out of these points and objects prepared out of these polygons.
  • Open GL ES only supports the use of three sided polygon (Aka triangle)


  • Select an arbitrary point in space and call it the Origin.
  • You can then designate any point in space referencing the origin
  •  Core Graphics, which is another framework for doing graphics on iPhone uses a slightly different coordinate system in that the y axis decreases as it goes up from the origin, and increases as it goes down.
  • Since any object's location in three-dimensional space can be represented by three values, an object's position is generally represented in OpenGL by the use of three GLfloat variables.
                        GLfloat vertex [3];
                        vertex [0] = 10.0;        - > x-position
                        vertex [1] = 23.75;      - > y-position
                        vertex [2] = -12.532;   - > z-position

  • In OpenGL ES, you generally submit all the vertices that make up some or all the objects in your scene as a vertex array.
  • A vertex array is simply an array of values that contains the vertex data for some or all of the objects in the world.
  • we can define a data structure to hold a single vertex, like this
            typedef struct {
GLfloat x;
                        GLfloat y;
                        GLfloat z;
            } Vertex3D;

By doing this, our code becomes much more readable:

                        Vertex3D vertex;
                        vertex.x = 10.0;
                        vertex.y = 13.75;
                        vertex.z = -12.532;
  • Distance between two points in three-dimensional space with this simple inline function:
                      
            We can implement this formula to calculate the straight-line distance between any two points in three-dimensional space with this simple inline function:
static inline GLfloat Vertex3DCalculateDistanceBetweenVertices (Vertex3D first, Vertex3D second)
{
    GLfloat deltaX = second.x - first.x;
    GLfloat deltaY = second.y - first.y;
    GLfloat deltaZ = second.z - first.z;
    return sqrtf(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ );
};
 -------------------------------------------------------------------------------------------------------------------------
 -------------------------------------------------------------------------------------------------------------------------
Triangles:
Since OpenGL ES only support Triangles, we can also create a data structure to group three vertices into single triangle object.
typedef struct {
            Vertex3D v1;
            Vertex3D v2;
            Vertex3D v3;
}Triangle3D;

Winding: which just means that the order in which the vertices are drawn matters.

Front Face: Unlike the objects in the real world which is having two sides. The objects in the OpenGL have one side, which is considered the front face, which is facing the viewer.

Blackface: The side which is not visible and the side which isn’t drawn are called a blackface.

-          OpenGL determines which front face and which is the back face by looking at the drawing order of the vertices.