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>
21 #include <boost/thread/mutex.hpp>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/internal/event/common/property-notification-impl.h>
26 #include <dali/internal/common/message-container.h>
36 typedef boost::mutex MessageQueueMutex;
38 struct NotificationManager::Impl
41 : notificationCount(0)
49 // Used to skip duplicate operations during Notify()
50 unsigned int notificationCount;
52 // queueMutex must be locked whilst accessing queue
53 MessageQueueMutex queueMutex;
54 MessageContainer updateQueue;
55 MessageContainer eventQueue;
58 NotificationManager::NotificationManager()
63 NotificationManager::~NotificationManager()
68 void NotificationManager::QueueMessage( MessageBase* message )
70 DALI_ASSERT_DEBUG( NULL != message );
72 // queueMutex must be locked whilst accessing queue
73 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
75 mImpl->updateQueue.PushBack( message );
78 bool NotificationManager::MessagesToProcess()
80 // queueMutex must be locked whilst accessing queue
81 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
83 return ( false == mImpl->updateQueue.IsEmpty() );
86 void NotificationManager::ProcessMessages()
88 // Done before messages are processed, for notification count comparisons
89 ++mImpl->notificationCount;
91 // queueMutex must be locked whilst accessing queue
93 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
95 // Swap the queue, original queue ends up empty, then release the lock
96 mImpl->updateQueue.Swap( mImpl->eventQueue );
98 // end of scope, lock is released
100 MessageContainer::Iterator iter = mImpl->eventQueue.Begin();
101 MessageContainer::Iterator end = mImpl->eventQueue.End();
102 for( ; iter != end; ++iter )
104 (*iter)->Process( 0u/*ignored*/ );
107 // release the processed messages from event side queue
108 mImpl->eventQueue.Clear();
111 unsigned int NotificationManager::GetNotificationCount() const
113 return mImpl->notificationCount;
116 } // namespace Internal