2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/common/notification-manager.h>
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wall"
26 #include <boost/thread/mutex.hpp>
28 #pragma clang diagnostic pop
31 #include <boost/thread/mutex.hpp>
36 #include <dali/public-api/common/dali-common.h>
37 #include <dali/internal/event/common/property-notification-impl.h>
38 #include <dali/internal/common/message-container.h>
48 typedef boost::mutex MessageQueueMutex;
50 struct NotificationManager::Impl
53 : notificationCount(0)
61 // Used to skip duplicate operations during Notify()
62 unsigned int notificationCount;
64 // queueMutex must be locked whilst accessing queue
65 MessageQueueMutex queueMutex;
66 MessageContainer updateCompletedQueue;
67 MessageContainer updateWorkingQueue;
68 MessageContainer eventQueue;
71 NotificationManager::NotificationManager()
76 NotificationManager::~NotificationManager()
81 void NotificationManager::QueueMessage( MessageBase* message )
83 DALI_ASSERT_DEBUG( NULL != message );
85 // queueMutex must be locked whilst accessing queue
86 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
88 mImpl->updateWorkingQueue.PushBack( message );
91 void NotificationManager::UpdateCompleted()
93 // queueMutex must be locked whilst accessing queue
94 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
95 // Swap the queue, original queue ends up empty, then release the lock
96 mImpl->updateCompletedQueue.Swap( mImpl->updateWorkingQueue );
99 bool NotificationManager::MessagesToProcess()
101 // queueMutex must be locked whilst accessing queue
102 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
104 return ( false == mImpl->updateCompletedQueue.IsEmpty() );
107 void NotificationManager::ProcessMessages()
109 // Done before messages are processed, for notification count comparisons
110 ++mImpl->notificationCount;
112 // queueMutex must be locked whilst accessing queue
114 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
116 // Swap the queue, original queue ends up empty, then release the lock
117 mImpl->updateCompletedQueue.Swap( mImpl->eventQueue );
119 // end of scope, lock is released
121 MessageContainer::Iterator iter = mImpl->eventQueue.Begin();
122 MessageContainer::Iterator end = mImpl->eventQueue.End();
123 for( ; iter != end; ++iter )
125 (*iter)->Process( 0u/*ignored*/ );
128 // release the processed messages from event side queue
129 mImpl->eventQueue.Clear();
132 unsigned int NotificationManager::GetNotificationCount() const
134 return mImpl->notificationCount;
137 } // namespace Internal