screensaver/snsrdisplaycontrol_s60/src/snsrdisplaycontrolsession.cpp
changeset 92 6727c5d0afc7
child 90 3ac3aaebaee5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/screensaver/snsrdisplaycontrol_s60/src/snsrdisplaycontrolsession.cpp	Fri Sep 17 08:27:54 2010 +0300
@@ -0,0 +1,129 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: Implementation for server side session object of
+*              Screensaver Display Control Server
+*
+*/
+
+#include <power_save_display_mode.h>
+#include <hal.h>
+
+#include "snsrdisplaycontrolsession.h"
+#include "snsrdisplaycontrolcommon.h"
+
+
+// ======== LOCAL FUNCTIONS ========
+
+
+// ======== MEMBER FUNCTIONS ========
+
+
+// ---------------------------------------------------------------------------
+// CSnsrDisplayControlSession
+// ---------------------------------------------------------------------------
+//
+CSnsrDisplayControlSession::CSnsrDisplayControlSession() : 
+    CSession2()
+    {
+    }
+
+
+// ---------------------------------------------------------------------------
+// ConstructL
+// ---------------------------------------------------------------------------
+//
+void CSnsrDisplayControlSession::ConstructL()
+    {
+    iPowerSave = CPowerSaveDisplayMode::NewL();
+    
+    // Create pixel buffer that can hold the full screen picture of our 
+    // display device.
+    TInt x = 0;
+    TInt y = 0;
+    HAL::Get(HALData::EDisplayXPixels, x);
+    HAL::Get(HALData::EDisplayYPixels, y);
+    iPowerSavePixelBuffer = HBufC::NewL(x*y);
+    iPowerSavePixelBuffer->Des().FillZ();
+    }
+
+
+// ---------------------------------------------------------------------------
+// NewL
+// ---------------------------------------------------------------------------
+//
+EXPORT_C CSnsrDisplayControlSession* CSnsrDisplayControlSession::NewL()
+    {
+    CSnsrDisplayControlSession* self = new (ELeave) CSnsrDisplayControlSession();
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+
+// ---------------------------------------------------------------------------
+// ~CSnsrDisplayControlSession
+// ---------------------------------------------------------------------------
+//
+CSnsrDisplayControlSession::~CSnsrDisplayControlSession()
+    {
+    delete iPowerSave;
+    delete iPowerSavePixelBuffer;
+    }
+
+// ---------------------------------------------------------------------------
+// ServiceL
+// ---------------------------------------------------------------------------
+//
+void CSnsrDisplayControlSession::ServiceL( const RMessage2& aMessage )
+    {
+    TInt func = aMessage.Function();
+    
+    TInt err( KErrNone );
+    
+    switch ( func )
+        {
+        case ESnsrDispCtrlSrvDisplayOff:
+            {
+            // off
+            // TODO
+            break;
+            }
+        case ESnsrDispCtrlSrvDisplayLowPower:
+            {
+            // low power
+            TInt startRow = aMessage.Int0();
+            TInt endRow = aMessage.Int1();
+            // TODO: for now, we pass a zero-filled pixel buffer to power save API.
+            // This works fine with our reference hardware but some types of displays
+            // might require passing the actual screen contents in this buffer.
+            TUint16* ptr = const_cast<TUint16*>( iPowerSavePixelBuffer->Ptr() );
+            err = iPowerSave->Set(startRow, endRow, ptr);
+            break;
+            }
+        case ESnsrDispCtrlSrvDisplayFullPower:
+            {
+            // full power
+            err = iPowerSave->Exit();
+            break;
+            }
+        default:
+            {
+            err = KErrNotSupported;
+            }
+        }
+    
+    aMessage.Complete(err);
+    }
+