System programming, Cluster computing, Writing Operating System, iOS application Development, Advanced C programming, Assembly langauge, C++
Wednesday, October 8, 2008
Sending message to service provider
Example:
1. getting prepaid account balance.
2. Getting other information from service provider (cricket, wedding, art of living... Vodafone india).
code:
CPhCltUssd* BalanceQuery = CPhCltUssd::NewL( ETrue );
CleanupStack::PushL( BalanceQuery );
TBuf<20> Vodafone_Balance_KeyString;
Vodafone_Balance_KeyString.Copy( _L("*100") );
TInt result = BalanceQuery->SendUssd( Vodafone_Balance_KeyString );
CleanupStack::PopAndDestroy( BalanceQuery );
:-)
Saturday, September 27, 2008
Auto Call Answering and playing prerecorded voice when call is active
------------------------Answering Machine in S60------------------------------------
This article is for sending prerecorded voice over UPLINK when call is active.
1. Whenever an incoming call is coming this application will automatically answers the call.
2. Then it will play a prerecorded voice over uplink.
3. Once play completes it will automatically terminates the call.
Class that need for achieving this
1. CTelephony
---->This class is used for getting notification change, whenever there is a change happens in voice line. It’s not only for getting the notification and also dialing a new call, answering an incoming call, holding, & resuming call etc… But there are some problem using CTelephony classes. Most of the functions in CTelephony calls are asynchronies functions so we cannot use NotifyChange function and other CTelephony function in same Active objects because one active object cannot serve two asynchronies function at the same time. We will discuss about this later. For the time being just understand the purpose of CTelephony class.
2. CMdaAudioPlayerUtility
---->This class is used for playing MP3, WAV file. There are some tricks we need to use here for sending voice over UPLINK.
3. MMdaAudioPlayerCallback
---->This M class is used by CMdaAudioPlayerUtility for call back. What is call back here? CMdaAudioPlayerUtility::Play() this function is used for playing a sounds. Once this function completes playing, it will call MapcPlayComplete function present in MMdaAudioPlayerCallback.
CallHandling.h
#ifndef __CALLHANDLING_H__
#define __CALLHANDLING_H__
#include "e32base.h"
#include "Etel3rdParty.h"
#include "w32std.h"
#include "mdaAudiosampleplayer.h"
class CTelCallHandling;
class CCallListener: public CActive
{
public:
CCallListener();
static CCallListener* NewL();
static CCallListener* NewLC();
~CCallListener();
void StartListening();
private:
void ConstructL();
void RunL();
TInt RunError(TInt anError);
void DoCancel();
private:
CTelephony* iTelephony;
RWsSession wsSession;
CTelephony::TCallStatusV1 iCallStatus;
CTelephony::TCallStatusV1Pckg iCallStatusPkg;
CTelephony::TCallId icallId;
CTelCallHandling* iCallHandlingObj;
};
class CTelCallHandling : public CActive, public MMdaAudioPlayerCallback
{
public:
CTelCallHandling();
static CTelCallHandling* NewL();
static CTelCallHandling* NewLC();
~CTelCallHandling();
void StartListening();
void CallHandling(TInt aCallStatus);
enum TAudioPlayerState
{
EPlayerNotReady=0,
EPlayerReadyToPlay,
EPlayerPlaying
};
CMdaAudioPlayerUtility * iMdaAudioPlayerUtility;
private:
void ConstructL();
void RunL();
void DoCancel();
private:
TAudioPlayerState iPlayerState;
TInt iCallStatus;
CTelephony::TCallId icallId;
CTelephony* iTelephony;
void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration);
void MapcPlayComplete(TInt aError);
void PlayL();
};
#endif
CallHandling.cpp
#include "e32base.h"
#include "Etel3rdParty.h"
#include "e32debug.h"
#include "TerminateCall.h"
CCallListener::CCallListener() :CActive(EPriorityIdle),iCallStatusPkg(iCallStatus)
{
}
CCallListener* CCallListener::NewL()
{
CTelObserver* self = CTelObserver::NewLC();
CleanupStack::Pop(self);
return self;
}
CCallListener* CCallListener::NewLC()
{
CCallListener* self = new (ELeave) CCallListener();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CCallListener::ConstructL()
{
iTelephony = CTelephony::NewL();
TInt Err = wsSession.Connect();
if (Err != KErrNone)
RDebug::Printf("Window server session connect error\n");
iCallHandlingObj = CTelCallHandling::NewL();
CActiveScheduler::Add(this);
}
CCallListener::~CTelObserver()
{
RDebug::Printf("STA CTel Observer\n");
Cancel();
wsSession.Close();
if (iTelephony)
delete iTelephony;
}
void CCallListener::RunL()
{
CTelephony::TCallStatus status = iCallStatus.iStatus;
switch (status)
{
case CTelephony::EStatusRinging:
iCallHandlingObj->CallHandling(status);
StartListening();
break;
case CTelephony::EStatusAnswering:
iCallHandlingObj->CallHandling(status);
StartListening();
break;
case CTelephony::EStatusConnected:
iCallHandlingObj->CallHandling(status);
StartListening();
break;
case CTelephony::EStatusDisconnecting:
iCallHandlingObj->CallHandling(status);
StartListening();
break;
default:
StartListening();
break;
}
}
TInt CCallListener::RunError(TInt anError)
{
return anError;
}
void CCallListener::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
}
void CCallListener::StartListening()
{
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange, iCallStatusPkg);
SetActive();
}
CallHandling.cpp
//call handling class
CTelCallHandling::CTelCallHandling():CActive(EPriorityIdle)
{
}
CTelCallHandling* CTelCallHandling::NewL()
{
CTelCallHandling* self = CTelCallHandling::NewLC();
CleanupStack::Pop(self);
return self;
}
CTelCallHandling* CTelCallHandling::NewLC()
{
CTelCallHandling* self = new (ELeave) CTelCallHandling();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CTelCallHandling::ConstructL()
{
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);
}
void CTelCallHandling::CallHandling(TInt aCallStatus)
{
iCallStatus = aCallStatus;
switch(aCallStatus)
{
case CTelephony::EStatusRinging:
RDebug::Printf("CTelCallHandling::CallHandling --- EStatusRinging\n");
iTelephony->AnswerIncomingCall(iStatus, icallId);
SetActive();
break;
case CTelephony::EStatusAnswering:
User::After(5000000);
_LIT(KSong, "z:\\Data\\Sounds\\Tones\\tune.mp3");
TBufC<128> buffer(KSong);
iMdaAudioPlayerUtility=CMdaAudioPlayerUtility::NewFilePlayerL(buffer, *this);
if (iMdaAudioPlayerUtility->SetPriority(80,(TMdaPriorityPreference)0x00060001) == KErrNone)
{
RDebug::Printf("STA SetPriority Success-------------...!!!!!!\n");
}
else
RDebug::Printf("STA setpriority failure.....!!!!!!\n");
break;
case CTelephony::EStatusConnected:
RunL();
break;
case CTelephony::EStatusDisconnecting:
RunL();
break;
}
}
void CTelCallHandling::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
{
RDebug::Printf("CTelCallHandling::MapcInitComplete Error code %d = \n", aError);
iPlayerState = aError ? EPlayerNotReady : EPlayerReadyToPlay;
if (aError==KErrNone)
{
RDebug::Printf("PlayL()\n");
PlayL();
}
else
RDebug::Printf("Error playing music\n");
}
void CTelCallHandling::MapcPlayComplete(TInt aError)
{
iPlayerState = aError ? EPlayerNotReady : EPlayerReadyToPlay;
User::After(6000000);
iTelephony->Hangup(iStatus, icallId);
SetActive();
}
void CTelCallHandling::PlayL()
{
if (iPlayerState==EPlayerReadyToPlay)
{
RDebug::Printf("STA playing....\n");
iMdaAudioPlayerUtility ->Play();
iPlayerState=EPlayerPlaying;
}
}
void CTelCallHandling::RunL()
{
switch(iCallStatus)
{
case CTelephony::EStatusRinging:
RDebug::Printf("Call handling RunL()-- EStatusRinging-- %d\n",CTelephony::EStatusRinging);
break;
case CTelephony::EStatusConnected:
RDebug::Printf("Call handling RunL()-- EStatusConnected--%d\n",CTelephony::EStatusConnected);
break;
case CTelephony::EStatusAnswering:
RDebug::Printf("Call handling RunL()-- EStatusAnswering-- %d\n",CTelephony::EStatusAnswering);
break;
case CTelephony::EStatusConnecting:
RDebug::Printf("Call handling RunL()-- EStatusConnecting-- %d\n", CTelephony::EStatusConnecting);
break;
case CTelephony::EStatusDisconnecting:
RDebug::Printf("Call handling RunL()-- EStatusDisconnecting-- %d\n",CTelephony::EStatusDisconnecting);
break;
default:
RDebug::Printf("Call Handling RunL default\n");
break;
}
}
void CTelCallHandling::DoCancel()
{
}
CTelCallHandling::~CTelCallHandling()
{
Cancel();
}
Thursday, September 4, 2008
Sending S60 Application to Background & bringing back to Foreground
Key Events
When ever user presses a key, Key down and Key event will be generated by system and when releasing the key, key up event will be generated by system. This is not only in Symbian but all Operating system is designed like this.
How to capture these three key events in S60?
1. RWindowGroup:: CaptureKeyUpAndDowns()
2. RWindowGroup:: CaptureKey()
These two functions are used to capture three event for a single key press and release events. (i.e) EEventKey, EEventKeyUp, EEventKeyDown.
---->Capturing keys are like redirecting the normal behavior of system. Once we done with the work for a particular key, we need to pass the key to window server so that normal behavior will not get spoiled. Most of the example will not send the captured key (if they are not capturing the key then they will send the key to WS) to window server so, you cannot expect correct behavior.
---->This below code is for sending a application to background and bringing back to foreground. When this application is in foreground press END key to send it to background and if you press HASH (#) the same application will come to foreground.
MMPFile
CAPABILITY SwEvent
Header file
#include "w32std.h"
#include "e32keys.h"
#include "apgtask.h"
Add these in AppUi header file
TInt iEndKeyUpDown , iEndKeyEvent, iHashKeyUpDown, iHashKeyEvent;
Add these lines in
RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
iEndKeyUpDown = groupWin.CaptureKeyUpAndDowns( EStdKeyNo, 0, 0 );
iEndKeyEvent = groupWin.CaptureKey( EStdKeyNo, 0, 0 );
iHashKeyUpDown = groupWin.CaptureKeyUpAndDowns ( ‘#’, 0, 0 );
iHashKeyEvent = groupWin.CaptureKey(‘#’, 0 , 0);
Override function in AppUi
void HandleWsEventL (const TWsEvent &aEvent, CCoeControl *aDestination);
{
TApaTaskList taskList2(iEikonEnv->WsSession());
TApaTask task2 = taskList2.FindApp(TUid::Uid(0xE9F96B59));
TInt key = aEvent.Key()->iScanCode;
if (EStdKeyHash == key && aEvent.Type() == EEventKey)
task2.BringToForeground();
if(EStdKeyNo == key && aEvent.Type() == EEventKey)
task2.SendToBackground();
fSession.Close();
CAknAppUi::HandleWsEventL(aEvent,aDestination);
}
Add in Destructor of
RWindowGroup& groupWin = CEikonEnv::Static()->RootWin();
groupWin.CancelCaptureKeyUpAndDowns(iEndKeyUpDown );
groupWin.CancelCaptureKey( iEndKeyEvent );
groupWin.CancelCaptureKeyUpAndDowns( iHashKeyUpDown);
groupWin.CancelCaptureKey( iHashKeyEvent );
RWindowGroup
Every application has its own Window group object, this is used to register an application behavior into window server, like when ever window server receives a key event where should it pass.
TApaTaskList : This class is used to get the list of running tasks. This will ask window server to get list of task for that TApaTaskList class need a window server session, so we are giving our application’s window server session which is maintained by framework.
TApaTask: This class is for holding information about a particular task so we can bring the application to foreground or background or kill etc….
:-).....
Tuesday, August 5, 2008
S60 Programming
How to access the HAL (Hardware Abstraction Layer) for getting system information? Here we are going to explore this. First we need to understand what is HAL and how kernel uses this layer and what is the necessity of HAL layer?
1. What is HAL layer?
Layer means some set of code will be used as an interface between two objects. Here HAL layer is used between user/kernel and HW.
2. What is the necessity of this layer?
For each device there should be an instance to communicate. HAL is the place to store those instances so that kernel can use those instances to communicate. We are registering device driver instance that is very close to HW so they named it as HAL (Hardware Abstraction Layer).
Header File: hal.h
Library: hal.lib
Class Names HAL & HALData
Function static IMPORT_C TInt Get(TAttribute aAttribute, TInt &aValue);
The above function is used to get information about the system like RAM , LCD, ect…
1. For getting Free RAM information
TInt aFreeRamSize;
HAL::Get(HALData::EMemoryRAMFree, aFreeRamSize);
This will return in bytes we need to convert into KB or MB or anything.
2. Example code
void FreeRamInfo()
{
TBuf<50> str;
TBuf<10> freeram;
char text[10];
TInt aFreeRamSize;
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
_ LIT(aFreeRamSizeFMT, "%S %d Bytes");
freeram.Copy(_L(“Free RAM”
HAL::Get(HALData::EMemoryRAMFree, aFreeRamSize);
str.Format(aFreeRamSizeFMT, &freeram, aFreeRamSize);
informationNote->ExecuteLD( *str );
}
We can get below information using HAL class.
EAccessoryPower, EBacklight, EBacklightState, ECPU, ECPUABI, ECPUABI_ARM4, ECPUABI_ARM5T, ECPUABI_ARMI, ECPUABI_MCORE, ECPUABI_MSVC, ECPUABI_THUMB, ECPUABI_X86, ECPUArch, ECPUSpeed, ECPU_ARM, ECPU_MCORE, ECPU_X86, ECaseState, ECaseSwitch, ECaseSwitchDisplayOff, ECaseSwitchDisplayOn, EClipboardDrive, ECustomRestart, ECustomRestartReason, EDebugPort, EDeviceFamily, EDeviceFamilyRev, EDeviceFamily_Crystal, EDeviceFamily_Pearl, EDeviceFamily_Quartz, EDisplayBitsPerPixel, EDisplayBrightness, EDisplayBrightnessMax, EDisplayColors, EDisplayContrast, EDisplayContrastMax, EDisplayIsMono, EDisplayIsPalettized, EDisplayIsPixelOrderLandscape, EDisplayIsPixelOrderRGB, EDisplayMemoryAddress, EDisplayMode, EDisplayNumModes, EDisplayNumberOfScreens, EDisplayOffsetBetweenLines, EDisplayOffsetToFirstPixel, EDisplayPaletteEntry, EDisplayState, EDisplayXPixels, EDisplayXTwips, EDisplayYPixels, EDisplayYTwips, EFastCounterCountsUp, EFastCounterFrequency, EHardwareFloatingPoint, EIntegratedPhone, EKeyboard, EKeyboardAppKeys, EKeyboardBacklightState, EKeyboardClick, EKeyboardClickState, EKeyboardClickVolume, EKeyboardClickVolumeMax, EKeyboardDeviceKeys, EKeyboardIndex, EKeyboardState, EKeyboard_Full, EKeyboard_Keypad, ELEDmask, ELEDs, ELanguageIndex, ELocaleLoaded, EMachineUid, EMachineUid_Assabet, EMachineUid_Brutus, EMachineUid_CL7211_Eval, EMachineUid_Cogent, EMachineUid_Helen, EMachineUid_IQ80310, EMachineUid_Integrator, EMachineUid_LinkUp, EMachineUid_Lubbock, EMachineUid_OmapH2, EMachineUid_OmapH4, EMachineUid_Series5mx, EMachineUid_Win32Emulator, EMachineUid_WinC, EMachineUid_X86PC, EMachineUid_Zylonite, EManufacturer, EManufacturerHardwareRev, EManufacturerSoftwareBuild, EManufacturerSoftwareRev, EManufacturer_Cirrus, EManufacturer_Cogent, EManufacturer_Ericsson, EManufacturer_Intel, EManufacturer_Linkup, EManufacturer_Motorola, EManufacturer_Nokia, EManufacturer_Panasonic, EManufacturer_Psion, EManufacturer_TexasInstruments, EMaxRAMDriveSize, EMemoryPageSize, EMemoryRAM, EMemoryRAMFree, EMemoryROM, EModel, EMouse, EMouseAcceleration, EMouseButtonState, EMouseButtons, EMouseSpeed, EMouseState, EMouseState_Invisible, EMouseState_Visible, EMouseX, EMouseY, ENanoTickPeriod, ENumHalAttributes, EPen, EPenClick, EPenClickState, EPenClickVolume, EPenClickVolumeMax, EPenDisplayOn, EPenState, EPenX, EPenY, EPointer3D, EPointer3DPhiSupported, EPointer3DPressureSupported, EPointer3DRotationSupported, EPointer3DThetaSupported, EPointer3DZ, EPowerBackup, EPowerBackupStatus, EPowerBackupStatus_Good, EPowerBackupStatus_Low, EPowerBackupStatus_Replace, EPowerBackupStatus_Zero, EPowerBatteryStatus, EPowerBatteryStatus_Good, EPowerBatteryStatus_Low, EPowerBatteryStatus_Replace, EPowerBatteryStatus_Zero, EPowerExternal, EPowerGood, ESettable, ESwitches, ESystemDrive, ESystemException, ESystemStartupReason, ESystemStartupReason_Cold, ESystemStartupReason_Fault, ESystemStartupReason_Warm, ESystemTickPeriod, EValid, TAttribute, TAttributeProperty, TCPU, TCPUABI, TDeviceFamily, TKeyboard, TMachineUid, TManufacturer, TMouseState, TPowerBackupStatus, TPowerBatteryStatus, TSystemStartupReason