Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / dali / internal / event / common / notification-manager.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/common/notification-manager.h>
19
20 // EXTERNAL INCLUDES
21 #ifdef __clang__
22 #pragma clang diagnostic push
23 #pragma clang diagnostic ignored "-Wall"
24
25 #include <boost/thread/mutex.hpp>
26
27 #pragma clang diagnostic pop
28 #else
29
30 #include <boost/thread/mutex.hpp>
31
32 #endif // __clang__
33
34 // INTERNAL INCLUDES
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>
38
39 using namespace std;
40
41 namespace Dali
42 {
43
44 namespace Internal
45 {
46
47 typedef boost::mutex MessageQueueMutex;
48
49 struct NotificationManager::Impl
50 {
51   Impl()
52   : notificationCount(0)
53   {
54   }
55
56   ~Impl()
57   {
58   }
59
60   // Used to skip duplicate operations during Notify()
61   unsigned int notificationCount;
62
63   // queueMutex must be locked whilst accessing queue
64   MessageQueueMutex queueMutex;
65   MessageContainer updateQueue;
66   MessageContainer eventQueue;
67 };
68
69 NotificationManager::NotificationManager()
70 {
71   mImpl = new Impl();
72 }
73
74 NotificationManager::~NotificationManager()
75 {
76   delete mImpl;
77 }
78
79 void NotificationManager::QueueMessage( MessageBase* message )
80 {
81   DALI_ASSERT_DEBUG( NULL != message );
82
83   // queueMutex must be locked whilst accessing queue
84   MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
85
86   mImpl->updateQueue.PushBack( message );
87 }
88
89 bool NotificationManager::MessagesToProcess()
90 {
91   // queueMutex must be locked whilst accessing queue
92   MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
93
94   return ( false == mImpl->updateQueue.IsEmpty() );
95 }
96
97 void NotificationManager::ProcessMessages()
98 {
99   // Done before messages are processed, for notification count comparisons
100   ++mImpl->notificationCount;
101
102   // queueMutex must be locked whilst accessing queue
103   {
104     MessageQueueMutex::scoped_lock lock( mImpl->queueMutex );
105
106     // Swap the queue, original queue ends up empty, then release the lock
107     mImpl->updateQueue.Swap( mImpl->eventQueue );
108   }
109   // end of scope, lock is released
110
111   MessageContainer::Iterator iter = mImpl->eventQueue.Begin();
112   MessageContainer::Iterator end = mImpl->eventQueue.End();
113   for( ; iter != end; ++iter )
114   {
115     (*iter)->Process( 0u/*ignored*/ );
116   }
117
118   // release the processed messages from event side queue
119   mImpl->eventQueue.Clear();
120 }
121
122 unsigned int NotificationManager::GetNotificationCount() const
123 {
124   return mImpl->notificationCount;
125 }
126
127 } // namespace Internal
128
129 } // namespace Dali