SAGA Adaptor CPI v.1.0
|
00001 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00002 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/server.cpp") 00003 #endif 00004 // Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) 00005 // Copyright (c) 2005-2009 Hartmut Kaiser 00006 // 00007 // Use, modification and distribution is subject to the Boost Software 00008 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 00009 // http://www.boost.org/LICENSE_1_0.txt) 00010 00011 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00012 #pragma wave option(preserve: 0, output: null) 00013 #endif 00014 00015 // this is needed in every file including detail/monitorable_impl.hpp and not 00016 // belonging to the engine 00017 #define SAGA_NO_IMPORT_MONITORABLE 00018 #define SAGA_NO_IMPORT_PERMISSIONS 00019 00020 // include the package we implement 00021 #include <saga/saga/context.hpp> 00022 #include <saga/saga/stream.hpp> 00023 #include <saga/impl/stream.hpp> 00024 #include <saga/saga/detail/call.hpp> 00025 00026 #include <saga/saga/detail/monitorable_impl.hpp> 00027 #include <saga/saga/detail/permissions_impl.hpp> 00028 00029 #ifdef SAGA_DEBUG 00030 #include <saga/saga/packages/stream/preprocessed/server.cpp> 00031 #else 00032 00033 #if defined(__WAVE__) && defined(SAGA_CREATE_PREPROCESSED_FILES) 00034 #pragma wave option(preserve: 2, line: 1, output: "preprocessed/server.cpp") 00035 #endif 00036 00037 namespace saga 00038 { 00039 namespace stream { 00041 namespace metrics 00042 { 00044 saga::metrics::init_data const server_metric_data[] = 00045 { 00046 { 00047 saga::stream::metrics::server_clientconnect, 00048 "Metric fires if if a client connects.", 00049 saga::attributes::metric_mode_readonly, 00050 "1", 00051 saga::attributes::metric_type_trigger, 00052 "0" 00053 } 00054 }; 00056 } 00057 00058 00059 server::server (session const& s, saga::url url) 00060 : saga::object (new saga::impl::server (s, url)) 00061 { 00062 init_metrics(); 00063 this->saga::object::get_impl()->init(); 00064 } 00065 00066 server::server (saga::url url) 00067 : saga::object (new saga::impl::server (detail::get_the_session(), url)) 00068 { 00069 init_metrics(); 00070 this->saga::object::get_impl()->init(); 00071 } 00072 00073 server::server (void) 00074 : saga::object (new saga::impl::server (detail::get_the_session(), saga::url())) 00075 { 00076 init_metrics(); 00077 this->saga::object::get_impl()->init(); 00078 } 00079 00080 server::server (saga::impl::server* impl) 00081 : saga::object (impl) 00082 { 00083 init_metrics(); 00084 } 00085 00086 server::server (int) 00087 { 00088 } 00089 00090 void server::init_metrics() 00091 { 00092 // initialize metrics 00093 std::vector<saga::metric> metrics; 00094 for (unsigned int i = 0; 00095 i < sizeof(saga::stream::metrics::server_metric_data)/sizeof(saga::metrics::init_data); 00096 ++i) 00097 { 00098 saga::metrics::init_data const* p = &metrics::server_metric_data[i]; 00099 saga::metric m(*this, p->name, p->description, p->mode, p->unit, 00100 p->type, p->value); 00101 metrics.push_back(m); 00102 } 00103 this->monitorable_base_type::init (metrics); 00104 } 00105 00106 server::~server (void) 00107 { 00108 } 00109 00110 saga::impl::server* server::get_impl() const 00111 { 00112 typedef saga::object base_type; 00113 return static_cast<saga::impl::server*>(this->base_type::get_impl()); 00114 } 00115 00116 TR1::shared_ptr <saga::impl::server> server::get_impl_sp(void) const 00117 { 00118 // FIXME: this needs documentation 00119 typedef saga::object base_type; 00120 return TR1::static_pointer_cast <saga::impl::server>( 00121 this->base_type::get_impl_sp()); 00122 } 00123 00125 server::server (saga::object const& o) 00126 : saga::object (o) 00127 { 00128 if (this->get_type() != saga::object::StreamServer) 00129 { 00130 SAGA_THROW("Bad type conversion.", saga::BadParameter); 00131 } 00132 } 00133 00134 server &server::operator= (saga::object const& o) 00135 { 00136 return saga::object::operator=(o), *this; 00137 } 00138 00139 // factory 00140 SAGA_CALL_CREATE_IMP_2(server, impl::server, session const&, saga::url) 00141 00142 // server methods 00143 SAGA_CALL_IMP_1(server, connect, double) 00144 SAGA_CALL_IMP_1(server, serve, double) 00145 SAGA_CALL_CONST_IMP_0(server, get_url) 00146 SAGA_CALL_IMP_1(server, close, double) 00147 00148 } // namespace saga 00149 00150 namespace detail 00151 { 00153 // implement the monitorable functions (we need to explicitly specialize 00154 // the template because the functions are not implemented inline) 00155 template struct SAGA_STREAM_PACKAGE_EXPORT saga::detail::monitorable<stream::server>; 00156 00158 // implement the permissions functions (we need to explicitly specialize 00159 // the template because the functions are not implemented inline) 00160 template struct SAGA_STREAM_PACKAGE_EXPORT permissions<stream::server>; 00161 00162 template struct SAGA_STREAM_PACKAGE_EXPORT permissions_priv<stream::server, task_base::Sync>; 00163 template struct SAGA_STREAM_PACKAGE_EXPORT permissions_priv<stream::server, task_base::Async>; 00164 template struct SAGA_STREAM_PACKAGE_EXPORT permissions_priv<stream::server, task_base::Task>; 00165 } 00166 00168 } 00169 #endif // SAGA_DEBUG 00170