Saturday, December 10, 2011

Configuring CSipSimple SIP client on Galaxy SL for Nymgo

Here is the configuration to be done. These is carefully written to cover most of the points and a hastle free experience when you do the setup. You can refer to nymgo.com site, they have given some basic info, it would serve as reference.

First when adding account, you need to select the Basic Wizard.
Menu Key -> Accounts  -> Add Account  -> Generic Wizards -> Basic

  • Account Name: Nymgo
  • User: Nymgo User Name
  • Server: ata.nymgo.com (no need to give port number even though we knows its 80, it would be taken care by wizard, and if you give, it seems to be not working for me)
  • Password: Nymgo Password.
You are almost done !! 

Next thing is that, we should be using UDP for communication, so 

Menu Key (Left Soft Key in Galaxy S) -> Settings -> Network
Do the following settings -> UDP port number set as 5060

Stun should be on -> set it to stun.nymgo.com:80

Set Networks for All outgoing calls.

Settings -> Media
* You need to disable all codecs except below ones
   G729 8Khz (Wideband)
   G729 HKhz (Narrowband)
* Use Samsung Galaxy Hack [ checked ]
* Micro / Speaker amplification can be used if audio is very low, I have used mirco to 5 and audio as it is.

Settings -> Call options
Caller id -> Set to your own number, if you have used caller id feature in Nymgo.

Settings -> Filters 
These can be used when you have enabled the Android integration, and can be used to make sure all numbers starting with +91 (India) can be made to go through phone dialer and International calls through Nymgo, I have enabled it, but its optional, let me know if you have any questions here.

Once the configuration is done, dial 111 from your SIP dialer and wait for Nymgo test service, and you would be able to test if you configuration is working fine, if you could hear your own voice back after recording, then you are ready to use nymgo, feel free to drop your comments and queries, I would be glad to help you.


Saturday, November 12, 2011

Some of the useful info when working with ADB on phone


For remounting the system partition as RW on Galaxy SL, (need to be super user)
# mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

For mounting back to RO
# mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

Basic ADB commands
# adb push <local_path> <remote_path>
# adb pull <remote_path> <local_path>
# adb install <path_to_apk>

If you have not installed the cp command may not work, the work around would be 
# cat [source_file] > [destination_file]

The command binaries would be located at this location, /system/bin/ And if you had installed busybox, in /system/xbin/ then first the above path is looked for command, and later the below path.

The /system partition has limited memory, so if you try installing too many applications here, then you may run out of space, and its a better idea to delete many of the unwanted bloat applications from there. I have deleted the following apps and they do not be of much use for me. May be if its not useful for you, you can delete them as well. And you can also delete any other apps which are of no use for you.
  1. Samsung Apps [They are meant for Bada, and of no use in Android! wonder why its added here!]
  2. BuddiesNow.apk/odex
  3. thinkdroid.apk/odex [ThinkFree Office - I have installed Polaris Office instead of this, which is much better]
  4. Day.apk/odex
  5. DualClock.apk/odex
  6. SamsungWidget_Calenderclock.apk/odex
  7. SamsungWidget_Feedandupdate.apk/odex
  8. SamsungWidget_stockclock.apk/odex
  9. SamsungWidget_Weatherclock.apk/odex
All the best, and keep a backup of the file before altering or deleting any file inside /system partition, so that you can restore if something goes wrong, and I am not responsible for any thing if at all it goes wrong :)
Some useful tips and tricks about galaxy S/SL can be found here, its quite long, but when free go through.

Monday, October 3, 2011

Install Polaris Office of Galaxy S2 on Galaxy SL i9003

Polaris office is one of the office suite for mobile, similar to the many available for mobile phones. Galaxy SL comes with think free office, which is also good, but formatting, editing are much better in Polaris office. 

You need to have root for installing this application, as it needs to be installed in system folders. I have referred to this post of xda for installation and also downloaded from the link provided there.


Here is the procedure to follow to install the same

1. Extract the files from compressed file
2. Copy apk from app to /system/app
3. Copy files from lib folder to /system/lib

You may have to free some space in /system folder as that partition is of limited size, and you may need to delete unwanted applications and may be you can delete the think free application.

Tuesday, September 27, 2011

Update i9003 with Galaxy S-II Dock Icons

Bored of the same dock bar at the home screen, and you think the Galaxy S-II one looks much better. Its not difficult to update it to that. All that you need it root permissions.

