Dali 3D User Interface Engine
ecore-file-descriptor-monitor.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
20 
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 
24 // INTERNAL INCLUDES
26 
27 namespace Dali
28 {
29 
30 namespace Internal
31 {
32 
33 namespace Adaptor
34 {
35 
40 {
41  // Construction
42  Impl( int fileDescriptor, CallbackBase* callback, int eventsToMonitor)
43  : mFileDescriptor( fileDescriptor ),
44  mEventsToMonitor( eventsToMonitor ),
45  mCallback( callback ),
46  mHandler( NULL )
47  {
48  }
49 
51  {
52  delete mCallback;
53  }
54 
55  // Data
59  Ecore_Fd_Handler* mHandler;
60 
61  // Static Methods
62 
66  static Eina_Bool EventDispatch(void* data, Ecore_Fd_Handler *handler)
67  {
68  Impl* impl = reinterpret_cast<Impl*>(data);
69 
70  // if we want read events, check to see if a read event is available
72 
73  if( ecore_main_fd_handler_active_get( handler, ECORE_FD_ERROR) )
74  {
76  DALI_LOG_ERROR("ECORE_FD_ERROR occurred on %d", impl->mFileDescriptor);
77 
78  return ECORE_CALLBACK_CANCEL;
79  }
80 
81  if( impl->mEventsToMonitor & ECORE_FD_READ )
82  {
83  if (ecore_main_fd_handler_active_get( handler, ECORE_FD_READ))
84  {
86  }
87  }
88  // check if we want write events
89  if( impl->mEventsToMonitor & ECORE_FD_WRITE )
90  {
91  if (ecore_main_fd_handler_active_get( handler, ECORE_FD_WRITE))
92  {
94  }
95  }
96 
97  // if there is an event, execute the callback
99  {
100  CallbackBase::Execute( *impl->mCallback, static_cast< FileDescriptorMonitor::EventType >(type ) );
101  }
102 
103  return ECORE_CALLBACK_RENEW;
104  }
105 };
106 
107 FileDescriptorMonitor::FileDescriptorMonitor( int fileDescriptor, CallbackBase* callback, int eventBitmask)
108 {
109  mImpl = new Impl(fileDescriptor, callback, eventBitmask);
110 
111  if (fileDescriptor < 1)
112  {
113  DALI_ASSERT_ALWAYS( 0 && "Invalid File descriptor");
114  return;
115  }
116 
117  int events = 0;
118  if( eventBitmask & FD_READABLE)
119  {
120  events = ECORE_FD_READ;
121  }
122  if( eventBitmask & FD_WRITABLE)
123  {
124  events |= ECORE_FD_WRITE;
125  }
126  mImpl->mEventsToMonitor = events;
127  mImpl->mHandler = ecore_main_fd_handler_add( fileDescriptor, static_cast<Ecore_Fd_Handler_Flags >( events ), &Impl::EventDispatch, mImpl, NULL, NULL );
128 
129 }
130 
132 {
133  if (mImpl->mHandler)
134  {
135  ecore_main_fd_handler_del(mImpl->mHandler);
136  }
137 
138  delete mImpl;
139  mImpl = NULL;
140 }
141 
142 } // namespace Adaptor
143 
144 } // namespace Internal
145 
146 } // namespace Dali
Dali Docs Home
Read more about Dali