#include "notification/mobile/notification_manager.h"
-// Utility to lock a mutex and unlock it in the end of the scope.
-struct AutoLock {
- explicit AutoLock(pthread_mutex_t* m) : m_(m) { pthread_mutex_lock(m_); }
- ~AutoLock() { pthread_mutex_unlock(m_); }
- private:
- pthread_mutex_t* m_;
-};
-
NotificationManager::NotificationManager() {
- pthread_mutex_init(&mutex_, NULL);
notification_register_detailed_changed_cb(
OnDetailedChanged, reinterpret_cast<void*>(this));
}
-NotificationManager::~NotificationManager() {
- // Extension should outlive all its contexts, so when it is shutdown, all the
- // contexts were destroyed, so no contention here.
- pthread_mutex_destroy(&mutex_);
-}
+NotificationManager::~NotificationManager() {}
notification_h NotificationManager::CreateNotification() {
- AutoLock lock(&mutex_);
return notification_new(NOTIFICATION_TYPE_NOTI,
NOTIFICATION_GROUP_ID_NONE,
NOTIFICATION_PRIV_ID_NONE);
bool NotificationManager::PostNotification(const std::string& id,
notification_h notification,
NotificationClient* client) {
- AutoLock lock(&mutex_);
int priv_id;
notification_error_e err = notification_insert(notification, &priv_id);
if (err != NOTIFICATION_ERROR_NONE)
}
bool NotificationManager::RemoveNotification(const std::string& id) {
- AutoLock lock(&mutex_);
IDMap::iterator it = id_map_.find(id);
if (it == id_map_.end())
return false;
}
void NotificationManager::DetachClient(NotificationClient* client) {
- AutoLock lock(&mutex_);
IDMap::iterator it = id_map_.begin();
while (it != id_map_.end()) {
IDMap::iterator current = it++;
void NotificationManager::OnDetailedChanged(
notification_type_e type, notification_op* op_list, int num_op) {
- AutoLock lock(&mutex_);
// This function gets warned about every notification event for every
// application. This code filters so we just look into removals of priv_ids
// handled by this manager.