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_NETWORK_STREAM_SERVICE_H 00025 #define SCALESTACK_NETWORK_STREAM_SERVICE_H 00026 00027 #include <memory> 00028 #include <sys/socket.h> 00029 #include <sys/types.h> 00030 00031 #include <scalestack/event/handler_service.h> 00032 #include <scalestack/kernel/service.h> 00033 00034 namespace scalestack 00035 { 00036 namespace network 00037 { 00038 00039 class stream; 00040 00044 class stream_service: public kernel::service 00045 { 00046 public: 00047 00048 stream_service(kernel::module& module); 00049 00050 virtual ~stream_service(); 00051 00057 virtual network::stream* add_stream(void) = 0; 00058 00059 private: 00060 00064 stream_service(const stream_service&); 00065 00069 stream_service& operator=(const stream_service&); 00070 }; 00071 00075 class stream_service_provider: public kernel::service 00076 { 00077 public: 00078 00079 stream_service_provider(kernel::module& module, 00080 std::auto_ptr<stream_service> stream_service); 00081 00082 virtual ~stream_service_provider(); 00083 00091 virtual void add_accepted(int file_descriptor, 00092 struct sockaddr& peer, 00093 socklen_t peer_size) = 0; 00094 00095 protected: 00096 00097 std::auto_ptr<stream_service> _stream_service; 00098 event::handler_service _handler_service; 00099 00100 private: 00101 00105 stream_service_provider(const stream_service_provider&); 00106 00110 stream_service_provider& operator=(const stream_service_provider&); 00111 }; 00112 00113 /* 00114 * Public stream_service methods. 00115 */ 00116 00117 inline stream_service::stream_service(kernel::module& module): 00118 kernel::service(module) 00119 { 00120 } 00121 00122 inline stream_service::~stream_service() 00123 { 00124 } 00125 00126 /* 00127 * Public stream_service_provider methods. 00128 */ 00129 00130 inline stream_service_provider::stream_service_provider(kernel::module& module, 00131 std::auto_ptr<stream_service> stream_service): 00132 kernel::service(module), 00133 _stream_service(stream_service), 00134 _handler_service(module) 00135 { 00136 } 00137 00138 inline stream_service_provider::~stream_service_provider() 00139 { 00140 } 00141 00142 } /* namespace network */ 00143 } /* namespace scalestack */ 00144 00145 #endif /* SCALESTACK_NETWORK_STREAM_SERVICE_H */
1.6.3