I could not get this full information in one place on net, so if you are reading my blog you are lucky to have all the information in one place. You do not need to install a custom TouchWiz, you can modify what you have right now. I am running TouchWiz 4.0 for your information. (Galaxy SL - Gingerbread 2.3.4 XXKPH) 

First have copy Contact.apk, Email.apk, Mms.apk and TouchWiz30Launcher.apk & DialerTabActivity from system/app to PC, then Open it with any tools such as Winrar or 7Zip, do not extract.


check the icons in the path - res/drawable-hdbi.


-Contakt.apk: ic_launcher_contacts.png
-DialerTabActivity - ic_launcher_phone.png
-Mms.apk: ic_launcher_smsmms.png
-Email.apk: icon.png
-TouchWiz30Launcher.apk: mainmenu_icon_application.png and mainmenu_icon_home.png.

Replace all these icons with new Icons and drag and drop into the 7Zip explorer.
Copy the .apk fils back to system/app and restart the launcher or the phone.

It should look something like this, after you have updated everything that is mentioned here.


That goes with many stock apps. I hope its useful.

The Samsung Galaxy S-II icons can be downloaded from here.

Sunday, September 25, 2011

Customize Icon Tiles for Galaxy SL i9003

As I had mentioned in the previous post about the TouchWiz 4.0, the icon backdrops/tiles are not set as it should be. I mean to say, even though in the apk, all of the tiles have been named as to which icon it should be applied, they are not been applied to them. My belief is that it must be because of the mismatch of the binary and the TouchWiz 4.0 apk, but I am not sure. I need some expert to comment here.

I have referred to this post, and worked my way, it was mean for touchwiz 3.0 for getting rid of the icon tiles by replacing them with transparent ones. I have followed the same procedure and replaced the unwanted tiles with the one I want to have.


All you need to have is a rooted phone, because for replacing touch wiz files you need to have root permissions. You also need to have ADB and Tool like Winrar or 7Zip. I use 7zip.

First take out the TouchWiz30Laucnher.apk file located in the '/system/app' folder and put on your desktop or somewhere. Use the below command. 

adb pull /system/app/TouchWiz30Launcher.apk <local_path>

Now you can open this apk file in 7Zip, do not extract, but replace the tiles you want by directly dragging and dropping in to the 7Zip window. The tiles would be located at '/res/drawable-hdpi-v4/' or similar folder, use your common sense, they would start with something like 'mainmenu or homescreen' and end with '_bg.png'

Once you are done replace this apk with the original apk present in the '/system/app/' folder. remember to keep a copy in case if you have done something wrong.
In the windows command prompt, use adb push to push the apk into SD Card.



> adb push <local_path>\TouchWiz30Launcher.apk /sdcard/
> adb shell
$ su
# mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
# mv /system/app/TouchWiz30Launcher.apk /system/app/TouchWiz30Launcher.apk.bak
# cp /sdcard/TouchWiz30Launcher.apk /system/app/TouchWiz30Launcher.apk
# chmod 744 TouchWiz30Launcher.apk
# mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system
# exit
$ exit
> exit


What I have done here its, first pushed the apk to sdcard, opened the adb shell, logged in as root, mounted the system partition as read/write, renamed the original file to keep a backup and then copied the new file from sd card to the original file's path, them changed the permissions as needed, and remounted the file system as read only and then exited.


I will update a screen shot, to show that all of market applications which use to use some crap icon tiles now use the system icon tiles and the UI looks pretty good, and I feel its much much better than before. Only problem is that the way it chooses background is still random, and every time you restart the icon tiles would change. :) 

Monday, September 19, 2011

Install Busybox on Samsung i9003 Galaxy SL

First of all let me tell me if busy box is needed for you. Mostly it is needed because the adb shell does not have most of the commands supported such cp (copy), and it makes it difficult when you want to modify something (if you have rooted already) difficult because of unavailability of the commands support. So it is preferred to have Busy box, which has most of the command support, and if you had worked in Linux you would know what is busy box for.

Usually, you need to copy the busy box binary on to whichever folder you need, with the help of any command line tool, then say busybox --install, it should setup the links for all the commands and should work for you. And you may need to add that path into you PATH variable. Somehow after long search, I could not find any such thing working for me. 

But now that this application names 'busybox installer' does exactly the same, and it needs root permissions (to make it install in /system/xbin/ ) and you have the option to install any version of busybox you wish to.

