2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Shi Hezhang (hezhang.shi@samsung.com)
24 #include <dpl/scoped_ptr.h>
25 #include <dpl/log/log.h>
26 #include <Commons/Exception.h>
27 #include <Commons/ThreadPool.h>
28 #include "Backlight.h"
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::Commons;
33 namespace WrtDeviceApis {
36 Backlight::Backlight() :
37 EventLightOffTimerReqReceiver(ThreadEnum::POWER_THREAD),
38 EventLightReqReceiver(ThreadEnum::POWER_THREAD)
43 Backlight::~Backlight()
48 int Backlight::changeState(Power::Api::BacklightStatus state,
54 LogDebug("state: " << state << ", timeout: " << timeout);
55 result = pm_change_state(toLCDState(state));
56 if (state == Power::Api::BACKLIGHT_NORMAL) {
57 EventLightOffTimerPtr lightOffTimerEvent =
58 EventLightOffTimerPtr(
59 new EventLightOffTimer());
60 lightOffTimerEvent->setForAsynchronousCall(NULL);
61 EventLightOffTimerReqReceiver::PostRequest(
67 LogDebug("[ERROR] return value result =" << result);
69 LogDebug("[SUCCESS]return value result =" << result);
75 void Backlight::changeState(const Power::Api::EventLightPtr& event)
77 EventLightReqReceiver::PostRequest(event);
80 int Backlight::toLCDState(Power::Api::BacklightStatus state) const
84 case Power::Api::BACKLIGHT_DIM:
87 case Power::Api::BACKLIGHT_NORMAL:
90 case Power::Api::BACKLIGHT_OFF:
94 LogDebug("error status");
101 void Backlight::OnRequestReceived(const EventLightOffTimerPtr& /*event*/)
103 LogInfo("LightOffTimer event is received!!");
104 pm_change_state(LCD_DIM);
107 void Backlight::OnRequestReceived(const Power::Api::EventLightPtr& event)
109 LogInfo("Backlight event is received!!");
113 LogError("event is NULL!");
114 ThrowMsg(Commons::PlatformException, "Event is NULL!!");
117 "Status: " << event->getStatus() << ", Duratin: " <<
118 event->getDuration());
119 if (changeState(event->getStatus(), event->getDuration()) < 0) {
120 LogError("changeState returned error!!");
121 ThrowMsg(Commons::PlatformException, "Play Beep is Failed!");
124 catch (Commons::PlatformException) {
125 LogError("platform exception");
126 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);