Track ActiveTexture calls
[platform/core/uifw/dali-adaptor.git] / adaptors / common / file-descriptor-monitor.cpp
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 "file-descriptor-monitor.h"
20
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 /**
34  * Using Impl to hide away EFL specific members
35  */
36 struct FileDescriptorMonitor::Impl
37 {
38   // Construction
39   Impl(int fileDescriptor, boost::function<void()> functor)
40   : mFileDescriptor(fileDescriptor),
41     mFunctor(functor),
42     mHandler(NULL)
43   {
44   }
45
46   // Data
47   int mFileDescriptor;
48   boost::function<void()> mFunctor;
49   Ecore_Fd_Handler* mHandler;
50
51   // Static Methods
52
53   /**
54    * Called when the file descriptor receives an event.
55    */
56   static Eina_Bool EventDispatch(void* data, Ecore_Fd_Handler *handler)
57   {
58     Impl* impl = reinterpret_cast<Impl*>(data);
59
60     impl->mFunctor();
61
62     return ECORE_CALLBACK_RENEW;
63   }
64 };
65
66 FileDescriptorMonitor::FileDescriptorMonitor(int fileDescriptor, boost::function<void()> functor)
67 {
68   mImpl = new Impl(fileDescriptor, functor);
69
70   if (fileDescriptor >= 0)
71   {
72     mImpl->mHandler = ecore_main_fd_handler_add(fileDescriptor, ECORE_FD_READ, &Impl::EventDispatch, mImpl, NULL, NULL);
73   }
74 }
75
76 FileDescriptorMonitor::~FileDescriptorMonitor()
77 {
78   if (mImpl->mHandler)
79   {
80     ecore_main_fd_handler_del(mImpl->mHandler);
81   }
82
83   delete mImpl;
84   mImpl = NULL;
85 }
86
87 } // namespace Adaptor
88
89 } // namespace Internal
90
91 } // namespace Dali