So my search ends here (somehow I had seen this before, and dint want to do it this way, wanted to do it manually). One you have installed it, it will automatically restart your phone. Now you have all the comands available on your phone when connected to adb. Some commands may still be taken from old toolbox, and if you specifically need busy box one, you can override it by typing busybox before it. 

Samsung Touch Wiz 4.0 Look and Feel

This post is dedicated for showing the Look and Feel of Touch Wiz 4.0 Running on Galaxy SL (i9003). If you follow my previous post, absolutely there are no bugs, no lags, and only excitement !!

Here are few screen captures for showing all the features


 Fig 1: Picture showing home screen, if you observe, you can add as many icons as you want in the dock below. And the look and feel of home icon is updated.


Fig 2 : Picture showing the app drawer, you can see that instead of black now you have the transparent screen, and icon tiles have been removed, in fact you have option to enable or disable the same


 Fig 3 : Home screen widgets are more standardized and looks more like Galaxy S-II, I usually don't like widgets and only widget I use is weather bug.


Fig 4: Wallpaper options are more neat and clean, and it looks much better as show above.


Fig 5 : App drawer editing is also improved and you can specify the number of columns and rows and also the number of icons. The best part is if some one likes to have folders then that option is also allowed. There is unofficial version named as Touch WIz 4.5 also available in XDA which seems to be modified a lot, and so, I do not recommend, but it does have lot of other enhancements.

The icon tiles can be enabled to have backdrops for each icon, but it seems to be randomly picking the tiles from somewhere. I myself have opened the apk file in 7zip and see that most of the apps have well defined backdrops/tiles, but the TouchWiz 4.0 is messing up with it, and seems to be mismatch when it picks the icon tiles, so you may not be very impressed with icon tiles, you may have to live with it. I absolutely have no idea how they are picking the icon tiles at this point, if someone knows and why it behaves like this please do let me know.

Sunday, September 18, 2011

Replace ADB Shell With Putty

If your phone is rooted, you need ADB (Android Debug Bridge) for accessing the phone over command line. And when on Windows you may not be comfortable running the Linux command prompt on Windows. You can always run a telnet server on your android phone, and connect using the Putty, but this needs lot of work, and its not an easy option. 

There is an easy option with the help of ADB, you need to have a modified Putty for this, which has the ADB connection type to choose from, and then you can use Putty as you normally use to. Thanks for senior XDA member sztupy. sztupy has compiled a Putty binary with most of the settings pre-set. Here is a snap shot of the same for your reference.

image

All you need to do is to set the host name to 'transport-usb' as shown and if port number did not come automatically set it to '5037' and you are done. 

Connect the phone using usb cable ans set the debugging mode on, as you normally do to use with ADB, you can enjoy the familiar Putty interface.

Install Samsung TouchWiz 4.0 for Galaxy SL i9003

If you have updated to the Gingerbread 2.3.4 and rooted by following posts on my phone, then you would see that there is not much cosmetic changes done to the User Interface, except for the status bar battery icons etc. The easiest way is to update to a new UI is to install any other launcher such as Go Launcher. In fact Go Launcher Ex is very powerful, and it has most of the features you would look for in your phone, and also many themes are available for download. As a second launcher I would always have it on my phone, in case the primary one fails after some updates etc. 

But the battery consumption seems to be very high, may be because of the visual effects. The main reason I wanted to update to new UI theme is that, with Galaxy S2, Samsung had get rid of that icon tiles which would give an iPhone type look. But sometimes the choice of wrong color for the tile makes it look very boring, and some how I am bored with it, and want to get rid of it.

So, I come across this link on XDA, and he has given the TouchWiz 4.0 Launcher apk, which is working fine with my Galaxy SL, and I have obsolutely no issues with it. Few of the Widgets does not work with it, especially the Samsung ones and mostly you don't need them at all, so you can delete them get rid of it.

The install process is very simple,

  • Copy it to SD card via ADB or any other method.
  • Use ADB connection, and login as root.
  • Mount the /system/ as RW
  • There will be TouchWiz30Launcher.apk and TouchWiz30Launcher.odex files, make a back up of them incase if something goes wrong.
  • Replace the TouchWiz30Launcher.apk with the new one downloaded.
  • You need to place the lib file inside the /system/lib folder
  • Use cat source > destination as cp command does not work

Now that most of things work except for Samsung Widgets, There is an Share button when you edit the app drawer, which would cause a force close, you need to fix this.

