00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SAGA_COMM_STREAM_STREAMSERVICE_HPP
00010 #define SAGA_COMM_STREAM_STREAMSERVICE_HPP
00011
00012
00013 #include <string>
00014
00015
00016 #include <saga/saga/util.hpp>
00017 #include <saga/saga/call.hpp>
00018 #include <saga/saga/base.hpp>
00019 #include <saga/saga/task.hpp>
00020 #include <saga/saga/session.hpp>
00021 #include <saga/saga/detail/monitorable.hpp>
00022 #include <saga/saga/detail/permissions.hpp>
00023
00024
00025 #include <saga/saga/packages/stream/config.hpp>
00026
00027
00028 #include <saga/saga/stream.hpp>
00029
00030
00031 #if defined(BOOST_MSVC)
00032 #pragma warning(push)
00033 #pragma warning(disable: 4251 4231 4660)
00034 #endif
00035
00037 namespace saga
00038 {
00039 namespace stream {
00040
00041 namespace metrics
00042 {
00043 char const* const server_clientconnect = "server.ClientConnect";
00044 }
00045
00052 class SAGA_STREAM_PACKAGE_EXPORT server
00053 : public saga::object,
00054 public saga::detail::monitorable<server>,
00055 public saga::detail::permissions<server>
00056 {
00058
00059 friend struct saga::detail::monitorable<server>;
00060 friend struct saga::detail::permissions<server>;
00061 typedef saga::detail::monitorable<server> monitorable_base_type;
00063
00064 protected:
00066
00067 TR1::shared_ptr <saga::impl::server> get_impl_sp(void) const;
00068 saga::impl::server* get_impl (void) const;
00069 friend class saga::impl::server;
00070 friend struct saga::detail::create_default<server>;
00071
00072 explicit server (saga::impl::server* impl);
00073 explicit server (int);
00075
00076 private:
00077
00078 SAGA_CALL_CREATE_PRIV_2(session const&, saga::url)
00079
00080
00081 SAGA_CALL_CONST_PRIV_0(get_url)
00082 SAGA_CALL_PRIV_1(serve, double)
00083 SAGA_CALL_PRIV_1(close, double)
00084
00085 void init_metrics();
00086
00087 public:
00092 explicit server (session const& s, saga::url url = saga::url());
00093
00098 explicit server (saga::url url);
00099
00104 server ();
00105
00110 explicit server (saga::object const& o);
00111
00116 ~server (void);
00117
00121 static server create(session const& s, saga::url name = saga::url())
00122 {
00123 return server(s, name);
00124 }
00126 SAGA_CALL_CREATE_2_DEF_1(session const&, saga::url, saga::url())
00128
00131 static server create(saga::url name = saga::url())
00132 {
00133 return server(name);
00134 }
00135 template <typename Tag>
00136 static saga::task create(saga::url name = saga::url())
00137 {
00138 return create<Tag>(detail::get_the_session(), name);
00139 }
00140
00145 server &operator= (saga::object const& o);
00146
00153 saga::url get_url() const
00154 {
00155 saga::task t = get_urlpriv(saga::task_base::Sync());
00156 return t.get_result<saga::url>();
00157 }
00158 SAGA_CALL_CONST_PUB_0_DEF_0(get_url)
00159
00160
00167 saga::stream::stream serve(double timeout = 0.0)
00168 {
00169 saga::task t = servepriv(timeout, saga::task_base::Sync());
00170 return t.get_result<saga::stream::stream>();
00171 }
00172 SAGA_CALL_PUB_1_DEF_1(serve, double, -1.0)
00173
00174
00179 void close(double timeout = 0.0)
00180 {
00181 saga::task t = closepriv(timeout, saga::task_base::Sync());
00182 t.get_result ();
00183 }
00184 SAGA_CALL_PUB_1_DEF_1(close, double, 0.0)
00185 };
00186
00187 }
00188
00189 namespace detail
00190 {
00191
00192
00193
00194 template<>
00195 struct create_default<saga::stream::server>
00196 {
00197 static saga::stream::server* call()
00198 {
00199 return new saga::stream::server(1);
00200 }
00201 template <typename T_> static void call(T_* obj)
00202 {
00203 new (obj) saga::stream::server(1);
00204 }
00205 };
00206 }
00207
00208 }
00209
00210
00211 #if defined(BOOST_MSVC)
00212 #pragma warning(pop)
00213 #endif
00214
00215 #endif // SAGA_COMM_STREAM_STREAMSERVICE_HPP
00216