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_HANDLER_SERVICE_H 00025 #define SCALESTACK_EVENT_HANDLER_SERVICE_H 00026 00027 #include <set> 00028 00029 #include <scalestack/event/service.h> 00030 #include <scalestack/kernel/macros.h> 00031 #include <scalestack/kernel/service.h> 00032 #include <scalestack/threading/mutex.h> 00033 00034 namespace scalestack 00035 { 00036 namespace event 00037 { 00038 00043 class SCALESTACK_API handler_service: public kernel::service 00044 { 00045 public: 00046 00052 handler_service(kernel::module& module); 00053 00054 ~handler_service(); 00055 00060 void stop(void); 00061 00062 private: 00063 00067 SCALESTACK_LOCAL 00068 handler_service(const handler_service&); 00069 00073 SCALESTACK_LOCAL 00074 handler_service& operator=(const handler_service&); 00075 00079 SCALESTACK_LOCAL 00080 handler_provider* _add_handler(handler* handler); 00081 00087 void _start_handler(handler* handler); 00088 00094 void _stop_handler(handler* handler); 00095 00096 typedef std::set<handler*> handlers; 00097 00098 bool _stop; 00099 size_t _handler_count; 00100 event::service& _service; 00101 int _pipe[2]; 00102 threading::mutex _handler_mutex; 00103 handlers _handlers; 00104 00105 friend class handler; 00106 }; 00107 00108 /* 00109 * Private methods. 00110 */ 00111 00112 inline handler_provider* handler_service::_add_handler(handler* handler) 00113 { 00114 return _service._add_handler(handler); 00115 } 00116 00117 } /* namespace event */ 00118 } /* namespace scalestack */ 00119 00120 #endif /* SCALESTACK_EVENT_HANDLER_SERVICE_H */
1.6.3