/src/maidsafe/rpcprotocol/channel.cc

http://maidsafe-dht.googlecode.com/ · C++ · 157 lines · 100 code · 31 blank · 26 comment · 0 complexity · 22bbaef53b3c0b882873219ba842403e MD5 · raw file

  1. /* Copyright (c) 2009 maidsafe.net limited
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without modification,
  4. are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright notice,
  6. this list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. * Neither the name of the maidsafe.net limited nor the names of its
  11. contributors may be used to endorse or promote products derived from this
  12. software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  17. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  21. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include "maidsafe/rpcprotocol/channelimpl.h"
  25. #include "maidsafe/rpcprotocol/channel-api.h"
  26. #include "maidsafe/transport/transporthandler-api.h"
  27. namespace rpcprotocol {
  28. Controller::Controller() : controller_pimpl_(new ControllerImpl) {}
  29. Controller::~Controller() {}
  30. void Controller::SetFailed(const std::string &str) {
  31. controller_pimpl_->SetFailed(str);
  32. }
  33. void Controller::Reset() {
  34. controller_pimpl_->Reset();
  35. }
  36. bool Controller::Failed() const {
  37. return controller_pimpl_->Failed();
  38. }
  39. std::string Controller::ErrorText() const {
  40. return controller_pimpl_->ErrorText();
  41. }
  42. void Controller::StartCancel() {
  43. controller_pimpl_->StartCancel();
  44. }
  45. bool Controller::IsCanceled() const {
  46. return controller_pimpl_->IsCanceled();
  47. }
  48. void Controller::NotifyOnCancel(google::protobuf::Closure* done) {
  49. controller_pimpl_->NotifyOnCancel(done);
  50. }
  51. void Controller::set_timeout(const boost::uint32_t &seconds) {
  52. controller_pimpl_->set_timeout(seconds);
  53. }
  54. boost::uint64_t Controller::timeout() const {
  55. return controller_pimpl_->timeout();
  56. }
  57. boost::uint64_t Controller::Duration() const {
  58. return controller_pimpl_->Duration();
  59. }
  60. void Controller::StartRpcTimer() {
  61. controller_pimpl_->StartRpcTimer();
  62. }
  63. void Controller::StopRpcTimer() {
  64. controller_pimpl_->StopRpcTimer();
  65. }
  66. void Controller::set_rtt(const float &rtt) {
  67. controller_pimpl_->set_rtt(rtt);
  68. }
  69. float Controller::rtt() const {
  70. return controller_pimpl_->rtt();
  71. }
  72. void Controller::set_transport_id(const boost::int16_t &transport_id) {
  73. controller_pimpl_->set_transport_id(transport_id);
  74. }
  75. boost::int16_t Controller::transport_id() const {
  76. return controller_pimpl_->transport_id();
  77. }
  78. void Controller::set_request_id(const boost::uint32_t &id) {
  79. return controller_pimpl_->set_request_id(id);
  80. }
  81. boost::uint32_t Controller::request_id() const {
  82. return controller_pimpl_->request_id();
  83. }
  84. void Controller::set_message_info(const std::string &service,
  85. const std::string &method) {
  86. controller_pimpl_->set_message_info(service, method);
  87. }
  88. void Controller::message_info(std::string *service, std::string *method) const {
  89. controller_pimpl_->message_info(service, method);
  90. }
  91. Channel::Channel(ChannelManager *channelmanager,
  92. transport::TransportHandler *transport_handler)
  93. : pimpl_(new ChannelImpl(channelmanager, transport_handler)) {}
  94. Channel::Channel(ChannelManager *channelmanager,
  95. transport::TransportHandler *transport_handler,
  96. const boost::int16_t &transport_id,
  97. const std::string &remote_ip,
  98. const boost::uint16_t &remote_port,
  99. const std::string &local_ip,
  100. const boost::uint16_t &local_port,
  101. const std::string &rendezvous_ip,
  102. const boost::uint16_t &rendezvous_port)
  103. : pimpl_(new ChannelImpl(channelmanager, transport_handler, transport_id,
  104. remote_ip, remote_port, local_ip, local_port,
  105. rendezvous_ip, rendezvous_port)) {}
  106. Channel::~Channel() {}
  107. void Channel::CallMethod(const google::protobuf::MethodDescriptor *method,
  108. google::protobuf::RpcController *controller,
  109. const google::protobuf::Message *request,
  110. google::protobuf::Message *response,
  111. google::protobuf::Closure *done) {
  112. pimpl_->CallMethod(method, controller, request, response, done);
  113. }
  114. void Channel::SetService(google::protobuf::Service* service) {
  115. pimpl_->SetService(service);
  116. }
  117. void Channel::HandleRequest(const RpcMessage &request,
  118. const boost::uint32_t &connection_id,
  119. const boost::int16_t &transport_id,
  120. const float &rtt) {
  121. pimpl_->HandleRequest(request, connection_id, transport_id, rtt);
  122. }
  123. } // namespace rpcprotocol