#ifdef __cplusplus
}
#endif
-#endif /* __AMBIENT_VIEWER_INCLUDE_AMBIENT_VIEWER_H__ */
+#endif /* __AMBIENT_VIEWER_INCLUDE_AMBIENT_VIEWER_H__ */
\ No newline at end of file
#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<screen_connector::EvasObject> 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;
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;
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) {
return 0;
}
-
const ISurface& AmbientViewer::GetWatchSurface() const {
return *watch_surface_;
}
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
#ifndef __AMBIENT_VIEWER_AMBIENT_VIEWER_H__
#define __AMBIENT_VIEWER_AMBIENT_VIEWER_H__
+#include <aul.h>
+#include <aul_app_com.h>
#include <bundle.h>
+#include <bundle_cpp.h>
#include <string>
#include <memory>
public:
AmbientViewer(std::shared_ptr<screen_connector::EvasObject> 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<screen_connector::EvasObject> win_;
std::shared_ptr<ISurface> watch_surface_;
std::shared_ptr<ISurface> top_app_surface_;
+ aul_app_com_connection_h receive_signal_conn_;
};
} // namespace ambient_viewer
#include "isurface.h"
using namespace std;
+using namespace tizen_base;
using namespace ambient_viewer;
using namespace screen_connector;
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<ambient_event_type_e>(event), sender.c_str(), extra,
+ void InvokeReceiveCallback(AmbientViewer::EventType event, std::string sender,
+ Bundle extra) {
+ bundle *b;
+ b = extra.GetHandle();
+ cb_(static_cast<ambient_event_type_e>(event), sender.c_str(), b,
user_data_);
}
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<MonitorCallbackInfo> info) {
return AMBIENT_VIEWER_ERROR_NONE;
}
- int SetEventCallbackInfo (unique_ptr<EventCallbackInfo> info) {
+ int SetReceiveCallbackInfo (unique_ptr<ReceiveCallbackInfo> 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<MonitorCallbackInfo> monitor_cb_;
- unique_ptr<EventCallbackInfo> event_cb_;
+ unique_ptr<ReceiveCallbackInfo> event_cb_;
};
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<EvasObject>(new EvasObject(win, false)));
if (h == nullptr) {
LOGE("out of memory");
}
AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
- stub->NotifyAmbientEvent(enter, static_cast<AmbientViewer::Direction>(dir), extra);
+ stub->NotifyAmbientEvent(enter, static_cast<AmbientViewer::Direction>(dir), Bundle(extra, false, false));
return AMBIENT_VIEWER_ERROR_NONE;
}
AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
- unique_ptr<EventCallbackInfo> info (
- new (nothrow)EventCallbackInfo(callback, user_data));
+ unique_ptr<ReceiveCallbackInfo> 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;
}
}
AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
- stub->ClearEventCallbackInfo();
+ stub->ClearReceiveCallbackInfo();
return AMBIENT_VIEWER_ERROR_NONE;
}
using namespace std;
using namespace ambient_viewer;
using namespace screen_connector;
+using namespace tizen_base;
class AmbientViewerStub : public AmbientViewer {
public:
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 {