Download the ShareApp.apk from here, and place it in the /system/app/ folder following the same method mentioned above.

You are DONE, you would have a fully running, low battery consuming Samsung Touch Wiz 4.0 ready on your phone, Enjoy.

The Benefits are as below. 

For appdrawer:
  • column count
  • item count per page
  • free sort mode / alphabetical sort
  • enable/disable colored tile
For Home screen:
  • enable Landscape mode (if you change from off to on -> needs a reboot to take effect)
  • use big page indicator icons
  • whether to show the App names
  • uninstall apps from home screen [on/off]
  • page indicator icon fades off after swiping [on/off]
  • amount of rows on home screen
  • screen count-defaultscreen (starts at 0)
  • amount of icons in dock (not tested with higher numbers then 5)

Friday, September 16, 2011

Google Music Beta on Android

You might have heard that Google had launched the music beta service, which is similar to the other Google service which is linked to your Google account, but only limitation as of now is that it is available on in the United States, and it also says that its free for limited period of time. May be only till the beta testing is complete, but I hope to have it continued after that. You can store about 20,000 songs to your account and they will be stored in cloud, so that it can be accessed from any device, such as TAB or Android Phone. You can carry your music collection where ever you go, sound impressive huh? why don't you get one? 

All you need is an US proxy and log into your Google account from the proxy server or VPN and request for one, or if you have a friend who can send invite ask him to send one. So you would get the invite in few days if you have requested for one. 

After the invite is received you can download the music manager from music.google.com and install it. 
  • Make sure you keep all your tag information for the songs updated before uploading using Google Music Manager, otherwise it becomes a mess later to organize your music. Google music would organize your music based on the tag information.
  • Also make sure that you use the folder upload option rather than windows media player library sync, because mostly if you have updated the tag information recently, it seems to be not working fine. 
  • Anyways, follow which ever method, but upload the music, but one thing to remember, while uploading you don't need to be in VPN, and sometimes with VPN, if corporate it will not work.
Now you need android application to use the same music on your android device, but if you are not in US, then the market wont allow you to install from there, even though it is free application. So you need to download it from here, and install using any other method, such as copy to SD card then install by enabling non market application installation in settings.


Once you have installed fortunately, it does not need a VPN to play your music, you can be in any country, Wifi/3G/EDGE/GPRS, it can play the music for you.


Thursday, September 15, 2011

Root Samsung Galaxy SL (i9003) Gingerbread 2.3.4 (XXKPH)

I had hard time finding how to root the Samsung Galaxy SL, 2.3.4, XXPKH. There were many blogs and website talking about rooting, but because XXKPH was the latest version and it was 2.3.4, most of the methods mentioned in there does not work. 

The most basic method is to use the SOC (Super One Click) and it does not work with XXKPH, because the kernel exploit cannot be done by Ginger break, and it seems they have closed the loophole which ginger break was using. The original Ginger break method was mentioned in this website, and he has clearly mentioned that it has to be using the usb debugging mode on adb. SOC also uses the same method, and it should be the only way to do it.

Now how do we proceed, I read in a Spanish website for i9000 that the kernel must be replaced with a kernel which can be exploited and then exploit using SOC and replace back the original kernel after installing SU (super user app). I found it something convincing and then tried the method on XDA developer where he talks about flashing the fixed binary and then normal boot again. I was scared to try this before as I do not want to use any modified binary as the XXKPH is very stable, and battery life and GPS are working awesome for me. Any change would only deteriorate the performance, as these people may have done somethign which they are not very sure of.

Here goes the method for XXKPH
  • After Flashing to new Firmware , Go to Downloading Mode By pressing volume down + menu button + power button and Flash the Phone Using the PDA file GT-I9003_PDA_XXKPE-fixed.tar
  • Root USing SOC (Latest version of SOC can be downloaded from here)
    • While rooting, you may find that it it stuck at step #6, may be you can disconnect the cable and connect back, and it should do the trick !! (happened with me)

  • Flash PDA with the normalboot.img.tar attached below
Note: With the absolutely beautiful ADB exploit I use, titled rageagainstthecage (ratc), absolute ALL devices can be rooted. This is because it exploit is ADB which all devices use. There is an issue though. Some devices have a NAND lock which does not allow you to write to the /system mount. Because of this, you can't copy su, sqlite or busybox to /system/bin. This creates some issues but there is a work around. For things that don't need access to /system (like enabling non-market apps) I can use the ratc exploit to make those changes. If your device cannot use su in /system/bin then you can simple select a checkbox (as of v1.5) that says to use ratc. 


