2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "file-descriptor-monitor.h"
34 * Using Impl to hide away EFL specific members
36 struct FileDescriptorMonitor::Impl
39 Impl( int fileDescriptor, CallbackBase* callback )
40 : mFileDescriptor( fileDescriptor ),
41 mCallback( callback ),
53 CallbackBase* mCallback;
54 Ecore_Fd_Handler* mHandler;
59 * Called when the file descriptor receives an event.
61 static Eina_Bool EventDispatch(void* data, Ecore_Fd_Handler *handler)
63 Impl* impl = reinterpret_cast<Impl*>(data);
65 CallbackBase::Execute( *impl->mCallback );
67 return ECORE_CALLBACK_RENEW;
71 FileDescriptorMonitor::FileDescriptorMonitor( int fileDescriptor, CallbackBase* callback )
73 mImpl = new Impl(fileDescriptor, callback);
75 if (fileDescriptor >= 0)
77 mImpl->mHandler = ecore_main_fd_handler_add(fileDescriptor, ECORE_FD_READ, &Impl::EventDispatch, mImpl, NULL, NULL);
81 FileDescriptorMonitor::~FileDescriptorMonitor()
85 ecore_main_fd_handler_del(mImpl->mHandler);
92 } // namespace Adaptor
94 } // namespace Internal