#include <dlog.h>
#include <aul_app_com.h>
#include <uuid/uuid.h>
+#include <stdexcept>
#include "ambient-viewer.hh"
#include "top-app-surface.hh"
: win_(win) {
if (aul_app_com_create("aod.ambientevent", nullptr, OnReceiveSignal,
this, &receive_signal_conn_) != AUL_R_OK) {
- LOGE("Failed to listen sendextra signal");
+ LOGE("Failed to listen send extra signal");
+ }
+
+ if (aul_app_com_create("watch.dead", nullptr,
+ OnDeadSignal, this, &dead_signal_conn_) != AUL_R_OK) {
+ LOGE("failed to listen dead signal");
}
LOGD("CREATE AMBIENT VIEWER");
AmbientViewer::~AmbientViewer() {
if (receive_signal_conn_)
aul_app_com_leave(receive_signal_conn_);
+ if (dead_signal_conn_)
+ aul_app_com_leave(dead_signal_conn_);
}
std::shared_ptr<ISurface> AmbientViewer::CreateWatchSurface(int rid,
try {
Bundle data(safe_raw.get());
string appid = data.GetString(NOTIFY_CHANGED_EVENT_APPID_KEY);
+ if (!viewer->watch_stack_.empty()) {
+ if (viewer->watch_stack_.back()->GetAppId() == appid) {
+ LOGW("Already activated watch(%s)", appid.c_str());
+ return;
+ }
+ }
string rid = data.GetString(NOTIFY_CHANGED_EVENT_RID_KEY);
- viewer->watch_surface_ = viewer->CreateWatchSurface(
- stoi(rid), viewer->GetUUID(rid), appid, viewer->win_, viewer);
+ viewer->watch_stack_.push_back(viewer->CreateWatchSurface(
+ stoi(rid), viewer->GetUUID(rid), appid, viewer->win_, viewer));
viewer->OnReceived(EVENT_WATCH_CHANGED, appid, data);
} catch (const std::exception& e) {
LOGE("Exception occurred : %s", e.what());
}
}
+int AmbientViewer::OnDeadSignal(const char *endpoint, aul_app_com_result_e e,
+ bundle *envelope, void *user_data) {
+ AmbientViewer* viewer = (AmbientViewer*)user_data;
+ Bundle data(envelope, false, false);
+ string appid = data.GetString(AUL_K_APPID);
+ LOGW("Watch(%s) DEAD", appid.c_str());
+ list<shared_ptr<ISurface>>::iterator it;
+ for (it = viewer->watch_stack_.begin(); it != viewer->watch_stack_.end(); ++it) {
+ if ((*it)->GetAppId() == appid) {
+ viewer->watch_stack_.erase(it);
+ LOGW("REMOVE DEAD WATCH (%s)", appid.c_str());
+ break;
+ }
+ }
+ LOGW("DEAD DONE (%s)", appid.c_str());
+ return 0;
+}
+
void AmbientViewer::Monitor(bool full) {
if (full) {
void AmbientViewer::Unmonitor() {
top_app_surface_.reset();
- watch_surface_.reset();
+ watch_stack_.clear();
}
void AmbientViewer::BlockUpdate(bool enable) {
LOGW("Top App Block Update (%d)", enable);
}
- if (watch_surface_ != nullptr && watch_surface_.get() != nullptr) {
- watch_surface_->BlockUpdate(enable);
- LOGW("Watch Block Update (%d)", enable);
+ if (watch_stack_.empty()) {
+ LOGW("Empty stack!");
+ return;
}
+
+ watch_stack_.back()->BlockUpdate(enable);
+ LOGW("Watch Block Update (%d)", enable);
}
void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender,
}
const ISurface& AmbientViewer::GetWatchSurface() const {
- return *watch_surface_;
+ if (watch_stack_.empty()) {
+ LOGE("watch surface stack is empty !");
+ throw std::runtime_error("watch surface stack is empty !");
+ }
+ return *watch_stack_.back();
}
const ISurface& AmbientViewer::GetTopAppSurface() const {
#include <string>
#include <memory>
+#include <list>
#include "iambient-viewer.hh"
#include "isurface.hh"
private:
std::string GetUUID(std::string rid) const;
+ static int OnDeadSignal(const char *endpoint, aul_app_com_result_e e,
+ bundle *envelope, void *user_data);
static void OnChangedSignal(keynode_t *node, void *user_data);
static int OnReceiveSignal(const char *endpoint, aul_app_com_result_e e,
bundle *envelope, void *user_data);
Evas_Object* win_;
- std::shared_ptr<ISurface> watch_surface_;
+ std::list<std::shared_ptr<ISurface>> watch_stack_;
std::shared_ptr<ISurface> top_app_surface_;
+ aul_app_com_connection_h dead_signal_conn_ = nullptr;
aul_app_com_connection_h receive_signal_conn_ = nullptr;
};
AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
}
-TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface) {
+TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface_n2) {
ambient_viewer_h handle = nullptr;
ambient_viewer_surface_h surface = nullptr;
ASSERT_EQ(ambient_viewer_create_mock(reinterpret_cast<Evas_Object*>(&__not_null),
ASSERT_NE(handle, nullptr);
EXPECT_EQ(ambient_viewer_get_watch_surface(handle, &surface),
- AMBIENT_VIEWER_ERROR_NONE);
- EXPECT_EQ(surface, nullptr);
+ AMBIENT_VIEWER_ERROR_INVALID_OPERATION);
ASSERT_EQ(ambient_viewer_destroy(handle),
AMBIENT_VIEWER_ERROR_NONE);