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 updateQueue;
67 MessageContainer eventQueue;
70 NotificationManager::NotificationManager()
75 NotificationManager::~NotificationManager()
80 void NotificationManager::QueueMessage( MessageBase* message )
82 DALI_ASSERT_DEBUG( NULL != message );
84 // queueMutex must be locked whilst accessing queue
85 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
87 mImpl->updateQueue.PushBack( message );
90 bool NotificationManager::MessagesToProcess()
92 // queueMutex must be locked whilst accessing queue
93 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
95 return ( false == mImpl->updateQueue.IsEmpty() );
98 void NotificationManager::ProcessMessages()
100 // Done before messages are processed, for notification count comparisons
101 ++mImpl->notificationCount;
103 // queueMutex must be locked whilst accessing queue
105 MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
107 // Swap the queue, original queue ends up empty, then release the lock
108 mImpl->updateQueue.Swap( mImpl->eventQueue );
110 // end of scope, lock is released
112 MessageContainer::Iterator iter = mImpl->eventQueue.Begin();
113 MessageContainer::Iterator end = mImpl->eventQueue.End();
114 for( ; iter != end; ++iter )
116 (*iter)->Process( 0u/*ignored*/ );
119 // release the processed messages from event side queue
120 mImpl->eventQueue.Clear();
123 unsigned int NotificationManager::GetNotificationCount() const
125 return mImpl->notificationCount;
128 } // namespace Internal