2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/event/common/notification-manager.h>
22 #pragma clang diagnostic push
23 #pragma clang diagnostic ignored "-Wall"
25 #include <boost/thread/mutex.hpp>
27 #pragma clang diagnostic pop
30 #include <boost/thread/mutex.hpp>
35 #include <dali/public-api/common/dali-common.h>
36 #include <dali/internal/event/common/property-notification-impl.h>
37 #include <dali/internal/common/message-container.h>
47 typedef boost::mutex MessageQueueMutex;
49 struct NotificationManager::Impl
52 : notificationCount(0)
60 // Used to skip duplicate operations during Notify()
61 unsigned int notificationCount;
63 // queueMutex must be locked whilst accessing queue
64 MessageQueueMutex queueMutex;
65 MessageContainer updateQueue;
66 MessageContainer eventQueue;
69 NotificationManager::NotificationManager()
74 NotificationManager::~NotificationManager()
79 void NotificationManager::QueueMessage( MessageBase* message )
81 DALI_ASSERT_DEBUG( NULL != message );
83 // queueMutex must be locked whilst accessing queue
84 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
86 mImpl->updateQueue.PushBack( message );
89 bool NotificationManager::MessagesToProcess()
91 // queueMutex must be locked whilst accessing queue
92 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
94 return ( false == mImpl->updateQueue.IsEmpty() );
97 void NotificationManager::ProcessMessages()
99 // Done before messages are processed, for notification count comparisons
100 ++mImpl->notificationCount;
102 // queueMutex must be locked whilst accessing queue
104 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
106 // Swap the queue, original queue ends up empty, then release the lock
107 mImpl->updateQueue.Swap( mImpl->eventQueue );
109 // end of scope, lock is released
111 MessageContainer::Iterator iter = mImpl->eventQueue.Begin();
112 MessageContainer::Iterator end = mImpl->eventQueue.End();
113 for( ; iter != end; ++iter )
115 (*iter)->Process( 0u/*ignored*/ );
118 // release the processed messages from event side queue
119 mImpl->eventQueue.Clear();
122 unsigned int NotificationManager::GetNotificationCount() const
124 return mImpl->notificationCount;
127 } // namespace Internal