Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SOCROB_MULTICAST_MANAGER_H_
00021 #define _SOCROB_MULTICAST_MANAGER_H_
00022
00023 #include <string>
00024 #include <set>
00025 #include <vector>
00026
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/noncopyable.hpp>
00029
00030 #include <socrob_multicast/definitions.h>
00031 #include <socrob_multicast/compressor.h>
00032
00033
00034
00036 namespace socrob
00037 {
00039 namespace multicast
00040 {
00047 class ManagerOptions
00048 {
00049 public:
00059 ManagerOptions (uint8_t sid,
00060 uint8_t num_sids,
00061 std::string const& multicast_address) :
00062 sid_ (sid),
00063 num_sids_ (num_sids),
00064 multicast_address_ (multicast_address),
00065 bytes_per_second_ (0),
00066 multicast_long_port_ (2000),
00067 multicast_short_port_ (2001),
00068 online_handler_ (empty_id_function),
00069 offline_handler_ (empty_id_function),
00070 long_marshall_ (empty_buffer_function),
00071 long_unmarshall_ (empty_id_buffer_function),
00072 short_handler_ (empty_handler_function),
00073 tup_us_ (100000),
00074 max_lost_ (10),
00075 short_slot_us_ (5000),
00076 short_wait_us_ (1000),
00077 short_max_mine_simultaneous_ (4),
00078 compressor_ (new Compressor()) {}
00079
00088 ManagerOptions& bandwidth_bps (std::size_t bytes_per_second) {
00089 bytes_per_second_ = bytes_per_second;
00090 return *this;
00091 }
00092
00104 ManagerOptions& ports (unsigned short long_port, unsigned short short_port) {
00105 multicast_long_port_ = long_port;
00106 multicast_short_port_ = short_port;
00107 return *this;
00108 }
00109
00120 ManagerOptions& tup_ms (unsigned tup_ms) {
00121 tup_us_ = tup_ms * 1000;
00122 return *this;
00123 }
00124
00135 ManagerOptions& tup_us (unsigned tup_us) {
00136 tup_us_ = tup_us;
00137 return *this;
00138 }
00139
00151 ManagerOptions& max_lost (unsigned max_lost) {
00152 max_lost_ = max_lost;
00153 return *this;
00154 }
00155
00166 ManagerOptions& short_slot_us (unsigned short_slot_us) {
00167 short_slot_us_ = short_slot_us;
00168 return *this;
00169 }
00170
00183 ManagerOptions& short_wait_us (unsigned short_wait_us) {
00184 short_wait_us_ = short_wait_us;
00185 return *this;
00186 }
00187
00201 ManagerOptions& short_max_mine_simultaneous (std::size_t short_max_mine_simultaneous) {
00202 short_max_mine_simultaneous_ = short_max_mine_simultaneous;
00203 return *this;
00204 }
00205
00217 ManagerOptions& compressor (boost::shared_ptr<Compressor> const& compressor) {
00218 compressor_ = compressor;
00219 return *this;
00220 }
00221
00231 ManagerOptions& online_handler (id_function_type const& online_handler) {
00232 online_handler_ = online_handler;
00233 return *this;
00234 }
00235
00245 ManagerOptions& offline_handler (id_function_type const& offline_handler) {
00246 offline_handler_ = offline_handler;
00247 return *this;
00248 }
00249
00261 ManagerOptions& long_marshall (buffer_function_type const& long_marshall) {
00262 long_marshall_ = long_marshall;
00263 return *this;
00264 }
00265
00277 ManagerOptions& long_unmarshall (id_buffer_function_type const& long_unmarshall) {
00278 long_unmarshall_ = long_unmarshall;
00279 return *this;
00280 }
00281
00303 ManagerOptions& short_handler (handler_function_type const& short_handler) {
00304 short_handler_ = short_handler;
00305 return *this;
00306 }
00307
00308 private:
00309 friend class Manager;
00310
00311 uint8_t sid_;
00312 uint8_t num_sids_;
00313 std::string const& multicast_address_;
00314 std::size_t bytes_per_second_;
00315 unsigned short multicast_long_port_;
00316 unsigned short multicast_short_port_;
00317 id_function_type online_handler_;
00318 id_function_type offline_handler_;
00319 buffer_function_type long_marshall_;
00320 id_buffer_function_type long_unmarshall_;
00321 handler_function_type short_handler_;
00322 unsigned tup_us_;
00323 unsigned max_lost_;
00324 unsigned short_slot_us_;
00325 unsigned short_wait_us_;
00326 std::size_t short_max_mine_simultaneous_;
00327 boost::shared_ptr<Compressor> compressor_;
00328 };
00329
00330
00331
00337 class Manager :
00338 private boost::noncopyable
00339 {
00340 public:
00351 Manager (ManagerOptions const& options);
00352
00358 ~Manager();
00359
00371 bool
00372 startShortRound (std::vector<uint8_t> const& question,
00373 std::set<id_type> const& required_sids,
00374 short_callback_type const& callback = empty_short_callback);
00375
00386 bool
00387 startShortRound (std::vector<uint8_t> const& question,
00388 id_type required_sid,
00389 short_callback_type const& callback = empty_short_callback) {
00390 std::set<id_type> required_sids;
00391 required_sids.insert (required_sid);
00392 return startShortRound (question, required_sids, callback);
00393 }
00394
00395 private:
00396 struct implementation;
00397 boost::shared_ptr<implementation> impl_;
00398 };
00399 }
00400 }
00401
00402 #endif