Add TemporalState publisher (not observable) 92/141192/4
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 28 Jul 2017 11:47:52 +0000 (20:47 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 28 Jul 2017 13:53:25 +0000 (22:53 +0900)
Change-Id: Ib65124268bbab3f51aca021ba0b9c27e1bbce8eb
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/job_scheduler_types_internal.h
src/server/publisher/TemporalState.cpp [new file with mode: 0644]

index aacab31313466c89557b50504f8abfa17335676d..282d2742cf972ac4b2db7cdb5bed194af41d3323 100644 (file)
@@ -28,6 +28,7 @@
 #define CTX_SCHED_URI_POWERSAVE                CTX_SCHED_URI_PREFIX "state/powersave"
 #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_TIME                     CTX_SCHED_URI_PREFIX "state/time"
 
 #define CTX_SCHED_URI_STATIONARY       CTX_SCHED_URI_PREFIX "event/stationary"
 #define CTX_SCHED_URI_WALKING          CTX_SCHED_URI_PREFIX "event/walking"
@@ -46,6 +47,9 @@
 #define CTX_SCHED_ATTR_NAME_IS_CONNECTED       "IsConnected"
 #define CTX_SCHED_ATTR_NAME_IS_CHARGING                "IsCharging"
 #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"
+#define CTX_SCHED_ATTR_NAME_TIME_OF_DAY                "TimeOfDay"
 
 /* Attribute values */
 #define CTX_SCHED_ATTR_VALUE_TRUE                      1
 #define CTX_SCHED_ATTR_VALUE_OFF                       "Off"
 #define CTX_SCHED_ATTR_VALUE_DIM                       "Dim"
 
+#define CTX_SCHED_ATTR_VALUE_SUN                       "Sun"
+#define CTX_SCHED_ATTR_VALUE_MON                       "Mon"
+#define CTX_SCHED_ATTR_VALUE_TUE                       "Tue"
+#define CTX_SCHED_ATTR_VALUE_WED                       "Wed"
+#define CTX_SCHED_ATTR_VALUE_THU                       "Thu"
+#define CTX_SCHED_ATTR_VALUE_FRI                       "Fri"
+#define CTX_SCHED_ATTR_VALUE_SAT                       "Sat"
+
 #endif
diff --git a/src/server/publisher/TemporalState.cpp b/src/server/publisher/TemporalState.cpp
new file mode 100644 (file)
index 0000000..b368ca2
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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 <ContextTypes.h>
+#include <JobSchedulerTypesPrivate.h>
+#include <job_scheduler_types_internal.h>
+#include "../ContextPublisher.h"
+#include "../IContextObserver.h"
+
+using namespace ctx;
+
+namespace {
+       class TemporalState : public ContextPublisher {
+       public:
+               TemporalState(uid_t uid);
+               ~TemporalState();
+
+               const char* getUri() const;
+               const char* getPrivilege() const;
+
+               bool isObservable() const;
+
+               bool isReady();
+               const Json::Value& getData();
+
+       protected:
+               void read();
+               void subscribe();
+               void unsubscribe();
+       };
+}
+
+REGISTER_PUBLISHER(URI(TIME), TemporalState)
+
+TemporalState::TemporalState(uid_t uid)
+{
+       _D("Created");
+}
+
+TemporalState::~TemporalState()
+{
+       _D("Destroyed");
+}
+
+const char* TemporalState::getUri() const
+{
+       return URI(TIME);
+}
+
+const char* TemporalState::getPrivilege() const
+{
+       return "http://tizen.org/privilege/alarm.set";
+}
+
+bool TemporalState::isObservable() const
+{
+       return false;
+}
+
+bool TemporalState::isReady()
+{
+       return true;
+}
+
+const Json::Value& TemporalState::getData()
+{
+       static const char* weekDays[] = {
+               VALUE(SUN), VALUE(MON), VALUE(TUE), VALUE(WED), VALUE(THU), VALUE(FRI), VALUE(SAT)
+       };
+
+       time_t rawtime;
+       struct tm timeInfo;
+
+       time(&rawtime);
+       tzset();
+       localtime_r(&rawtime, &timeInfo);
+
+       int dayOfMonth = timeInfo.tm_mday;
+       int minuteOfDay = timeInfo.tm_hour * 60 + timeInfo.tm_min;
+       const char* weekDay = weekDays[timeInfo.tm_wday];
+
+       __data[NAME(DAY_OF_MONTH)] = dayOfMonth;
+       __data[NAME(DAY_OF_WEEK)] = weekDay;
+       __data[NAME(TIME_OF_DAY)] = minuteOfDay;
+
+       return __data;
+}
+
+void TemporalState::read()
+{
+}
+
+void TemporalState::subscribe()
+{
+}
+
+void TemporalState::unsubscribe()
+{
+}