diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/ssmanager_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/ssmanager_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,341 @@ + + + + +TB9.2 Example Applications: examples/AppFramework/ssmanager/src/ssmanager.cpp Source File + + + + + +

examples/AppFramework/ssmanager/src/ssmanager.cpp

00001 //
+00002 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+00003 // All rights reserved.
+00004 // This component and the accompanying materials are made available
+00005 // under the terms of "Eclipse Public License v1.0"
+00006 // which accompanies this distribution, and is available
+00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00008 //
+00009 // Initial Contributors:
+00010 // Nokia Corporation - initial contribution.
+00011 //
+00012 // Contributors:
+00013 //
+00014 // Description: This example is used to demonstrate the utilities of System state 
+00015 // Manager framework.
+00016 //      
+00017 
+00028 #include "ssmanager.h"
+00029 #include "dummy_diskstatus_swppolicy.hrh"
+00030 #include <ssm/ssmsubstates.hrh>
+00031 #include <ssm/ssmstate.h>
+00032 #include <ssm/ssmstateawaresession.h>
+00033 #include <ssm/ssmdomaindefs.h>
+00034 
+00035 _LIT(KTxtExampleCode,"System State Manager Example");
+00036 _LIT(KTxtError,"error is %d\n");
+00037 _LIT(KTxtFormat,"*****************************\n");
+00038 _LIT(KTxtFormat1,".............\n");
+00039 
+00040 _LIT(KTxtSwpInfo,"\nKey of the SwP is %d \n \nValue of the SwP is %d \n\n");
+00041 _LIT(KTxtSasResult,"\nState aware session connected with [%d]");
+00042 
+00043 _LIT(KTxtState,"\nValue of new state :");
+00044 _LIT(KTxtReqNotificationChgofState,"\nRequest Notification for any change of state\n");
+00045 _LIT(KTxtStateValues,"\n Main state: %04x \n SubState: %04x \n");
+00046 
+00047 _LIT(KTxtStateChangeResult,"\nState transition completed with : %d\n");
+00048 _LIT(KTxtSwpChangeResult,"\nSwP transition completed with : %d\n");
+00049 
+00050 const TUint KFiveSecDelay  = 500000;
+00051 
+00052 static TInt StopScheduler(TAny* /*aAny*/)
+00053         {
+00054         CActiveScheduler::Stop();
+00055         return KErrNone;
+00056         }
+00057         
+00058 CSysStateManagerExample* CSysStateManagerExample::NewLC()
+00059         {
+00060         CSysStateManagerExample* self=new(ELeave)CSysStateManagerExample();
+00061         CleanupStack::PushL(self);
+00062         return self;
+00063         }
+00064 
+00065 CSysStateManagerExample::CSysStateManagerExample()
+00066         {
+00067         
+00068         }
+00069 
+00073 CSysStateManagerExample::~CSysStateManagerExample()
+00074         {
+00075         iSsmStateManager.Close();
+00076         delete iConsole; // delete iConsole.
+00077         }
+00078 
+00082 void CSysStateManagerExample::SwpChanged(TSsmSwp /*aSwp*/)
+00083         {
+00084         _LIT(KTxtUserNotifiedSwPChange,"Notification received of a change in the SwP value.\n");
+00085         iConsole->Printf(KTxtUserNotifiedSwPChange);
+00086         }
+00087 
+00091 void CSysStateManagerExample::RequestSwpChange()
+00092         {
+00097         TSsmSwp swp(EExampleSwPKey, ESwpValueJustPublishSwP); 
+00098         // Request a Swp change
+00099         TRequestStatus status;
+00100         iSsmStateManager.RequestSwpChange(swp, status);
+00101         User::WaitForRequest(status);
+00102         iConsole->Printf(KTxtSwpChangeResult,status.Int());
+00103         iConsole->Printf(KTxtSwpInfo,swp.Key(),swp.Value());
+00104         }
+00105         
+00109 void CSysStateManagerExample::RequestSsChange()
+00110         {
+00111         _LIT(KTxtNormalToRestore,"\nRequesting a System state change from Normal to Restore\n");
+00112         TInt reason =0; //Various reasons for state transition can be stated, the value is taken as '0'
+00113         TSsmStateTransition state(ESsmRestore, ESsmRestoreSubState, reason); 
+00114         iConsole->Printf(KTxtNormalToRestore);
+00115     TRequestStatus status;
+00116         iSsmStateManager.RequestStateTransition(state,status);
+00117         User::WaitForRequest(status);
+00118         User::After(KFiveSecDelay); //Wait for 0.5sec to allow transitions to fully complete
+00119         iConsole->Printf(KTxtStateChangeResult,status.Int());
+00120         //This session helps you to get the details of the current state of the device
+00121         RSsmStateAwareSession stateAwareSession;
+00122         /*
+00123         'KSM2UiServicesDomain3' is the domain id for the third domain in the UI 
+00124         Service level of the Startup Domain Hierarchy.
+00125         */
+00126         TInt ret = stateAwareSession.Connect(KSM2UiServicesDomain3);
+00127         if(ret!=KErrNone)
+00128                 {
+00129                 iConsole->Printf(KTxtSasResult,ret);
+00130                 }
+00131         else
+00132                 {
+00133                 TSsmState current = stateAwareSession.State(); 
+00134                 TSsmStateName name = current.Name();
+00135                 iConsole->Printf(KTxtState);
+00136                 iConsole->Printf(name);
+00137                 iConsole->Printf(KTxtStateValues,current.MainState(),current.SubState());
+00138                 stateAwareSession.Close();
+00139                 }
+00140         }
+00141 
+00146  void CSysStateManagerExample::RequestSwpChangeWithNotificationL()
+00147         {
+00148         CActiveScheduler* sched = new(ELeave) CActiveScheduler;
+00149         CleanupStack::PushL(sched);
+00150         CActiveScheduler::Install(sched);       
+00155         CSsmSystemWideProperty* cProp = CSsmSystemWideProperty::NewLC(EExampleSwPKey);
+00156         
+00157         // Subscribe to changes in dummy disk status Swp
+00158         cProp->AddSubscriberL(*this);
+00159         
+00160         // Request Swp changes
+00161         TSsmSwp swp(EExampleSwPKey,ESwpValueJustPublishSwP);
+00162         TRequestStatus status;
+00163         iSsmStateManager.RequestSwpChange(swp, status);
+00164         User::WaitForRequest(status);
+00165         iConsole->Printf(KTxtSwpChangeResult,status.Int());     
+00166         iConsole->Printf(KTxtSwpInfo,swp.Key(),swp.Value());
+00167         
+00168         // Request Swp changes
+00169         swp.Set(EExampleSwPKey,ESwpValueForBackup);
+00170         iSsmStateManager.RequestSwpChange(swp, status);
+00171         User::WaitForRequest(status);
+00172         iConsole->Printf(KTxtSwpChangeResult,status.Int());     
+00173         iConsole->Printf(KTxtSwpInfo,swp.Key(),swp.Value());
+00174         CAsyncCallBack* stopper = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
+00175         CleanupStack::PushL(stopper);
+00176         TCallBack stopSchedulerCallback(StopScheduler, this);
+00177         stopper->Set(stopSchedulerCallback);
+00178         
+00179         // This callback will not run until the Swp change is finished, because it has idle priority. 
+00180         stopper->CallBack();
+00181         // Causes CSsmSystemWideProperty::RunL to run, as cProp is subscribing on 'Dummy Disk Status' changes
+00182         sched->Start();
+00183         CleanupStack::PopAndDestroy(3, sched); // Pop and Destroy sched, cprop and stopper.
+00184         }
+00185 
+00190  void CSysStateManagerExample::RequestSsChangeWithNotification()
+00191         {
+00192         _LIT(KTxtStateChangeNotificationSuccess,"\nNotification of the state transition received\n");
+00193         _LIT(KTxtStateChangeNotificationFailure,"\nNotification of the state transition failed\n");
+00194         _LIT(KTxtNormalToBackup,"\nRequest a System State change from Normal to Back up\n");
+00195         _LIT(KTxtAlreadyInThisState,"\nSystem state is already in Backup\n");
+00196         
+00197         // This session helps you to get the details of the current state of the device
+00198         RSsmStateAwareSession stateAwareSession;
+00199         
+00200         /*
+00201         'KSM2UiServicesDomain3' is the domain id for the third domain in the UI 
+00202         Service level of the Startup Domain Hierarchy.
+00203         */
+00204         TInt err = stateAwareSession.Connect(KSM2UiServicesDomain3);
+00205         iConsole->Printf(KTxtSasResult,err);
+00206         TSsmState current = stateAwareSession.State();
+00207         TSsmStateName name = current.Name();
+00208         
+00209         if(current.MainState()!= ESsmBackup)
+00210                 {
+00211                 TSsmStateTransition state1(ESsmBackup,ESsmBackupSubState, 0);
+00212                 iConsole->Printf(KTxtNormalToBackup);
+00213                 TRequestStatus status1,status2;
+00214                 iConsole->Printf(KTxtReqNotificationChgofState);
+00215                 stateAwareSession.RequestStateNotification(status1);
+00216                 iSsmStateManager.RequestStateTransition(state1,status2);
+00217                 User::WaitForRequest(status2);
+00218                 User::After(KFiveSecDelay); // Wait for 0.5 sec to allow transitions to fully complete
+00219                 if(status2.Int() == KErrNone)
+00220                         {
+00221                         iConsole->Printf(KTxtStateChangeResult,status2.Int());
+00222                         current = stateAwareSession.State();
+00223                         name = current.Name();
+00224                         }
+00225                 else
+00226                         {
+00227                         iConsole->Printf(KTxtStateChangeResult,status2.Int());  
+00228                         }
+00229                 iConsole->Printf(KTxtState);
+00230                 iConsole->Printf(name);
+00231                 iConsole->Printf(KTxtStateValues,current.MainState(),current.SubState());
+00232                 User::WaitForRequest(status1); //status1 of the Notification request waits for status2 to complete
+00233                 if(status1.Int() == KErrNone)
+00234                         {
+00235                         iConsole->Printf(KTxtStateChangeNotificationSuccess);
+00236                         }
+00237                 else
+00238                         {
+00239                         iConsole->Printf(KTxtStateChangeNotificationFailure);   
+00240                         }
+00241                 }
+00242         else
+00243                 {
+00244                 iConsole->Printf(KTxtAlreadyInThisState);
+00245                 }
+00246         stateAwareSession.Close();
+00247         }   
+00248 
+00249  void CSysStateManagerExample::SSManagerL()
+00250         {
+00251         _LIT(KTextPressAnyKey," [press any key]");
+00252         _LIT(KTextPressAnyKeyToExit," [press any key to exit]");
+00253         
+00254         _LIT(KTxtSwp,"Swp means SystemWide Property.\nDisk status, Battery information are few examples of System wide properties.\n");
+00255         _LIT(KTxtSs,"\n SS means System State.\n Ex:Backup,Restore, Start-up, Shutdown are few examples of System states.\n");
+00256         _LIT(KTxtExampleDemo,"\n The example helps the user in understanding, how to define new System states and System wide properties.It also helps him in exercising the various features of SSM framework.\n");
+00257         _LIT(KTxtSSM, "Exercise the features of System State Manager\n");                       
+00258         _LIT(KTxtConnect,"Connecting to System State Manager.........\n");
+00259         _LIT(KTxtSuccess,"Connection is successful.........\n");
+00260                 
+00261         _LIT(KTxtReqChangeInSwp,"1)     request a change to a Swp, without notification\n");
+00262         _LIT(KTxtReqChangeInSs,"2) request a change to a system state, without notification\n");
+00263         _LIT(KTxtNotifyChangeInSwp,"3) request a change to a Swp, with notification\n");
+00264         _LIT(KTxtNotifyChangeInSs,"4) request a change to a system state, with notification\n");
+00265         _LIT(KTxtOptionNotSupported,"this option is not supported\n");
+00266                 
+00267         _LIT(KTxtPressESC,"Press ESC to stop using the System State Information utility\n");
+00268         _LIT(KTxtContinue,"Choose any option 1 - 4 to continue\n");     
+00269 
+00270         iConsole= Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
+00271         iConsole->Printf(KTxtFormat);
+00272         iConsole->Printf(KTxtSwp);
+00273         iConsole->Printf(KTxtSs);
+00274         iConsole->Printf(KTxtExampleDemo);
+00275         iConsole->Printf(KTxtFormat);
+00276         iConsole->Printf(KTxtSSM);                      
+00277         iConsole->Printf(KTxtConnect);
+00278         iConsole->Printf(KTxtFormat1);
+00279         TInt connect = iSsmStateManager.Connect();      
+00280         if(connect==KErrNone)
+00281                 {
+00282                 iConsole->Printf(KTxtSuccess);
+00283                 iConsole->Printf(KTxtFormat);
+00284                 iConsole->Printf(KTextPressAnyKey);
+00285                 iConsole->Getch(); // Get and ignore character.
+00286                 iConsole->ClearScreen();
+00287                 iConsole->Printf(KTxtReqChangeInSwp);
+00288                 iConsole->Printf(KTxtReqChangeInSs);
+00289                 iConsole->Printf(KTxtNotifyChangeInSwp);
+00290                 iConsole->Printf(KTxtNotifyChangeInSs);
+00291                 iConsole->Printf(KTxtContinue);
+00292                 TChar tchar = iConsole->Getch();
+00293                 //make a choice
+00294                 while (tchar != EKeyEscape)
+00295                         {
+00296                         switch(tchar)
+00297                                 {
+00298                                 case '1':
+00299                                         {
+00300                                         RequestSwpChange();
+00301                                         break;
+00302                                         }
+00303                                 case '2':
+00304                                         {
+00305                                         RequestSsChange();
+00306                                         break;
+00307                                         }
+00308                                 case '3':
+00309                                         {
+00310                                         RequestSwpChangeWithNotificationL();
+00311                                         break;
+00312                                         }
+00313                                 case '4':
+00314                                         {
+00315                                         RequestSsChangeWithNotification();
+00316                                         break;
+00317                                         }
+00318                                 default:
+00319                                         {
+00320                                         iConsole->Printf(KTxtOptionNotSupported);
+00321                                         break;
+00322                                         }
+00323                                 }
+00324                         iConsole->Printf(KTextPressAnyKey);
+00325                         iConsole->Getch(); // Get and ignore character.
+00326                         iConsole->ClearScreen();
+00327                         iConsole->Printf(KTxtPressESC);
+00328                         iConsole->Printf(KTxtContinue);
+00329                         iConsole->Printf(KTxtReqChangeInSwp);
+00330                         iConsole->Printf(KTxtReqChangeInSs);
+00331                         iConsole->Printf(KTxtNotifyChangeInSwp);
+00332                         iConsole->Printf(KTxtNotifyChangeInSs);
+00333                         tchar = iConsole->Getch(); 
+00334                         }
+00335                 }
+00336         else
+00337                 {
+00338                 iConsole->Printf(KTxtError,connect);    
+00339                 }
+00340         iConsole->Printf(KTextPressAnyKeyToExit);
+00341         iConsole->Getch(); // Get and ignore character.
+00342         }
+00343  
+00344 static void doExampleL()
+00345         {
+00346         CSysStateManagerExample* ssManager = CSysStateManagerExample::NewLC();
+00347         ssManager->SSManagerL();
+00348         CleanupStack::PopAndDestroy(ssManager);
+00349         }
+00350         
+00351 extern TInt E32Main()
+00352     {
+00353         __UHEAP_MARK;
+00354         CTrapCleanup* cleanup=CTrapCleanup::New(); // Get clean-up stack.
+00355         if(cleanup!=NULL)
+00356                 {
+00357                 TRAPD (error,doExampleL());
+00358                 __ASSERT_ALWAYS(!error,User::Panic(KTxtExampleCode,error));
+00359                 }
+00360         delete cleanup; // Delete clean-up stack.
+00361         __UHEAP_MARKEND;
+00362         return KErrNone; // And return.
+00363     }
+
+
Generated by  + +doxygen 1.6.2
+ +