00001 /* 00002 * Scale Stack 00003 * 00004 * Copyright 2010 Eric Day 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00024 #ifndef SCALESTACK_EVENT_LIBEVENT_HANDLER_PROVIDER_H 00025 #define SCALESTACK_EVENT_LIBEVENT_HANDLER_PROVIDER_H 00026 00027 #include <event.h> 00028 00029 #include <scalestack/event/handler.h> 00030 00031 namespace scalestack 00032 { 00033 namespace event 00034 { 00035 namespace libevent 00036 { 00037 00038 class thread; 00039 00043 extern "C" void handler_provider_callback(int file_descriptor, 00044 short events, 00045 void* context); 00046 00050 class handler_provider: public event::handler_provider 00051 { 00052 public: 00053 00061 handler_provider(kernel::module& module, handler* handler, thread& thread); 00062 00063 ~handler_provider(); 00064 00068 void start(void); 00069 00073 void stop(void); 00074 00078 void set_timer(uint64_t milliseconds); 00079 00083 void set_file_descriptor(int file_descriptor); 00084 00088 void watch_read(void); 00089 00093 void watch_write(void); 00094 00098 void run_now(void); 00099 00106 bool add_to_check_queue(void); 00107 00112 void check(void); 00113 00114 private: 00115 00119 handler_provider(const handler_provider&); 00120 00124 handler_provider& operator=(const handler_provider&); 00125 00129 void _notify_thread(void); 00130 00134 bool _event_has_changed(void); 00135 00139 void _update_event(void); 00140 00147 void _callback(int file_descriptor, short events); 00148 00149 bool _in_check_queue; 00150 bool _need_start; 00151 bool _need_run; 00152 bool _need_stop; 00153 bool _is_processing; 00154 bool _is_set; 00155 bool _is_added; 00156 bool _watch_read; 00157 bool _set_watch_read; 00158 bool _watch_write; 00159 bool _set_watch_write; 00160 int _file_descriptor; 00161 int _set_file_descriptor; 00162 thread& _thread; 00163 uint64_t _expire_time; 00164 uint64_t _set_expire_time; 00165 struct event _event; 00166 struct timeval _timer; 00167 00168 friend void handler_provider_callback(int file_descriptor, 00169 short events, 00170 void* context); 00171 }; 00172 00173 } /* namespace libevent */ 00174 } /* namespace event */ 00175 } /* namespace scalestack */ 00176 00177 #endif /* SCALESTACK_EVENT_LIBEVENT_HANDLER_PROVIDER_H */
1.6.3