SipEvent.cxx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #include "SipEvent.h"
  23. #include "SipSession.h"
  24. #include "SipMessage.h"
  25. #include "SipStack.h"
  26. #define takeOwnership_Implement(cls, name, session) \
  27. name##Session* cls##Event::take##session##Ownership() const \
  28. { \
  29. if(this->sipevent && this->sipevent->ss /*&& !tsip_ssession_have_ownership(this->sipevent->ss)*/){ \
  30. SipStack* stack = this->getStack(); \
  31. if(stack){ \
  32. /* The constructor will call take_ownerhip() */ \
  33. return new name##Session(stack, this->sipevent->ss); \
  34. } \
  35. } \
  36. return tsk_null; \
  37. } \
  38. /* ======================== SipEvent ========================*/
  39. SipEvent::SipEvent(const tsip_event_t *_sipevent)
  40. {
  41. this->sipevent = _sipevent;
  42. if(_sipevent) {
  43. this->sipmessage = new SipMessage(_sipevent->sipmessage);
  44. }
  45. else {
  46. this->sipmessage = tsk_null;
  47. }
  48. }
  49. SipEvent::~SipEvent()
  50. {
  51. if(this->sipmessage) {
  52. delete this->sipmessage;
  53. }
  54. }
  55. short SipEvent::getCode() const
  56. {
  57. return this->sipevent->code;
  58. }
  59. const char* SipEvent::getPhrase() const
  60. {
  61. return this->sipevent->phrase;
  62. }
  63. const SipSession* SipEvent::getBaseSession() const
  64. {
  65. const void* userdata = tsip_ssession_get_userdata(this->sipevent->ss);
  66. if(userdata) {
  67. return dyn_cast<const SipSession*>((const SipSession*)userdata);
  68. }
  69. return tsk_null;
  70. }
  71. const SipMessage* SipEvent::getSipMessage() const
  72. {
  73. return this->sipmessage;
  74. }
  75. SipStack* SipEvent::getStack()const
  76. {
  77. const tsip_stack_handle_t* stack_handle = tsip_ssession_get_stack(sipevent->ss);
  78. const void* userdata;
  79. if(stack_handle && (userdata = tsip_stack_get_userdata(stack_handle))) {
  80. return dyn_cast<SipStack*>((SipStack*)userdata);
  81. }
  82. return tsk_null;
  83. }
  84. /* ======================== DialogEvent ========================*/
  85. DialogEvent::DialogEvent(const tsip_event_t *_sipevent)
  86. :SipEvent(_sipevent) { }
  87. DialogEvent::~DialogEvent() { }
  88. /* ======================== DialogEvent ========================*/
  89. StackEvent::StackEvent(const tsip_event_t *_sipevent)
  90. :SipEvent(_sipevent) { }
  91. StackEvent::~StackEvent() { }
  92. /* ======================== InviteEvent ========================*/
  93. InviteEvent::InviteEvent(const tsip_event_t *_sipevent)
  94. :SipEvent(_sipevent)
  95. {
  96. }
  97. InviteEvent::~InviteEvent()
  98. {
  99. }
  100. tsip_invite_event_type_t InviteEvent::getType() const
  101. {
  102. return TSIP_INVITE_EVENT(this->sipevent)->type;
  103. }
  104. twrap_media_type_t InviteEvent::getMediaType() const
  105. {
  106. // Ignore Mixed session (both audio/video and MSRP) as specified by GSMA RCS.
  107. if (this->sipevent && this->sipevent->ss) {
  108. tmedia_type_t type = tsip_ssession_get_mediatype(this->sipevent->ss);
  109. if ((type & tmedia_msrp) == tmedia_msrp) {
  110. return twrap_media_msrp;
  111. }
  112. else {
  113. return twrap_get_wrapped_media_type(type);
  114. }
  115. }
  116. return twrap_media_none;
  117. }
  118. const InviteSession* InviteEvent::getSession() const
  119. {
  120. return dyn_cast<const InviteSession*>(this->getBaseSession());
  121. }
  122. takeOwnership_Implement(Invite, Call, CallSession);
  123. takeOwnership_Implement(Invite, Msrp, MsrpSession);
  124. /* ======================== MessagingEvent ========================*/
  125. MessagingEvent::MessagingEvent(const tsip_event_t *_sipevent)
  126. :SipEvent(_sipevent)
  127. {
  128. }
  129. MessagingEvent::~MessagingEvent()
  130. {
  131. }
  132. tsip_message_event_type_t MessagingEvent::getType() const
  133. {
  134. return TSIP_MESSAGE_EVENT(this->sipevent)->type;
  135. }
  136. const MessagingSession* MessagingEvent::getSession() const
  137. {
  138. return dyn_cast<const MessagingSession*>(this->getBaseSession());
  139. }
  140. takeOwnership_Implement(Messaging, Messaging, Session);
  141. /* ======================== InfoEvent ========================*/
  142. InfoEvent::InfoEvent(const tsip_event_t *_sipevent)
  143. :SipEvent(_sipevent)
  144. {
  145. }
  146. InfoEvent::~InfoEvent()
  147. {
  148. }
  149. tsip_info_event_type_t InfoEvent::getType() const
  150. {
  151. return TSIP_INFO_EVENT(this->sipevent)->type;
  152. }
  153. const InfoSession* InfoEvent::getSession() const
  154. {
  155. return dyn_cast<const InfoSession*>(this->getBaseSession());
  156. }
  157. takeOwnership_Implement(Info, Info, Session);
  158. /* ======================== OptionsEvent ========================*/
  159. OptionsEvent::OptionsEvent(const tsip_event_t *_sipevent)
  160. :SipEvent(_sipevent)
  161. {
  162. }
  163. OptionsEvent::~OptionsEvent()
  164. {
  165. }
  166. tsip_options_event_type_t OptionsEvent::getType() const
  167. {
  168. return TSIP_OPTIONS_EVENT(this->sipevent)->type;
  169. }
  170. const OptionsSession* OptionsEvent::getSession() const
  171. {
  172. return dyn_cast<const OptionsSession*>(this->getBaseSession());
  173. }
  174. takeOwnership_Implement(Options, Options, Session);
  175. /* ======================== PublicationEvent ========================*/
  176. PublicationEvent::PublicationEvent(const tsip_event_t *_sipevent)
  177. :SipEvent(_sipevent)
  178. {
  179. }
  180. PublicationEvent::~PublicationEvent()
  181. {
  182. }
  183. tsip_publish_event_type_t PublicationEvent::getType() const
  184. {
  185. return TSIP_PUBLISH_EVENT(this->sipevent)->type;
  186. }
  187. const PublicationSession* PublicationEvent::getSession() const
  188. {
  189. return dyn_cast<const PublicationSession*>(this->getBaseSession());
  190. }
  191. takeOwnership_Implement(Publication, Publication, Session);
  192. /* ======================== RegistrationEvent ========================*/
  193. RegistrationEvent::RegistrationEvent(const tsip_event_t *_sipevent)
  194. :SipEvent(_sipevent)
  195. {
  196. }
  197. RegistrationEvent::~RegistrationEvent()
  198. {
  199. }
  200. tsip_register_event_type_t RegistrationEvent::getType() const
  201. {
  202. return TSIP_REGISTER_EVENT(this->sipevent)->type;
  203. }
  204. const RegistrationSession* RegistrationEvent::getSession() const
  205. {
  206. return dyn_cast<const RegistrationSession*>(this->getBaseSession());
  207. }
  208. takeOwnership_Implement(Registration, Registration, Session);
  209. /* ======================== SubscriptionEvent ========================*/
  210. SubscriptionEvent::SubscriptionEvent(const tsip_event_t *sipevent)
  211. :SipEvent(sipevent)
  212. {
  213. }
  214. SubscriptionEvent::~SubscriptionEvent()
  215. {
  216. }
  217. tsip_subscribe_event_type_t SubscriptionEvent::getType() const
  218. {
  219. return TSIP_SUBSCRIBE_EVENT(this->sipevent)->type;
  220. }
  221. const SubscriptionSession* SubscriptionEvent::getSession() const
  222. {
  223. return dyn_cast<const SubscriptionSession*>(this->getBaseSession());
  224. }
  225. takeOwnership_Implement(Subscription, Subscription, Session);