Add the GpsState context publisher 95/140195/3
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 24 Jul 2017 06:41:46 +0000 (15:41 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 24 Jul 2017 06:50:03 +0000 (15:50 +0900)
Change-Id: Ib3f066bb496b07be13f0c342f463d45e06660d7e
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/job_scheduler_types_internal.h
packaging/context-job-scheduler.spec
src/server/CMakeLists.txt
src/server/publisher/GpsState.cpp [new file with mode: 0644]

index c7cce3f0b65c183b2e9a81e071913bcef27d74ad..48ab846b2774f75e4c1ce410a61f6229f7f8817e 100644 (file)
 #ifndef __CAPI_CONTEXT_JOB_SCHEDULER_TYPES_INTERNAL_H__
 #define __CAPI_CONTEXT_JOB_SCHEDULER_TYPES_INTERNAL_H__
 
-
+/* URIs */
 #define CTX_SCHED_URI_PREFIX           "http://tizen.org/context/"
 
 #define CTX_SCHED_URI_BATTERY          CTX_SCHED_URI_PREFIX "state/battery"
 #define CTX_SCHED_URI_CHARGER          CTX_SCHED_URI_PREFIX "state/charger"
 #define CTX_SCHED_URI_GPS                      CTX_SCHED_URI_PREFIX "state/gps"
-#define CTX_SCHED_URI_NPS                      CTX_SCHED_URI_PREFIX "state/nps"
 #define CTX_SCHED_URI_EARJACK          CTX_SCHED_URI_PREFIX "state/earjack"
 #define CTX_SCHED_URI_USB                      CTX_SCHED_URI_PREFIX "state/usb"
 #define CTX_SCHED_URI_WIFI                     CTX_SCHED_URI_PREFIX "state/wifi"
 #define CTX_SCHED_URI_CALENDAR_DB      CTX_SCHED_URI_PREFIX "event/calendar_db"
 #define CTX_SCHED_URI_PLACE_DB         CTX_SCHED_URI_PREFIX "event/place_db"
 
+/* Attribute names */
+#define CTX_SCHED_ATTR_NAME_STATE              "state"
+
+/* Attribute values */
+#define CTX_SCHED_ATTR_VALUE_UNDEFINED "undefined"
+#define CTX_SCHED_ATTR_VALUE_DISABLED  "disabled"
+#define CTX_SCHED_ATTR_VALUE_SEARCHING "searching"
+#define CTX_SCHED_ATTR_VALUE_CONNECTED "connected"
 
 #endif
index 4a5350fa57741fcecfedc186b2faec564b80102a..a59f94a0a6d8fb9139761039d23d9d31bdf3113e 100644 (file)
@@ -15,6 +15,9 @@ BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-system-device)
+BuildRequires: pkgconfig(capi-system-runtime-info)
 
 BuildRequires: pkgconfig(context-common-server)
 BuildRequires: pkgconfig(context-common-client)
index 21573b2b23bcb07746d83fd89e148a7f4d5a2bd7..3fd32d222c9072b2f975c0c9d84969e3ecb361e8 100644 (file)
@@ -1,6 +1,7 @@
 SET(target "${PROJECT_NAME}-server-genuine")
 
 SET(DEPS "${DEPS} jsoncpp sqlite3 vconf context-common-server")
+SET(DEPS "${DEPS} capi-system-info capi-system-device capi-system-runtime-info")
 
 FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
 MESSAGE("Sources: ${SRCS}")
diff --git a/src/server/publisher/GpsState.cpp b/src/server/publisher/GpsState.cpp
new file mode 100644 (file)
index 0000000..cf7370e
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * 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 <system_info.h>
+#include <runtime_info.h>
+
+#include <ContextTypes.h>
+#include <job_scheduler_types_internal.h>
+#include "../ContextPublisher.h"
+#include "../IContextObserver.h"
+
+using namespace ctx;
+
+namespace {
+       class GpsState : public ContextPublisher {
+       public:
+               GpsState(uid_t uid);
+               ~GpsState();
+
+               const char* getUri() const;
+
+       protected:
+               void read();
+               void subscribe();
+               void unsubscribe();
+
+       private:
+               void __update(int state);
+
+               static void __changedCb(runtime_info_key_e infoKey, void* userData);
+       };
+}
+
+REGISTER_PUBLISHER(CTX_SCHED_URI_GPS, GpsState)
+
+static const char* __state_to_string(int state)
+{
+       if (state == RUNTIME_INFO_GPS_STATUS_DISABLED)
+               return CTX_SCHED_ATTR_VALUE_DISABLED;
+
+       if (state == RUNTIME_INFO_GPS_STATUS_SEARCHING)
+               return CTX_SCHED_ATTR_VALUE_SEARCHING;
+
+       if (state == RUNTIME_INFO_GPS_STATUS_CONNECTED)
+               return CTX_SCHED_ATTR_VALUE_CONNECTED;
+
+       return CTX_SCHED_ATTR_VALUE_UNDEFINED;
+}
+
+GpsState::GpsState(uid_t uid)
+{
+       bool supported = false;
+       system_info_get_platform_bool("tizen.org/feature/location.gps", &supported);
+       IF_FAIL_THROW(supported, E_SUPPORT);
+}
+
+GpsState::~GpsState()
+{
+       unsubscribe();
+}
+
+const char* GpsState::getUri() const
+{
+       return CTX_SCHED_URI_GPS;
+}
+
+void GpsState::read()
+{
+       int state = RUNTIME_INFO_GPS_STATUS_DISABLED;
+       int err = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &state);
+
+       if (IS_FAILED(err))
+               _E("Getting runtime information failed (%d)", err);
+
+       __data[CTX_SCHED_ATTR_NAME_STATE] = __state_to_string(state);
+}
+
+void GpsState::subscribe()
+{
+       int err = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_GPS_STATUS, __changedCb, this);
+
+       if (IS_FAILED(err))
+               _E("Setting changed callback failed (%d)", err);
+}
+
+void GpsState::unsubscribe()
+{
+       runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_GPS_STATUS);
+}
+
+void GpsState::__update(int state)
+{
+       __data[CTX_SCHED_ATTR_NAME_STATE] = __state_to_string(state);
+       notifyObservers();
+}
+
+void GpsState::__changedCb(runtime_info_key_e infoKey, void* userData)
+{
+       int state = RUNTIME_INFO_GPS_STATUS_DISABLED;
+       int err = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &state);
+
+       if (IS_FAILED(err))
+               _E("Getting runtime information failed (%d)", err);
+
+       static_cast<GpsState*>(userData)->__update(state);
+}