Add PowerSave state publisher 00/141900/5
authorSomin Kim <somin926.kim@samsung.com>
Wed, 2 Aug 2017 03:06:16 +0000 (12:06 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 3 Aug 2017 02:05:14 +0000 (02:05 +0000)
Change-Id: Iabbde1586659f653a7bc53db15a768ae03f00c6d
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
include/job_scheduler_types_internal.h
src/server/publisher/PowerSaveState.cpp [new file with mode: 0644]

index f5edee33ec6d6fe55c7a66478bf16a1f8bff0328..fee01ab3dbd4d0a46e86dd56f1e4b2ae14908b1b 100644 (file)
 #define CTX_SCHED_ATTR_NAME_ACCURACY           "Accuracy"
 #define CTX_SCHED_ATTR_NAME_IS_CONNECTED       "IsConnected"
 #define CTX_SCHED_ATTR_NAME_IS_CHARGING                "IsCharging"
+#define CTX_SCHED_ATTR_NAME_IS_ENABLED         "IsEnabled"
 #define CTX_SCHED_ATTR_NAME_BSSID                      "BSSID"
 #define CTX_SCHED_ATTR_NAME_DAY_OF_MONTH       "DayOfMonth"
 #define CTX_SCHED_ATTR_NAME_DAY_OF_WEEK                "DayOfWeek"
diff --git a/src/server/publisher/PowerSaveState.cpp b/src/server/publisher/PowerSaveState.cpp
new file mode 100644 (file)
index 0000000..e0c11fa
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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();
+}