There are 3 levels of "root" we can define:
Level 1: Shell Root (with ratc rooting the adb shell but no /system write access)
Level 2: Temporary Root (/system/bin/su installed but lost on reboot)
Level 3: Full Root (/system/bin/su installed and sticks)

Some devices have a NAND lock. SuperOneClick will only give a Shell root until you remove this lock.

Gingerbreak uses rageagainstthecage,  is a root exploit via a fork bomb. Some antivirus program may raise alert for malicious content while unzipping, and here is the explanation for it. 

It IS a potentially malicious payload, BUT it is being used with owner's consent to root the phone. The DreamDroid malware use exactly same payload - they are trojans, but this is a helpful tool. It IS a dangerous tool in the wrong hands, but this is a root exploit, so you should exercise common sense and a little understanding of what it does and how it works.

Tuesday, September 13, 2011

Update Galaxy SL (i9003) to Gingerbread 2.3.4

I followed the procedure from here. Out of all the guides out there, which are most confusing this is the best one I have ever come across. He is clear and straight forward of what you have to do, and small guide, not to get confused with lengthy ones.

I am copy pasting it here for your reference, may be for my reference later, as I am not interested with all of it.







Note: XXKPH can only be flashed with help from it's supporting predecessor XXKPE, So make sure you have XXKPE downloaded. User flashing version varies with this, but this is my successful 100% assured boot.
  1. Firstly, Download the link from spacebar's XXKPH Feedback thread.
  2. Run Odin3 v1.83
  3. Set your phone to download mode : Press Volume down + OK first, then hold Power button.
  4. Connect your phone, you should see Odin shows your phone is Added with COM number.
  5. Click PIT button and select this file: latona_20110114.pit
  6. You should see Re-Partition, Auto Reboot and F. Reset Time checked.
  7. Click PDA button and select this file: CODE_I9003XXKPE_CL409735_REV08_user_low_ship.tar
  8. Click PHONE button and select this file: MODEM_I9003XXKPE_REV_00_CL1041909.tar
  9. Click BOOTLOADER button and select this file: APBOOT_I9003XXKPE_CL409735_REV08_user_low_ship.tar
  10. Click CSC button and select this file: GT-I9003-CSC-MULTI-OXAKPE.tar
  11. Click Start button to flash these files to phone.
  12. Do not touch anything till you see PASS on the program window.
  13. Turn off the phone and set it back into download mode once you get an initial first boot to homescreen. Do not set up anything, Just power off and set to download mode. 
    Note: You only need to flash once to XXKPE before proceeding to XXKPH
  14. In Odin, press Reset button. Re-partition should be unchecked automatically.
  15. Select file I9003XXKPH_I9003XXKPH_I9003SERKPH_HOME.tar as PDA
  16. Click on Start to flash XXKPH PDA to phone
  17. Once you have flashed, after the phone started up, press *#1234# and check your PDA,Phone and CSC, everything should ended with KPH
  18. Factory reset and enjoy
Feedback: These is my experience and it may differ.

I had updated for KB2 Indian version. I flashed first XXKPE as suggested by the guide, and then XXKPH. 
  1. Now the battery life seem to have increased, I am not very sure about it, but feels like, my phone use to always crib low battery, and not it does not happen. I hardly put on charging these days :)
  2. No overheating etc, as some might have wrongly mentioned, but as far as I know this is official release for Russia so such issues can't be there
  3. All peripherals and system functions such as wifi, camera everything works fine.
  4. The GPS works like charm, and it has been fixed, it locks within 5 seconds and you are connected. 
  5. There are three new apps
    • Samsung Navigation Route 66 - which seems promising, it has information about the city, so easy to search and navigate.
    • Publication Reader - You can put your paper/magazine subscriptions and can be read offline.
    • There is a short cut to downloads which was much needed and was missing in previous version
  6. Not many cosmetic changes compared to 2.2 Froyo, it's all the same look and feel. The boot animation music has changed, I felt previous one was better.
  7. Performance has not changed much, it's almost same, may be little better I could say. 
  8. Last, but not the least Gmail video chat is something which is expected in 2.3.4 and it does not present in this, and for this you need to root and install the apk from outside, but as of now no good rooting available for 2.3.4, and whatever present seem to be not working.
  9. So if you have problem with battery life, then only update, else no need, and don't wait for gmail video chat support to come, I don't think it would ever come on SL
