Merge "Add support for new accessibility actions" into devel/master
[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, CallbackBase* callback )
40   : mFileDescriptor( fileDescriptor ),
41     mCallback( callback ),
42     mHandler( NULL )
43   {
44   }
45
46   ~Impl()
47   {
48     delete mCallback;
49   }
50
51   // Data
52   int mFileDescriptor;
53   CallbackBase* mCallback;
54   Ecore_Fd_Handler* mHandler;
55
56   // Static Methods
57
58   /**
59    * Called when the file descriptor receives an event.
60    */
61   static Eina_Bool EventDispatch(void* data, Ecore_Fd_Handler *handler)
62   {
63     Impl* impl = reinterpret_cast<Impl*>(data);
64
65     CallbackBase::Execute( *impl->mCallback );
66
67     return ECORE_CALLBACK_RENEW;
68   }
69 };
70
71 FileDescriptorMonitor::FileDescriptorMonitor( int fileDescriptor, CallbackBase* callback )
72 {
73   mImpl = new Impl(fileDescriptor, callback);
74
75   if (fileDescriptor >= 0)
76   {
77     mImpl->mHandler = ecore_main_fd_handler_add(fileDescriptor, ECORE_FD_READ, &Impl::EventDispatch, mImpl, NULL, NULL);
78   }
79 }
80
81 FileDescriptorMonitor::~FileDescriptorMonitor()
82 {
83   if (mImpl->mHandler)
84   {
85     ecore_main_fd_handler_del(mImpl->mHandler);
86   }
87
88   delete mImpl;
89   mImpl = NULL;
90 }
91
92 } // namespace Adaptor
93
94 } // namespace Internal
95
96 } // namespace Dali