/services/ChannelSubscriber.cpp

https://github.com/starcasters/lisanna · C++ · 185 lines · 105 code · 37 blank · 43 comment · 30 complexity · 6223f5439acfcfd2ba6e90357317084f MD5 · raw file

  1. /*
  2. This file is part of Lisana.
  3. Lisana is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. Lisana is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Lisana. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // ChannelSubscriber
  15. // bnet.protocol.channel.ChannelSubscriber
  16. //
  17. // { NotifyAdd .bnet.protocol.channel.AddNotification .bnet.protocol.NO_RESPONSE }
  18. // { NotifyJoin .bnet.protocol.channel.JoinNotification .bnet.protocol.NO_RESPONSE }
  19. // { NotifyRemove .bnet.protocol.channel.RemoveNotification .bnet.protocol.NO_RESPONSE }
  20. // { NotifyLeave .bnet.protocol.channel.LeaveNotification .bnet.protocol.NO_RESPONSE }
  21. // { NotifySendMessage .bnet.protocol.channel.SendMessageNotification .bnet.protocol.NO_RESPONSE }
  22. // { NotifyUpdateChannelState .bnet.protocol.channel.UpdateChannelStateNotification .bnet.protocol.NO_RESPONSE }
  23. // { NotifyUpdateMemberState .bnet.protocol.channel.UpdateMemberStateNotification .bnet.protocol.NO_RESPONSE }
  24. #include "ChannelSubscriber.h"
  25. #include <iostream>
  26. using namespace google::protobuf;
  27. CServiceChannelSubscriber::CServiceChannelSubscriber()
  28. {
  29. // place here any initialization (?)
  30. }
  31. CServiceChannelSubscriber::CServiceChannelSubscriber(CServiceMgr* owner=0,int SID=0, std::string serviceName=string(SERVICE_ChannelSubscriber_NAME)) :
  32. CService(owner, SID, serviceName)
  33. {
  34. //what goes here now?
  35. }
  36. Message* CServiceChannelSubscriber::GetMethodMessage(int MethodID, bool request) {
  37. switch (MethodID) {
  38. case 1:
  39. if (request) { return ::bnet::protocol::channel::AddNotification::default_instance().New(); }
  40. else { cerr << "error: method has no response data" << endl; }
  41. case 2:
  42. if (request) { return ::bnet::protocol::channel::JoinNotification::default_instance().New(); }
  43. else { cerr << "error: method has no response data" << endl; }
  44. case 3:
  45. if (request) { return ::bnet::protocol::channel::RemoveNotification::default_instance().New(); }
  46. else { cerr << "error: method has no response data" << endl; }
  47. case 4:
  48. if (request) { return ::bnet::protocol::channel::LeaveNotification::default_instance().New(); }
  49. else { cerr << "error: method has no response data" << endl; }
  50. case 5:
  51. if (request) { return ::bnet::protocol::channel::SendMessageNotification::default_instance().New(); }
  52. else { cerr << "error: method has no response data" << endl; }
  53. case 6:
  54. if (request) { return ::bnet::protocol::channel::UpdateChannelStateNotification::default_instance().New(); }
  55. else { cerr << "error: method has no response data" << endl; }
  56. case 7:
  57. if (request) { return ::bnet::protocol::channel::UpdateMemberStateNotification::default_instance().New(); }
  58. else { cerr << "error: method has no response data" << endl; }
  59. default:
  60. cerr << "error: method not implemented" << endl;
  61. return NULL;
  62. }
  63. }
  64. //This function was autogenerated:
  65. bool CServiceChannelSubscriber::DispatchMethod(int MethodID, bool request, TCPSocket *sock, apacket* packet) {
  66. switch (MethodID) {
  67. case 1:
  68. if (request) { return handle_NotifyAdd_Request(sock, packet); }
  69. else {cerr << "error: method has no response data" << endl; }
  70. case 2:
  71. if (request) { return handle_NotifyJoin_Request(sock, packet); }
  72. else {cerr << "error: method has no response data" << endl; }
  73. case 3:
  74. if (request) { return handle_NotifyRemove_Request(sock, packet); }
  75. else {cerr << "error: method has no response data" << endl; }
  76. case 4:
  77. if (request) { return handle_NotifyLeave_Request(sock, packet); }
  78. else {cerr << "error: method has no response data" << endl; }
  79. case 5:
  80. if (request) { return handle_NotifySendMessage_Request(sock, packet); }
  81. else {cerr << "error: method has no response data" << endl; }
  82. case 6:
  83. if (request) { return handle_NotifyUpdateChannelState_Request(sock, packet); }
  84. else {cerr << "error: method has no response data" << endl; }
  85. case 7:
  86. if (request) { return handle_NotifyUpdateMemberState_Request(sock, packet); }
  87. else {cerr << "error: method has no response data" << endl; }
  88. default:
  89. cerr << "error: method not implemented" << endl;
  90. return false;
  91. }
  92. }
  93. bool CServiceChannelSubscriber::handle_NotifyAdd_Request(TCPSocket *sock, apacket* packet)
  94. {
  95. ::bnet::protocol::channel::AddNotification* request;
  96. //this packet has no response asociated.
  97. // do something...
  98. return true;
  99. }
  100. bool CServiceChannelSubscriber::handle_NotifyJoin_Request(TCPSocket *sock, apacket* packet)
  101. {
  102. ::bnet::protocol::channel::JoinNotification* request;
  103. //this packet has no response asociated.
  104. // do something...
  105. return true;
  106. }
  107. bool CServiceChannelSubscriber::handle_NotifyRemove_Request(TCPSocket *sock, apacket* packet)
  108. {
  109. ::bnet::protocol::channel::RemoveNotification* request;
  110. //this packet has no response asociated.
  111. // do something...
  112. return true;
  113. }
  114. bool CServiceChannelSubscriber::handle_NotifyLeave_Request(TCPSocket *sock, apacket* packet)
  115. {
  116. ::bnet::protocol::channel::LeaveNotification* request;
  117. //this packet has no response asociated.
  118. // do something...
  119. return true;
  120. }
  121. bool CServiceChannelSubscriber::handle_NotifySendMessage_Request(TCPSocket *sock, apacket* packet)
  122. {
  123. ::bnet::protocol::channel::SendMessageNotification* request;
  124. //this packet has no response asociated.
  125. // do something...
  126. return true;
  127. }
  128. bool CServiceChannelSubscriber::handle_NotifyUpdateChannelState_Request(TCPSocket *sock, apacket* packet)
  129. {
  130. ::bnet::protocol::channel::UpdateChannelStateNotification* request;
  131. //this packet has no response asociated.
  132. // do something...
  133. return true;
  134. }
  135. bool CServiceChannelSubscriber::handle_NotifyUpdateMemberState_Request(TCPSocket *sock, apacket* packet)
  136. {
  137. ::bnet::protocol::channel::UpdateMemberStateNotification* request;
  138. //this packet has no response asociated.
  139. // do something...
  140. return true;
  141. }
  142. CServiceChannelSubscriber::~CServiceChannelSubscriber(void)
  143. {
  144. std::cout << "Bye from authserv.";
  145. }