Note: All the binaries needed can be downloaded from here

Monday, July 25, 2011

Type Casting in C++

Converting an expression of a given type into another type is known as type-casting. We have already seen some ways to type cast:

Implicit Conversion

Implicit conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. For example:

short a=2000;
int b;
b=a;

Here, the value of a has been promoted from short to int and we have not had to specify any type-casting operator. This is known as a standard conversion. Standard conversions affect fundamental data types, and allow conversions such as the conversions between numerical types (short to int, int to float, double to int...), to or from bool, and some pointer conversions. Some of these conversions may imply a loss of precision, which the compiler can signal with a warning. This can be avoided with an explicit conversion.

Implicit conversions also include constructor or operator conversions, which affect classes that include specific constructors or operator functions to perform conversions. For example:


class A {};
class B { public: B (A a) {} };

A a;
B b=a;

Here, a implicit conversion happened between objects of class A and class B, because B has a constructor that takes an object of class A as parameter. Therefore implicit conversions from A to B are allowed.

Explicit Conversion

C++ is a strong-typed language. Many conversions, specially those that imply a different interpretation of the value, require an explicit conversion. We have already seen two notations for explicit type conversion: functional and c-like casting:

short a=2000;
int b;
b = (int) a; // c-like cast notation
b = int (a); // functional notation

The functionality of these explicit conversion operators is enough for most needs with fundamental data types. However, these operators can be applied indiscriminately on classes and pointers to classes, which can lead to code that while being syntactically correct can cause runtime errors. For example, the following code is syntactically correct:

// class type-casting
#include <iostream>using namespace std;

class CDummy {
float i,j;
};

class CAddition {
int x,y;
public:
CAddition (int a, int b) { x=a; y=b; }
int result() { return x+y;}
};

int main () {
CDummy d;
CAddition * padd;
padd = (CAddition*) &d;
cout << padd->result();
return 0;
}

The program declares a pointer to CAddition, but then it assigns to it a reference to an object of another incompatible type using explicit type-casting:

padd = (CAddition*) &d;

Traditional explicit type-casting allows to convert any pointer into any other pointer type, independently of the types they point to. The subsequent call to member result will produce either a run-time error or a unexpected result.

In order to control these types of conversions between classes, we have four specific casting operators: dynamic_cast, reinterpret_cast, static_cast and const_cast. Their format is to follow the new type enclosed between angle-brackets (<>) and immediately after, the expression to be converted between parentheses.

dynamic_cast <new_type> (expression)
reinterpret_cast <new_type> (expression)
static_cast <new_type> (expression)
const_cast <new_type> (expression)

The traditional type-casting equivalents to these expressions would be:

(new_type) expression
new_type (expression)

but each one with its own special characteristics:

Dynamic Cast

dynamic cast can be used only with pointers and references to objects. Its purpose is to ensure that the result of the type conversion is a valid complete object of the requested class.

Therefore, dynamic_cast is always successful when we cast a class to one of its base classes:

class CBase { };
class CDerived: public CBase { };

CBase b; CBase* pb;
CDerived d; CDerived* pd;

pb = dynamic_cast<CBase*>(&d); // ok: derived-to-base
pd = dynamic_cast<CDerived*>(&b); // wrong: base-to-derived

The second conversion in this piece of code would produce a compilation error since base-to-derived conversions are not allowed with dynamic_cast unless the base class is polymorphic.

When a class is polymorphic, dynamic_cast performs a special checking during runtime to ensure that the expression yields a valid complete object of the requested class:


// dynamic_cast
#include <iostream>#include <exception>using namespace std;

class CBase { virtual void dummy() {} };
class CDerived: public CBase { int a; };

int main () {
try {
CBase * pba = new CDerived;
CBase * pbb = new CBase;
CDerived * pd;

pd = dynamic_cast<CDerived*>(pba);
if (pd==0) cout << "Null pointer on first type-cast" << endl;

pd = dynamic_cast<CDerived*>(pbb);
if (pd==0) cout << "Null pointer on second type-cast" << endl;

} catch (exception& e) {cout << "Exception: " << e.what();}
return 0;
}

Compatibility note:

dynamic_cast
requires the Run-Time Type Information (RTTI) to keep track of dynamic types. Some compilers support this feature as an option which is disabled by default. This must be enabled for runtime type checking using dynamic_cast to work properly.

