Dali 3D User Interface Engine
ecore-callback-manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 
18 // CLASS HEADER
19 #include "ecore-callback-manager.h"
20 
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 
25 
26 // INTERNAL INCLUDES
27 
28 
29 namespace Dali
30 {
31 
32 namespace Internal
33 {
34 
35 namespace Adaptor
36 {
37 
42 {
43 
48  : mCallback(callback),
50  mIdler(NULL)
51  {
52  }
57  {
58  delete mCallback;
60  }
61 
64  Ecore_Idler* mIdler;
65  };
66 
67 namespace
68 {
69 
73 Eina_Bool IdleCallback(void *data)
74 {
75  CallbackData *callbackData = static_cast< CallbackData * >( data );
76 
77  // remove callback data from the container
78  CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
79 
80  // run the function
81  CallbackBase::Execute( *callbackData->mCallback );
82 
83  // delete our data
84  delete callbackData;
85 
86  // CALLBACK Cancel will delete the idler so we don't need to call ecore_idler_del
87  return ECORE_CALLBACK_CANCEL;
88 }
89 
90 } // unnamed namespace
91 
93 :mRunning(false)
94 {
95 }
96 
97 
99 {
100  DALI_ASSERT_DEBUG( mRunning == false );
101 
102  mRunning = true;
103 }
104 
106 {
107  // make sure we're not called twice
108  DALI_ASSERT_DEBUG( mRunning == true );
109 
111 
112  mRunning = false;
113 
114 }
115 
117 {
118  if( !mRunning )
119  {
120  return false;
121  }
122 
123  CallbackData *callbackData = new CallbackData( callback );
124 
126 
127  // add the call back to the container
128  mCallbackContainer.push_front(callbackData);
129 
130  // add the idler
131  callbackData->mIdler = ecore_idler_add( IdleCallback, callbackData);
132 
133  DALI_ASSERT_ALWAYS( ( callbackData->mIdler != NULL ) && "Idle method not created" );
134 
135  return true;
136 }
137 
139 {
140  mCallbackContainer.remove(callbackData);
141 }
142 
144 {
145  // always called from main thread
146  for( CallbackList::iterator iter = mCallbackContainer.begin(); iter != mCallbackContainer.end(); ++iter)
147  {
148  CallbackData* data = (*iter);
149 
150  ecore_idler_del( data->mIdler );
151 
152  delete data;
153 
154  }
155  mCallbackContainer.clear();
156 }
157 
158 // Creates a concrete interface for CallbackManager
160 {
161  return new EcoreCallbackManager;
162 }
163 
164 } // namespace Adaptor
165 
166 } // namespace Internal
167 
168 } // namespace Dali
Dali Docs Home
Read more about Dali