--- /dev/null
+/*
+ * 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_);
+ }
+}
--- /dev/null
+/*
+ * 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