The code tries to perform two dynamic casts from pointer objects of type CBase* (pba and pbb) to a pointer object of type CDerived*, but only the first one is successful. Notice their respective initializations:

CBase * pba = new CDerived;
CBase * pbb = new CBase;

Even though both are pointers of type CBase*, pba points to an object of type CDerived, while pbb points to an object of type CBase. Thus, when their respective type-castings are performed using dynamic_cast, pba is pointing to a full object of class CDerived, whereas pbb is pointing to an object of class CBase, which is an incomplete object of class CDerived.

When dynamic_cast cannot cast a pointer because it is not a complete object of the required class -as in the second conversion in the previous example- it returns a null pointer to indicate the failure. If dynamic_cast is used to convert to a reference type and the conversion is not possible, an exception of type bad_cast is thrown instead.

dynamic_cast can also cast null pointers even between pointers to unrelated classes, and can also cast pointers of any type to void pointers (void*).

static_cast

static_cast can perform conversions between pointers to related classes, not only from the derived class to its base, but also from a base class to its derived. This ensures that at least the classes are compatible if the proper object is converted, but no safety check is performed during runtime to check if the object being converted is in fact a full object of the destination type. Therefore, it is up to the programmer to ensure that the conversion is safe. On the other side, the overhead of the type-safety checks of dynamic_cast is avoided.


class CBase {};
class CDerived: public CBase {};
CBase * a = new CBase;
CDerived * b = static_cast<CDerived*>(a);

This would be valid, although b would point to an incomplete object of the class and could lead to runtime errors if dereferenced.

static_cast can also be used to perform any other non-pointer conversion that could also be performed implicitly, like for example standard conversion between fundamental types:

double d=3.14159265;
int i = static_cast<int>(d);

Or any conversion between classes with explicit constructors or operator functions as described in "implicit conversions" above.

reinterpret_cast

reinterpret_cast converts any pointer type to any other pointer type, even of unrelated classes. The operation result is a simple binary copy of the value from one pointer to the other. All pointer conversions are allowed: neither the content pointed nor the pointer type itself is checked.

It can also cast pointers to or from integer types. The format in which this integer value represents a pointer is platform-specific. The only guarantee is that a pointer cast to an integer type large enough to fully contain it, is granted to be able to be cast back to a valid pointer.

The conversions that can be performed by reinterpret_cast but not by static_cast have no specific uses in C++ are low-level operations, whose interpretation results in code which is generally system-specific, and thus non-portable. For example:


class A {};
class B {};
A * a = new A;
B * b = reinterpret_cast<B*>(a);

This is valid C++ code, although it does not make much sense, since now we have a pointer that points to an object of an incompatible class, and thus dereferencing it is unsafe.

const_cast

This type of casting manipulates the constness of an object, either to be set or to be removed. For example, in order to pass a const argument to a function that expects a non-constant parameter:


// const_cast
#include <iostream>using namespace std;

void print (char * str)
{
cout << str << endl;
}

int main () {
const char * c = "sample text";
print ( const_cast<char *> (c) );
return 0;
}

typeid

typeid allows to check the type of an expression:

typeid (expression)

This operator returns a reference to a constant object of type type_info that is defined in the standard header file <typeinfo>. This returned value can be compared with another one using operators == and != or can serve to obtain a null-terminated character sequence representing the data type or class name by using its name() member.


// typeid
#include <iostream>#include <typeinfo>using namespace std;

int main () {
int * a,b;
a=0; b=0;
if (typeid(a) != typeid(b))
{
cout << "a and b are of different types:\n";
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
}
return 0;
}

When typeid is applied to classes typeid uses the RTTI to keep track of the type of dynamic objects. When typeid is applied to an expression whose type is a polymorphic class, the result is the type of the most derived complete object:


// typeid, polymorphic class
#include <iostream>#include <typeinfo>#include <exception>using namespace std;

class CBase { virtual void f(){} };
class CDerived : public CBase {};

int main () {
try {
CBase* a = new CBase;
CBase* b = new CDerived;
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
cout << "*a is: " << typeid(*a).name() << '\n';
cout << "*b is: " << typeid(*b).name() << '\n';
} catch (exception& e) { cout << "Exception: " << e.what() << endl; }
return 0;
}

Note: The string returned by member name of type_info depends on the specific implementation of your compiler and library. It is not necessarily a simple string with its typical type name, like in the compiler used to produce this output.

