Add missing files 18/226018/1
authorhyunho <hhstark.kang@samsung.com>
Wed, 26 Feb 2020 07:01:15 +0000 (16:01 +0900)
committerhyunho <hhstark.kang@samsung.com>
Wed, 26 Feb 2020 07:01:38 +0000 (16:01 +0900)
Change-Id: I7ef4b60c45578b136656bb8b1fa411602a5579d4
Signed-off-by: hyunho <hhstark.kang@samsung.com>
watch-holder/src/ambient_listener.cc [new file with mode: 0644]
watch-holder/src/ambient_listener.hh [new file with mode: 0644]

diff --git a/watch-holder/src/ambient_listener.cc b/watch-holder/src/ambient_listener.cc
new file mode 100644 (file)
index 0000000..48bf595
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2020 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 <string>
+
+#include <bundle_cpp.h>
+#include <bundle.h>
+#include <aul.h>
+#include <aul_app_com.h>
+#include <dlog.h>
+
+#include "common.hh"
+#include "ambient_listener.hh"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_HOLDER"
+
+using namespace tizen_base;
+using namespace std;
+namespace watch_holder {
+  AmbientListener::AmbientListener() {
+    if (aul_app_com_create("watch.ambientchange", nullptr, OnAmbientChangedSignal,
+        this, &ambient_changed_signal_conn_) != AUL_R_OK) {
+      LOGE("Failed to listen watch.launch signal");
+    }
+  }
+
+  AmbientListener::~AmbientListener() {
+    if (ambient_changed_signal_conn_)
+      aul_app_com_leave(ambient_changed_signal_conn_);
+  }
+}
diff --git a/watch-holder/src/ambient_listener.hh b/watch-holder/src/ambient_listener.hh
new file mode 100644 (file)
index 0000000..bb73255
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#ifndef __WATCH_HOLDER_AMBIENT_LISTENER_HH__
+#define __WATCH_HOLDER_AMBIENT_LISTENER_HH__
+
+#include <bundle_cpp.h>
+#include <aul_app_com.h>
+
+#include "common.hh"
+
+namespace watch_holder {
+
+class AmbientListener {
+ public:
+  AmbientListener();
+  ~AmbientListener();
+  static int OnAmbientChangedSignal(const char *endpoint,
+      aul_app_com_result_e e, bundle *envelope, void *user_data) {
+    tizen_base::Bundle data(envelope, false, false);
+    AmbientListener* listener = (AmbientListener*)user_data;
+    std::string mode = data.GetString("__AMBIENT_MODE__");
+    std::string extra = data.GetString("__AMBIENT_EXTRA__");
+    if (mode.empty())
+      return 0;
+
+    tizen_base::Bundle extra_data;
+    bool enter;
+    try {
+      extra_data = tizen_base::Bundle(extra);
+      enter = (bool)stoi(mode);
+    } catch (const std::exception& e) {
+      return 0;
+    }
+    listener->OnAmbientChanged(enter, extra_data);
+    return 0;
+  }
+
+  virtual void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) = 0;
+
+ private:
+  aul_app_com_connection_h ambient_changed_signal_conn_;
+};
+
+}  // namespace watch_holder
+
+#endif  // __WATCH_HOLDER_AMBIENT_LISTENER_HH__
\ No newline at end of file