%if 0%{?tizen_feature_power_support}
BuildRequires: pkgconfig(push)
BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(libpcrecpp)
%endif
%if 0%{?tizen_feature_tv_display_support}
'packages': [
'push',
'capi-appfw-application',
+ 'libpcrecpp',
]
},
}],
for (var key in dict) {
if (dict.hasOwnProperty(key)) {
Object.defineProperty(this, key, {
- value: dict[key],
+ value: key === 'date' ? new Date(dict[key] * 1000) : dict[key],
enumerable: true
});
}
namespace extension {
namespace push {
-PushInstance::PushInstance() {
+PushInstance::PushInstance():
+ m_ignoreNotificationEvents(true) {
LoggerD("Enter");
using std::placeholders::_1;
using std::placeholders::_2;
std::bind(&PushInstance::registerService, this, _1, _2));
RegisterHandler("Push_unregisterService",
std::bind(&PushInstance::unregisterService, this, _1, _2));
- RegisterHandler("Push_connectService",
+ RegisterSyncHandler("Push_connectService",
std::bind(&PushInstance::connectService, this, _1, _2));
RegisterSyncHandler("Push_disconnectService",
std::bind(&PushInstance::disconnectService, this, _1, _2));
void PushInstance::connectService(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
+ m_ignoreNotificationEvents = false;
picojson::value result;
ReportSuccess(result, out);
}
void PushInstance::disconnectService(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
+ m_ignoreNotificationEvents = true;
picojson::value result;
ReportSuccess(result, out);
}
PostMessage(res.serialize().c_str());
}
+void PushInstance::onPushNotify(const std::string& appData,
+ const std::string& alertMessage, double date) {
+ LoggerD("Enter");
+ if (m_ignoreNotificationEvents) {
+ LoggerD("Listener not set, ignoring event");
+ }
+ picojson::value::object dict;
+ dict["listenerId"] = picojson::value("Push_Notification_Listener");
+ picojson::value::object pushMessage;
+ pushMessage["appData"] = picojson::value(appData);
+ pushMessage["alertMessage"] = picojson::value(alertMessage);
+ pushMessage["date"] = picojson::value(date);
+ dict["pushMessage"] = picojson::value(pushMessage);
+ picojson::value resultListener(dict);
+ PostMessage(resultListener.serialize().c_str());
+}
+
PushInstance::~PushInstance() {
LoggerD("Enter");
}
virtual ~PushInstance();
virtual void onPushRegister(double callbackId,
common::PlatformResult result, const std::string& id);
+ virtual void onPushNotify(const std::string& appData,
+ const std::string& alertMessage, double date);
+
private:
void registerService(const picojson::value& args, picojson::object& out);
void unregisterService(const picojson::value& args, picojson::object& out);
void getRegistrationId(const picojson::value& args, picojson::object& out);
void getUnreadNotifications(const picojson::value& args,
picojson::object& out);
+
+ bool m_ignoreNotificationEvents;
};
} // namespace push
#include "push/push_manager.h"
#include <unistd.h>
+#include <pcrecpp.h>
#include <app_control.h>
#include <app_manager.h>
#include "common/logger.h"
void PushManager::onPushNotify(push_notification_h noti, void* user_data) {
LoggerD("Enter");
+ if (!getInstance().m_listener) {
+ LoggerW("Listener not set, ignoring");
+ return;
+ }
+
+ char* temp = NULL;
+ int ret = push_get_notification_data(noti, &temp);
+ if (ret != PUSH_ERROR_NONE) {
+ LoggerE("Failed to get appData");
+ return;
+ }
+ std::string appData = temp;
+ free(temp);
+
+ temp = NULL;
+ ret = push_get_notification_message(noti, &temp);
+ if (ret != PUSH_ERROR_NONE) {
+ LoggerE("Failed to get message");
+ return;
+ }
+
+ // parse query string and find value for alertMessage
+ pcrecpp::StringPiece input(temp);
+ pcrecpp::RE re("([^=]+)=([^&]*)&?");
+ string key;
+ string value;
+ std::string alertMessage;
+ while (re.Consume(&input, &key, &value)) {
+ if (key == "alertMessage") {
+ alertMessage = value;
+ break;
+ }
+ }
+ free(temp);
+
+ int64_t date = -1;
+ ret = push_get_notification_time(noti, &date);
+ if (ret != PUSH_ERROR_NONE) {
+ LoggerE("Failed to get date");
+ return;
+ }
+ getInstance().m_listener->onPushNotify(appData, alertMessage, date);
}
void PushManager::onPushRegister(push_result_e result, const char* msg,
public:
virtual void onPushRegister(double callbackId,
common::PlatformResult result, const std::string& id) = 0;
+ virtual void onPushNotify(const std::string& appData,
+ const std::string& alertMessage, double date) = 0;
virtual ~EventListener() {}
};