Notice how the type that typeid considers for pointers is the pointer type itself (both a and b are of type class CBase *). However, when typeid is applied to objects (like *a and *b) typeid yields their dynamic type (i.e. the type of their most derived complete object).

If the type typeid evaluates is a pointer preceded by the dereference operator (*), and this pointer has a null value, typeid throws a bad_typeid exception.

What our compiler returned in the calls type_info::name in the this example, our compiler generated names that are easily understandable by humans, but this is not a requirement: a compiler may just return any string.

Monday, July 18, 2011

My Favorite Android Games

There are thousands of games out there in market most of them are paid or free, but which one do you like, I did refer to people’s blog to find it out, and many like variety of games. But here is the list of paid and free games which I liked, and I play almost every day.

Angry Birds RioAngry Birds Rio is a variant of original Angry birds, so obviously it’s a FUN game, here you have different types of levels which makes it more attractive compared to the original game. They keep updating, so more fun to come in future. It’s free game but comes with Ads, if you disable the data connection while playing this game then you won’t see any ads, that’s the best way to deal with it.

Angry Birds SeasonsAngry Birds Seasons is another variant where in you can play them in different seasons such as Christmas, in snow falls etc., more or less same as the original one, but here you have some bonus levels if you complete all levels in 3 stars, so kind of challenging and keeps the game spirit on till the end of the game

Angry BirdsAngry Birds (Original) is a fun game, and you will get addicted to this game so fast that every night you have to play this before going to sleep, that’s the level of addiction.

Its whole aim is to use some physics knowledge and make the birds jump on the pigs and destroy them, who takes the eggs of these birds. There will be so many obstacles when you try to destroy them, so plan well and achieve the goal.

Bebbled

Bebbled may not be interesting to that extent, but it’s a good time pass game. There is a target pointes to be made for each level, and until you make those many points you wont be allowed to go to next level. You need to touch the bubbles of the same color to make them disappear and make points out of it. More bubbles of same colors come together the more points you get.

Bonsai Blast

Bonsai Blast is the ZUMA game which we use to play in computers, where there would be a FROG at the center and colored balls would come and you need to shoot them before reaching the end point. If you make the balls of same color count more than three, then they disappear, lot more weapons etc., are there but you need to install it to explore. It is good one, but not as good as the ZUMA, but still a time pass game.

Bubble Blast 2

Bubble Blast 2, I have never played the first version. This one has lot of levels, may be I would never be able to complete. Its just a time pass game, you don’t need to know anything, and its very difficult to plan the game also, but over all it’s a time pass game. Keep touching the bubbles and they grow and finally blast, there are some restrictions on the number of touches you need to finish blasting all the bubbles, sometimes if becomes so difficult that you may have to take an hint. Only one hint per day.

Klondike Solitaire

Klondike Solitaire  is the best solitaire game I have come across for android devices, and this one is simple and intuitive, and easy to use game. A very good time pass game. Levels are somewhat difficult.

Just disable the data connections, else the ads would be irritating.

Magic Marker

Magic Marker is not a game, but it’s a FUN app, with which you can make your phone a drawing board, and draw in different colors, which come as magic lights. If you want to write something and show to someone special may be this would come in handy.

I have the pretty old version which does not have ads, but recent version comes with ads, so you may have some irritating ads popping up in the screen.

Need for Speed Shift

Need For Speed (NFS) Shift, if you are a fan of NFS and or a fan of racing, then this is one game you must buy, such an awesome graphics and such a wonderful game play, you would love it.

There are different tracks and different cars. You need to buy the cars from the money you make from racing and build your career.

Paper Toss

Paper Toss is an game for time pass when you don’t have any work to do. It’s as simple as throwing a paper into a dust bin.

There are different levels such as office, toilet, airport, basement etc., where the distance would be different and the fan would be placed in different locations.

Pool Master Pro

Pool Master Pro is the best pool game I have come across for android. It has such awesome graphics that you keep playing and get addicted to it.

There is one more game which is 3D but then its not as good as this. Its free and ad free. So go for it.

 

Slice It

Slice it! is a game mostly for kids, but still it’s a FUN game you can play. You will be given objects of different shape and you need to slice them into N equal parts by certain number of counts.

Initially the game would be easier, and it keeps becoming complex as you go up. You may have to check your geometric skills once again. Its not as simple as slicing a piece of cake. Mind it!