--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <device/callback.h>
+#include <device/display.h>
+
+#include <ContextTypes.h>
+#include <JobSchedulerTypesPrivate.h>
+#include <job_scheduler_types_internal.h>
+#include "../ContextPublisher.h"
+#include "../IContextObserver.h"
+
+using namespace ctx;
+
+namespace {
+ class DisplayState : public ContextPublisher {
+ public:
+ DisplayState(uid_t uid);
+ ~DisplayState();
+
+ const char* getUri() const;
+
+ protected:
+ void read();
+ void subscribe();
+ void unsubscribe();
+
+ private:
+ static void __deviceCb(device_callback_e deviceType, void* value, void* userData);
+ };
+}
+
+REGISTER_PUBLISHER(URI(DISPLAY), DisplayState)
+
+DisplayState::DisplayState(uid_t uid)
+{
+ _D("Created");
+}
+
+DisplayState::~DisplayState()
+{
+ unsubscribe();
+
+ _D("Destroyed");
+}
+
+const char* DisplayState::getUri() const
+{
+ return URI(DISPLAY);
+}
+
+void DisplayState::read()
+{
+ display_state_e state;
+ int err = device_display_get_state(&state);
+
+ if (IS_FAILED(err))
+ _E("Getting display state failed (%d)", err);
+
+ __data[NAME(STATE)] = [&state]()->const char* {
+ if (state == DISPLAY_STATE_NORMAL)
+ return VALUE(ON);
+ if (state == DISPLAY_STATE_SCREEN_DIM)
+ return VALUE(DIM);
+ if (state == DISPLAY_STATE_SCREEN_OFF)
+ return VALUE(OFF);
+ return VALUE(UNDEFINED);
+ }();
+}
+
+void DisplayState::subscribe()
+{
+ int err = device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, __deviceCb, this);
+
+ if (IS_FAILED(err))
+ _E("Add device callback failed (%d)", err);
+}
+
+void DisplayState::unsubscribe()
+{
+ device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, __deviceCb);
+}
+
+void DisplayState::__deviceCb(device_callback_e deviceType, void* value, void* userData)
+{
+ DisplayState* pubs = static_cast<DisplayState*>(userData);
+ pubs->read();
+ pubs->notifyObservers();
+}