--- /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 <vconf.h>
+
+#include <ContextTypes.h>
+#include <JobSchedulerTypesPrivate.h>
+#include <job_scheduler_types_internal.h>
+#include "../ContextPublisher.h"
+#include "../IContextObserver.h"
+
+using namespace ctx;
+
+namespace {
+ class PowerSaveState : public ContextPublisher {
+ public:
+ PowerSaveState(uid_t uid);
+ ~PowerSaveState();
+
+ const char* getUri() const;
+
+ protected:
+ void read();
+ void subscribe();
+ void unsubscribe();
+
+ private:
+ static void __changedCb(keynode_t* node, void* userData);
+ };
+}
+
+REGISTER_PUBLISHER(URI(POWERSAVE), PowerSaveState)
+
+PowerSaveState::PowerSaveState(uid_t uid)
+{
+ _D("Created");
+}
+
+PowerSaveState::~PowerSaveState()
+{
+ unsubscribe();
+
+ _D("Destroyed");
+}
+
+const char* PowerSaveState::getUri() const
+{
+ return URI(POWERSAVE);
+}
+
+void PowerSaveState::read()
+{
+ int mode = 0;
+ int err = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode);
+
+ if (IS_FAILED(err))
+ _E("Getting vconf value failed (%d)", err);
+
+ __data[NAME(IS_ENABLED)] = (mode == 0 ? VALUE(FALSE) : VALUE(TRUE));
+}
+
+void PowerSaveState::subscribe()
+{
+ int err = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __changedCb, this);
+
+ if (IS_FAILED(err))
+ _E("Setting vconf key changed callback failed (%d)", err);
+}
+
+void PowerSaveState::unsubscribe()
+{
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __changedCb);
+}
+
+void PowerSaveState::__changedCb(keynode_t* node, void* userData)
+{
+ PowerSaveState* pubs = static_cast<PowerSaveState*>(userData);
+ pubs->read();
+ pubs->notifyObservers();
+}