systemswstubs/ssyreference/src/ssyreferencecmdhandler.cpp
changeset 52 3248d079cead
parent 1 ffb8e2ddd8dc
equal deleted inserted replaced
47:fb031b08c285 52:3248d079cead
    20 #include "ssyreferencecmdhandler.h"
    20 #include "ssyreferencecmdhandler.h"
    21 #include "ssyreferencecontrol.h"
    21 #include "ssyreferencecontrol.h"
    22 #include "ssyreferencechannel.h"
    22 #include "ssyreferencechannel.h"
    23 #include "ssyreferencetrace.h"
    23 #include "ssyreferencetrace.h"
    24 
    24 
       
    25 #ifdef	DSG
       
    26 #include <u32exec.h>
       
    27 #include <e32uid.h>
       
    28 #define	SystemCategory	KUidSystemCategory
       
    29 #define	EmulatorOrientationKey	KSystemEmulatorOrientationKey
       
    30 #endif	// DSG
       
    31 
    25 // ======== CONSTANTS ========
    32 // ======== CONSTANTS ========
    26 const TInt KSsyRefShortDelay = 100; 
    33 const TInt KSsyRefShortDelay = 100; 
    27 
    34 
    28 // ======== MEMBER FUNCTIONS ========
    35 // ======== MEMBER FUNCTIONS ========
    29 
    36 
    82         iSsyChannel.ProcessResponse( iMessage );
    89         iSsyChannel.ProcessResponse( iMessage );
    83         delete iMessage;
    90         delete iMessage;
    84         iMessage = NULL;
    91         iMessage = NULL;
    85         }
    92         }
    86 
    93 
       
    94 #ifdef	DSG
       
    95     if ( iPsListener )
       
    96         {
       
    97         iPsListener->Cancel();
       
    98         delete iPsListener;
       
    99         iPsListener = NULL;
       
   100         }
       
   101 #endif	// DSG
       
   102 
    87     if ( iTimer )
   103     if ( iTimer )
    88         {
   104         {
    89         iTimer->Cancel();
   105         iTimer->Cancel();
    90         delete iTimer;
   106         delete iTimer;
    91         }
   107         }
   110             {
   126             {
   111             iTimer->Cancel();
   127             iTimer->Cancel();
   112             delete iTimer;
   128             delete iTimer;
   113             iTimer = NULL;
   129             iTimer = NULL;
   114             }
   130             }
   115         
   131 
       
   132 #ifdef	DSG
       
   133 		if ( iPsListener )
       
   134 			{
       
   135 			iPsListener->Cancel();
       
   136 			delete iPsListener;
       
   137 			iPsListener = NULL;
       
   138 			}
       
   139 #endif	// DSG
       
   140 
   116         iDataItemArray.Reset();
   141         iDataItemArray.Reset();
   117         iDataItemPtr = 0;
   142         iDataItemPtr = 0;
   118         err = KErrNone;
   143         err = KErrNone;
   119         // No need to send ProcessResponse either
   144         // No need to send ProcessResponse either
   120         delete iMessage;
   145         delete iMessage;
   238                         }
   263                         }
   239 
   264 
   240                     // Reset pointer
   265                     // Reset pointer
   241                     iDataItemPtr = 0;
   266                     iDataItemPtr = 0;
   242 
   267 
       
   268 
   243                     // Start timer and continue processing in callback function
   269                     // Start timer and continue processing in callback function
   244                     iTimer = CPeriodic::NewL( EPriorityNormal );
   270                     iTimer = CPeriodic::NewL( EPriorityNormal );
       
   271 #ifndef	DSG
   245                     iTimer->Start( startInterval * 1000, 0, TCallBack( DataItemCallback, this ) );
   272                     iTimer->Start( startInterval * 1000, 0, TCallBack( DataItemCallback, this ) );
       
   273 #else
       
   274 					User::JustInTime();
       
   275                     if (startInterval > 0)
       
   276                     	{
       
   277 						iTimer->Start(startInterval * 1000, 0, TCallBack(DataItemCallback, this));
       
   278 						}
       
   279 					else
       
   280 						{
       
   281 						// Register to receive property updates ...
       
   282 						if (!iPsListener)
       
   283 							iPsListener = CSsyPsListener::NewL(*this, SystemCategory, EmulatorOrientationKey);
       
   284 						if (iPsListener)
       
   285 							{
       
   286 							// Respond to the inital value of the property, if it exists
       
   287 							static TInt initialValue;
       
   288 							if (RProperty::Get(SystemCategory, EmulatorOrientationKey, initialValue) == KErrNone)
       
   289 								PsValueSet(SystemCategory, EmulatorOrientationKey, initialValue);
       
   290 							}
       
   291 						}
       
   292 #endif	// DSG
   246                     }
   293                     }
   247                 break;
   294                 break;
   248                 }
   295                 }
   249             case ESsyReferenceOpenChannel:
   296             case ESsyReferenceOpenChannel:
   250                 {
   297                 {
   357 
   404 
   358     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelDataItem() - return" ) ) );
   405     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelDataItem() - return" ) ) );
   359     return KErrNone;
   406     return KErrNone;
   360     }
   407     }
   361 
   408 
       
   409 #ifdef	DSG
       
   410 
       
   411 void CSsyReferenceCmdHandler::SendData()
       
   412 	{
       
   413 	if (iMessage)
       
   414 		{
       
   415 		TSsyRefChannelDataBase dataItem = iDataItemArray[iDataItemPtr];
       
   416 
       
   417 		// Set timestamp to data item
       
   418 		TTime time;
       
   419 		time.HomeTime();
       
   420 		dataItem.SetTimestamp(time);
       
   421 
       
   422 		// Add data item to message
       
   423 		iMessage->SetDataItem(&dataItem);
       
   424 
       
   425 		// Send response
       
   426 		iMessage->SetFunction(ESsyReferenceDataItemReceived);
       
   427 		iSsyChannel.ProcessResponse(iMessage);
       
   428 		}
       
   429 	}
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // CSsyReferenceCmdHandler::GenerateChannelStateItem
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 TInt CSsyReferenceCmdHandler::GenerateChannelStateItem()
       
   436     {
       
   437     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelStateItem()" ) ) );
       
   438 
       
   439 	SendData();
       
   440 
       
   441 	// If we wrap around, or the 'Interval' (i.e. state number) of the next entry
       
   442 	// differs from that of the current one, we've finished this sequence of callbacks
       
   443 	TInt newIndex = iDataItemPtr+1;
       
   444     if (newIndex >= iDataItemArray.Count())
       
   445 		newIndex = 0;
       
   446 	TInt oldState = iDataItemArray[iDataItemPtr].Interval();
       
   447 	TInt newState = iDataItemArray[newIndex].Interval();
       
   448 	if (newState == oldState && newIndex != 0)
       
   449 	    {
       
   450         iDataItemPtr = newIndex;
       
   451 	    }
       
   452 	else
       
   453 	    {
       
   454         iTimer->Cancel();
       
   455         
       
   456   	    }
       
   457 	
       
   458     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::GenerateChannelStateItem() - return" ) ) );
       
   459     return KErrNone;
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // CSsyReferenceCmdHandler::StateItemCallback
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 TInt CSsyReferenceCmdHandler::StateItemCallback( TAny* aThis )
       
   467     {
       
   468     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::StateItemCallback()" ) ) );
       
   469     return static_cast<CSsyReferenceCmdHandler*>( aThis )->GenerateChannelStateItem();
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // CSsyReferenceCmdHandler::PsValueSet
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 void CSsyReferenceCmdHandler::PsValueSet(TUid aCategory, TUint aKey, TInt aValue)
       
   477     {
       
   478 	TUid c = aCategory;
       
   479 	TInt k = aKey;
       
   480     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::PsValueSet(%x, %x, %d)" ), aCategory, aKey, aValue ) );
       
   481 
       
   482 	// Find where to start ...
       
   483 	for (TInt index = 0; index < iDataItemArray.Count(); ++index)
       
   484 		{
       
   485 		TSsyRefChannelDataBase& dataItem = iDataItemArray[index];
       
   486 		if (dataItem.Interval() == aValue)
       
   487 			{
       
   488 			// The 'Interval' (i.e. state number) matches the property value.
       
   489 			// Set the start index and start the timer callback running
       
   490 			iDataItemPtr = index;
       
   491 			iTimer->Cancel();
       
   492 			iTimer->Start(10, 10000, TCallBack(StateItemCallback, this));
       
   493 			break;
       
   494 			}
       
   495 		}
       
   496 
       
   497     COMPONENT_TRACE( ( _L( "SSY Reference Plugin - CSsyReferenceCmdHandler::PsValueSet() - return" ) ) );
       
   498     }
       
   499 
       
   500 #include "ssypslistener.cpp"
       
   501 
       
   502 #endif	// DSG
       
   503 
   362 // End of file
   504 // End of file