From: Inkyun Kil Date: Fri, 14 Feb 2020 05:14:48 +0000 (+0900) Subject: Implement OnReceived for ambient-viewer X-Git-Tag: submit/tizen/20200303.071956~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09fb64c5c52850f2171fc031759454d7d4cfa77c;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Implement OnReceived for ambient-viewer Change-Id: I8777d13767aabb178b1068e1cc4a39a6d83e9b8d Signed-off-by: Inkyun Kil --- diff --git a/ambient-viewer/include/ambient_viewer.h b/ambient-viewer/include/ambient_viewer.h index a5c283b..3ade1e7 100644 --- a/ambient-viewer/include/ambient_viewer.h +++ b/ambient-viewer/include/ambient_viewer.h @@ -98,4 +98,4 @@ int ambient_viewer_get_top_app_surface(ambient_viewer_h handle, #ifdef __cplusplus } #endif -#endif /* __AMBIENT_VIEWER_INCLUDE_AMBIENT_VIEWER_H__ */ +#endif /* __AMBIENT_VIEWER_INCLUDE_AMBIENT_VIEWER_H__ */ \ No newline at end of file diff --git a/ambient-viewer/src/ambient-viewer.cc b/ambient-viewer/src/ambient-viewer.cc index a90bd40..eb4ff02 100644 --- a/ambient-viewer/src/ambient-viewer.cc +++ b/ambient-viewer/src/ambient-viewer.cc @@ -23,10 +23,32 @@ #include "top-app-surface.h" #include "watch-surface.h" +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "AMBIENT_VIEWER" + +using namespace tizen_base; namespace ambient_viewer { AmbientViewer::AmbientViewer(std::shared_ptr win) : win_(win) { + char appid_buf[512] = {0, }; + if (aul_app_get_appid_bypid( + getpid(), appid_buf, sizeof(appid_buf)) != AUL_R_OK) { + LOGE("Failed to get appid (%d)", getpid()); + } + + char endpoint[530]; + snprintf(endpoint, sizeof(endpoint), "send_extra_data:%s", appid_buf); + + if (aul_app_com_create(endpoint, nullptr, OnReceiveSignal, + this, &receive_signal_conn_) != AUL_R_OK) { + LOGE("Failed to listen sendextra signal"); + } + + LOGD("CREATE AMBIENT VIEWER"); } AmbientViewer::~AmbientViewer() = default; @@ -45,13 +67,10 @@ void AmbientViewer::Unmonitor() { watch_surface_.reset(); } -void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender, - bundle* extra) { -} - int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir, - bundle* extra) { + Bundle extra) { bundle* b; + bundle* extra_data; bundle_raw* raw = nullptr; int len; int ret; @@ -62,10 +81,12 @@ int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir, return -1; } + extra_data = extra.GetHandle(); + snprintf(ambient_mode, sizeof(ambient_mode), "%d", (int)enter); bundle_add_str(b, "__AMBIENT_MODE__", ambient_mode); - bundle_encode(extra, &raw, &len); + bundle_encode(extra_data, &raw, &len); bundle_add_str(b, "__AMBIENT_EXTRA__", (const char*)raw); switch (dir) { @@ -99,7 +120,6 @@ int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir, return 0; } - const ISurface& AmbientViewer::GetWatchSurface() const { return *watch_surface_; } @@ -108,5 +128,30 @@ const ISurface& AmbientViewer::GetTopAppSurface() const { return *top_app_surface_; } +int AmbientViewer::OnReceiveSignal(const char* endpoint, aul_app_com_result_e e, + bundle* envelope, void* user_data) +{ + AmbientViewer* av = (AmbientViewer*)user_data; + LOGD("OnReceiveSignal"); + + if (!envelope) { + LOGE("Bad bundle data from application"); + return -1; + } + + Bundle b = Bundle(envelope, false, false); + + std::string event_type= b.GetString("UI_APP_AMBIENT_EVENT"); + int type = stoi(event_type); + + std::string sender = b.GetString("UI_APP_AMBIENT_SENDER"); + + b.Delete("UI_APP_AMBIENT_EVENT"); + b.Delete("UI_APP_AMBIENT_SENDER"); + + av->OnReceived((EventType)type, sender, b); + + return 0; +} } // namespace ambient_viewer diff --git a/ambient-viewer/src/ambient-viewer.h b/ambient-viewer/src/ambient-viewer.h index 48adc80..d500e57 100644 --- a/ambient-viewer/src/ambient-viewer.h +++ b/ambient-viewer/src/ambient-viewer.h @@ -17,7 +17,10 @@ #ifndef __AMBIENT_VIEWER_AMBIENT_VIEWER_H__ #define __AMBIENT_VIEWER_AMBIENT_VIEWER_H__ +#include +#include #include +#include #include #include @@ -47,18 +50,24 @@ class EXPORT_API AmbientViewer : public IAmbientViewer { public: AmbientViewer(std::shared_ptr win); + virtual ~AmbientViewer(); + virtual void OnReceived(EventType ev, std::string sender, tizen_base::Bundle extra) = 0; + void Monitor(); void Unmonitor(); - void OnReceived(EventType ev, std::string sender, bundle *extra); - int NotifyAmbientEvent(bool enter, Direction dir, bundle *extra); + int NotifyAmbientEvent(bool enter, Direction dir, tizen_base::Bundle extra); const ISurface& GetWatchSurface() const; const ISurface& GetTopAppSurface() const; private: + static int OnReceiveSignal(const char *endpoint, aul_app_com_result_e e, + bundle *envelope, void *user_data); + std::shared_ptr win_; std::shared_ptr watch_surface_; std::shared_ptr top_app_surface_; + aul_app_com_connection_h receive_signal_conn_; }; } // namespace ambient_viewer diff --git a/ambient-viewer/src/stub.cc b/ambient-viewer/src/stub.cc index 8e0f2b5..cfbb737 100644 --- a/ambient-viewer/src/stub.cc +++ b/ambient-viewer/src/stub.cc @@ -25,6 +25,7 @@ #include "isurface.h" using namespace std; +using namespace tizen_base; using namespace ambient_viewer; using namespace screen_connector; @@ -57,15 +58,17 @@ class MonitorCallbackInfo { void* user_data_; }; -class EventCallbackInfo { +class ReceiveCallbackInfo { public: - EventCallbackInfo(ambient_viewer_event_cb cb, void* user_data) + ReceiveCallbackInfo(ambient_viewer_event_cb cb, void* user_data) : cb_(cb), user_data_(user_data) { } - void InvokeEventCallback(AmbientViewer::EventType event, std::string sender, - bundle *extra) { - cb_(static_cast(event), sender.c_str(), extra, + void InvokeReceiveCallback(AmbientViewer::EventType event, std::string sender, + Bundle extra) { + bundle *b; + b = extra.GetHandle(); + cb_(static_cast(event), sender.c_str(), b, user_data_); } @@ -92,8 +95,8 @@ class AmbientViewerStub : public AmbientViewer { monitor_cb_->InvokeRemoved(surface); } - void OnEvent(EventType ev, string sender, bundle* extra) { - event_cb_->InvokeEventCallback(ev, sender, extra); + void OnReceived(EventType ev, string sender, Bundle extra) { + event_cb_->InvokeReceiveCallback(ev, sender, extra); } int SetMonitorCallbackInfo(unique_ptr info) { @@ -106,19 +109,19 @@ class AmbientViewerStub : public AmbientViewer { return AMBIENT_VIEWER_ERROR_NONE; } - int SetEventCallbackInfo (unique_ptr info) { + int SetReceiveCallbackInfo (unique_ptr info) { event_cb_ = move(info); return AMBIENT_VIEWER_ERROR_NONE; } - int ClearEventCallbackInfo() { + int ClearReceiveCallbackInfo() { event_cb_.reset(); return AMBIENT_VIEWER_ERROR_NONE; } private: unique_ptr monitor_cb_; - unique_ptr event_cb_; + unique_ptr event_cb_; }; extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win, @@ -129,7 +132,7 @@ extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win, return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER; } - AmbientViewerStub* h = new (std::nothrow) AmbientViewerStub( + AmbientViewerStub* h = new (nothrow) AmbientViewerStub( shared_ptr(new EvasObject(win, false))); if (h == nullptr) { LOGE("out of memory"); @@ -164,7 +167,7 @@ extern "C" EXPORT_API int ambient_viewer_notify_ambient_event( } AmbientViewerStub* stub = static_cast(handle); - stub->NotifyAmbientEvent(enter, static_cast(dir), extra); + stub->NotifyAmbientEvent(enter, static_cast(dir), Bundle(extra, false, false)); return AMBIENT_VIEWER_ERROR_NONE; } @@ -217,14 +220,14 @@ extern "C" EXPORT_API int ambient_viewer_set_event_listener( AmbientViewerStub* stub = static_cast(handle); - unique_ptr info ( - new (nothrow)EventCallbackInfo(callback, user_data)); + unique_ptr info ( + new (nothrow)ReceiveCallbackInfo(callback, user_data)); if (info.get() == nullptr) { LOGE("out of memory"); return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY; } - stub->SetEventCallbackInfo(move(info)); + stub->SetReceiveCallbackInfo(move(info)); return AMBIENT_VIEWER_ERROR_NONE; } @@ -238,7 +241,7 @@ extern "C" EXPORT_API int ambient_viewer_unset_event_listener( } AmbientViewerStub* stub = static_cast(handle); - stub->ClearEventCallbackInfo(); + stub->ClearReceiveCallbackInfo(); return AMBIENT_VIEWER_ERROR_NONE; } diff --git a/unittest/src/test_ambient_viewer.cc b/unittest/src/test_ambient_viewer.cc index 24d088e..5dc8517 100644 --- a/unittest/src/test_ambient_viewer.cc +++ b/unittest/src/test_ambient_viewer.cc @@ -23,6 +23,7 @@ using namespace std; using namespace ambient_viewer; using namespace screen_connector; +using namespace tizen_base; class AmbientViewerStub : public AmbientViewer { public: @@ -32,6 +33,7 @@ class AmbientViewerStub : public AmbientViewer { void OnAdded(const ISurface& surface) override {} void OnUpdated(const ISurface& surface) override {} void OnRemoved(const ISurface& surface) override {} + void OnReceived(EventType ev, string sender, Bundle extra) override {} }; class AmbientViewerTest : public ::testing::Test {