rt_SipSession.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
  2. *
  3. * This file is part of Open Source Doubango Framework.
  4. *
  5. * DOUBANGO is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * DOUBANGO is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with DOUBANGO.
  17. */
  18. #pragma once
  19. #include "rt_Config.h"
  20. #include "rt_SipStack.h"
  21. #include "rt_SipUri.h"
  22. #include "rt_String.h"
  23. #include "rt_ActionConfig.h"
  24. #include "rt_MediaSessionMgr.h"
  25. #include "tinysip.h"
  26. class SipSession;
  27. class InviteSession;
  28. class CallSession;
  29. class MsrpSession;
  30. class MessagingSession;
  31. class InfoSession;
  32. class OptionsSession;
  33. class PublicationSession;
  34. class RegistrationSession;
  35. class SubscriptionSession;
  36. class SipStack;
  37. class T140CallbackData;
  38. class T140Callback;
  39. // error C4585: 'doubango_rt::rtSipSession' : A WinRT 'public ref class' must either be sealed or derive from an existing unsealed class
  40. #define rtISession_Declare() \
  41. virtual unsigned getId(); \
  42. virtual bool haveOwnership(); \
  43. virtual bool addHeader(Platform::String^ name, Platform::String^ value); \
  44. virtual bool removeHeader(Platform::String^ name); \
  45. [Windows::Foundation::Metadata::DefaultOverload] \
  46. virtual bool addCaps(Platform::String^ name, Platform::String^ value); \
  47. OVERRIDE_FUNC(virtual bool addCaps(Platform::String^ name);) \
  48. virtual bool removeCaps(Platform::String^ name); \
  49. virtual bool setExpires(unsigned expires); \
  50. OVERRIDE_FUNC(virtual bool setFromUri(Platform::String^ fromUriString);) \
  51. [Windows::Foundation::Metadata::DefaultOverload] \
  52. virtual bool setFromUri(rtSipUri^ fromUri); \
  53. OVERRIDE_FUNC(virtual bool setToUri(Platform::String^ toUriString);) \
  54. [Windows::Foundation::Metadata::DefaultOverload] \
  55. virtual bool setToUri(rtSipUri^ toUri); \
  56. virtual bool setSilentHangup(bool silent); \
  57. virtual bool addSigCompCompartment(Platform::String^ compId); \
  58. virtual bool removeSigCompCompartment(); \
  59. #define rtISession_Implement(cls) \
  60. unsigned cls##::getId(){ \
  61. return m_pSipSession->getId(); \
  62. } \
  63. bool cls##::haveOwnership(){ \
  64. return m_pSipSession->haveOwnership(); \
  65. } \
  66. bool cls##::addHeader(Platform::String^ name, Platform::String^ value){ \
  67. return m_pSipSession->addHeader(rtString::toUtf8(name).data(), rtString::toUtf8(value).data()); \
  68. } \
  69. bool cls##::removeHeader(Platform::String^ name){ \
  70. return m_pSipSession->removeHeader(rtString::toUtf8(name).data()); \
  71. } \
  72. bool cls##::addCaps(Platform::String^ name, Platform::String^ value){ \
  73. return m_pSipSession->addCaps(rtString::toUtf8(name).data(), rtString::toUtf8(value).data()); \
  74. } \
  75. OVERRIDE_FUNC(bool cls##::addCaps(Platform::String^ name){ \
  76. return addCaps(name, nullptr); \
  77. }) \
  78. bool cls##::removeCaps(Platform::String^ name){ \
  79. return m_pSipSession->removeCaps(rtString::toUtf8(name).data()); \
  80. } \
  81. bool cls##::setExpires(unsigned expires){ \
  82. return m_pSipSession->setExpires(expires); \
  83. } \
  84. OVERRIDE_FUNC(bool cls##::setFromUri(Platform::String^ fromUriString){ \
  85. return m_pSipSession->setFromUri(rtString::toUtf8(fromUriString).data()); \
  86. }) \
  87. bool cls##::setFromUri(rtSipUri^ fromUri){ \
  88. return m_pSipSession->setFromUri(fromUri->getWrappedUri()); \
  89. } \
  90. OVERRIDE_FUNC(bool cls##::setToUri(Platform::String^ toUriString){ \
  91. return m_pSipSession->setToUri(rtString::toUtf8(toUriString).data()); \
  92. }) \
  93. bool cls##::setToUri(rtSipUri^ toUri){ \
  94. return m_pSipSession->setToUri(toUri->getWrappedUri()); \
  95. } \
  96. bool cls##::setSilentHangup(bool silent){ \
  97. return m_pSipSession->setSilentHangup(silent); \
  98. } \
  99. bool cls##::addSigCompCompartment(Platform::String^ compId){ \
  100. return m_pSipSession->addSigCompCompartment(rtString::toUtf8(compId).data()); \
  101. } \
  102. bool cls##::removeSigCompCompartment(){ \
  103. return m_pSipSession->removeSigCompCompartment(); \
  104. }\
  105. #define rtIInviteSession_Declare() \
  106. [Windows::Foundation::Metadata::DefaultOverload] \
  107. virtual bool accept(rtActionConfig^ config); \
  108. OVERRIDE_FUNC(virtual bool accept();) \
  109. [Windows::Foundation::Metadata::DefaultOverload] \
  110. virtual bool hangup(rtActionConfig^ config); \
  111. OVERRIDE_FUNC(virtual bool hangup();) \
  112. [Windows::Foundation::Metadata::DefaultOverload] \
  113. virtual bool reject(rtActionConfig^ config); \
  114. OVERRIDE_FUNC(virtual bool reject();) \
  115. [Windows::Foundation::Metadata::DefaultOverload] \
  116. virtual bool sendInfo(VISIBLE_VOID_PTR payload, unsigned len, rtActionConfig^ config); \
  117. OVERRIDE_FUNC(virtual bool sendInfo(VISIBLE_VOID_PTR payload, unsigned len);) \
  118. virtual rtMediaSessionMgr^ getMediaMgr(); \
  119. #define rtIInviteSession_Implement(cls) \
  120. bool cls##::accept(rtActionConfig^ config){ \
  121. return m_pSipSession->accept(config ? config->getWrappedActionConfig() : tsk_null); \
  122. } \
  123. OVERRIDE_FUNC(bool cls##::accept(){ \
  124. return accept(nullptr); \
  125. }) \
  126. bool cls##::hangup(rtActionConfig^ config){ \
  127. return m_pSipSession->hangup(config ? config->getWrappedActionConfig() : tsk_null); \
  128. } \
  129. OVERRIDE_FUNC(bool cls##::hangup(){ \
  130. return hangup(nullptr); \
  131. }) \
  132. bool cls##::reject(rtActionConfig^ config){ \
  133. return m_pSipSession->reject(config ? config->getWrappedActionConfig() : tsk_null); \
  134. } \
  135. OVERRIDE_FUNC(bool cls##::reject(){ \
  136. return reject(nullptr); \
  137. }) \
  138. bool cls##::sendInfo(VISIBLE_VOID_PTR payload, unsigned len, rtActionConfig^ config){ \
  139. return m_pSipSession->sendInfo(VISIBLE_VOID_PTR_2_VOID_PTR(payload), len, config ? config->getWrappedActionConfig() : tsk_null); \
  140. } \
  141. OVERRIDE_FUNC(bool cls##::sendInfo(VISIBLE_VOID_PTR payload, unsigned len){ \
  142. return sendInfo(payload, len, nullptr); \
  143. }) \
  144. rtMediaSessionMgr^ cls##::getMediaMgr(){ \
  145. if(m_pSipSession->getMediaMgr()){ \
  146. return ref new rtMediaSessionMgr(const_cast<struct tmedia_session_mgr_s*>(m_pSipSession->getMediaMgr()->getWrappedMgr())); \
  147. } \
  148. return nullptr; \
  149. } \
  150. namespace doubango_rt
  151. {
  152. namespace BackEnd
  153. {
  154. ref class rtMsrpCallback;
  155. interface class rtIMsrpCallback;
  156. /* ======================== rtT140CallbackData ========================*/
  157. public ref class rtT140CallbackData sealed
  158. {
  159. internal:
  160. rtT140CallbackData(enum tmedia_t140_data_type_e data_type, const void* data_ptr, unsigned data_size);
  161. public:
  162. virtual ~rtT140CallbackData();
  163. private:
  164. T140CallbackData* m_pData;
  165. };
  166. /* ======================== rtT140Callback ========================*/
  167. public interface class rtIT140Callback
  168. {
  169. virtual int ondata(rtT140CallbackData^ pData);
  170. };
  171. public ref class rtT140Callback sealed
  172. {
  173. internal:
  174. rtT140Callback();
  175. const T140Callback* getWrappedCallback() {
  176. return m_pCallback;
  177. }
  178. public:
  179. rtT140Callback(rtIT140Callback^ pI) {
  180. m_pI = pI;
  181. }
  182. virtual ~rtT140Callback();
  183. protected:
  184. virtual int ondata(rtT140CallbackData^ pData) {
  185. if(m_pI) {
  186. return m_pI->ondata(pData);
  187. }
  188. return 0;
  189. }
  190. private:
  191. T140Callback* m_pCallback;
  192. rtIT140Callback^ m_pI;
  193. };
  194. /* ======================== rtISipSession ========================*/
  195. public interface class rtISipSession
  196. {
  197. rtISession_Declare();
  198. };
  199. /* ======================== rtIInviteSession ========================*/
  200. public interface class rtIInviteSession : rtISipSession
  201. {
  202. rtIInviteSession_Declare();
  203. };
  204. /* ======================== rtSipSession ========================*/
  205. public ref class rtSipSession sealed: rtISipSession
  206. {
  207. public:
  208. rtSipSession(rtSipStack^ pStack);
  209. virtual ~rtSipSession();
  210. internal:
  211. rtSipSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  212. SipSession* getWrappedSession() {
  213. return m_pSipSession;
  214. }
  215. public:
  216. rtISession_Declare();
  217. private:
  218. SipSession* m_pSipSession;
  219. };
  220. /* ======================== rtInviteSession ========================*/
  221. public ref class rtInviteSession sealed: rtIInviteSession
  222. {
  223. public:
  224. rtInviteSession(rtSipStack^ pStack);
  225. virtual ~rtInviteSession();
  226. internal:
  227. rtInviteSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  228. InviteSession* getWrappedSession() {
  229. return m_pSipSession;
  230. }
  231. public:
  232. rtISession_Declare();
  233. rtIInviteSession_Declare();
  234. private:
  235. InviteSession* m_pSipSession;
  236. };
  237. /* ======================== CallSession ========================*/
  238. public ref class rtCallSession sealed : rtIInviteSession
  239. {
  240. public:
  241. rtCallSession(rtSipStack^ pStack);
  242. virtual ~rtCallSession();
  243. internal:
  244. rtCallSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  245. CallSession* getWrappedSession() {
  246. return m_pSipSession;
  247. }
  248. public:
  249. rtISession_Declare();
  250. rtIInviteSession_Declare();
  251. [Windows::Foundation::Metadata::DefaultOverload]
  252. bool call(Platform::String^ remoteUriString, rt_twrap_media_type_t media, rtActionConfig^ config);
  253. [Windows::Foundation::Metadata::DefaultOverload]
  254. bool call(Platform::String^ remoteUriString, rt_twrap_media_type_t media);
  255. bool call(rtSipUri^ remoteUri, rt_twrap_media_type_t media, rtActionConfig^ config);
  256. bool call(rtSipUri^ remoteUri, rt_twrap_media_type_t media);
  257. bool setSessionTimer(unsigned timeout, Platform::String^ refresher);
  258. bool set100rel(bool enabled);
  259. bool setRtcp(bool enabled);
  260. bool setRtcpMux(bool enabled);
  261. bool setICE(bool enabled);
  262. bool setQoS(rt_tmedia_qos_stype_t type, rt_tmedia_qos_strength_t strength);
  263. bool setVideoFps(int32_t fps);
  264. bool setVideoBandwidthUploadMax(int32_t max);
  265. bool setVideoBandwidthDownloadMax(int32_t max);
  266. bool setVideoPrefSize(rt_tmedia_pref_video_size_t pref_video_size);
  267. bool hold(rtActionConfig^ config);
  268. bool hold();
  269. bool resume(rtActionConfig^ config);
  270. bool resume();
  271. bool transfer(Platform::String^ referToUriString, rtActionConfig^ config);
  272. bool transfer(Platform::String^ referToUriString);
  273. bool acceptTransfer(rtActionConfig^ config);
  274. bool acceptTransfer();
  275. bool rejectTransfer(rtActionConfig^ config);
  276. bool rejectTransfer();
  277. bool sendDTMF(int number);
  278. unsigned getSessionTransferId();
  279. #if COM_VISIBLE
  280. bool sendT140Data(rt_tmedia_t140_data_type_t data_type, Platform::String^ data);
  281. #else
  282. bool sendT140Data(rt_tmedia_t140_data_type_t data_type, Platform::IntPtr data_ptr, unsigned data_size);
  283. #endif
  284. bool sendT140Data(rt_tmedia_t140_data_type_t data_type);
  285. bool setT140Callback(rtT140Callback^ pT140Callback);
  286. private:
  287. CallSession* m_pSipSession;
  288. };
  289. /* ======================== rtMsrpSession ========================*/
  290. public ref class rtMsrpSession sealed : rtIInviteSession
  291. {
  292. public:
  293. rtMsrpSession(rtSipStack^ pStack, rtIMsrpCallback^ pCallback);
  294. virtual ~rtMsrpSession();
  295. internal:
  296. rtMsrpSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  297. MsrpSession* getWrappedSession() {
  298. return m_pSipSession;
  299. }
  300. public:
  301. rtISession_Declare();
  302. rtIInviteSession_Declare();
  303. bool setCallback(rtIMsrpCallback^ pCallback);
  304. [Windows::Foundation::Metadata::DefaultOverload]
  305. bool callMsrp(Platform::String^ remoteUriString, rtActionConfig^ config);
  306. [Windows::Foundation::Metadata::DefaultOverload]
  307. bool callMsrp(Platform::String^ remoteUriString);
  308. bool callMsrp(rtSipUri^ remoteUri, rtActionConfig^ config);
  309. bool callMsrp(rtSipUri^ remoteUri);
  310. #if COM_VISIBLE
  311. bool sendMessage(Platform::String^ payload, rtActionConfig^ config);
  312. bool sendMessage(Platform::String^ payload);
  313. #else
  314. bool sendMessage(Platform::IntPtr payload, unsigned len, rtActionConfig^ config);
  315. bool sendMessage(Platform::IntPtr payload, unsigned len);
  316. #endif
  317. private:
  318. MsrpSession* m_pSipSession;
  319. rtMsrpCallback^ m_pCallback;
  320. };
  321. /* ======================== rtMessagingSession ========================*/
  322. public ref class rtMessagingSession sealed : rtISipSession
  323. {
  324. internal:
  325. rtMessagingSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  326. public:
  327. rtMessagingSession(rtSipStack^ pStack);
  328. virtual ~rtMessagingSession();
  329. rtISession_Declare();
  330. #if COM_VISIBLE
  331. bool send(Platform::String^ payload, rtActionConfig^ config);
  332. bool send(Platform::String^ payload);
  333. #else
  334. [Windows::Foundation::Metadata::DefaultOverload]
  335. bool send(Platform::IntPtr payload, unsigned len, rtActionConfig^ config);
  336. bool send(Platform::IntPtr payload, unsigned len);
  337. #endif
  338. [Windows::Foundation::Metadata::DefaultOverload]
  339. bool accept(rtActionConfig^ config);
  340. bool accept();
  341. [Windows::Foundation::Metadata::DefaultOverload]
  342. bool reject(rtActionConfig^ config);
  343. bool reject();
  344. private:
  345. MessagingSession* m_pSipSession;
  346. };
  347. /* ======================== rtInfoSession ========================*/
  348. public ref class rtInfoSession sealed : rtISipSession
  349. {
  350. internal:
  351. rtInfoSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  352. public:
  353. rtInfoSession(rtSipStack^ pStack);
  354. virtual ~rtInfoSession();
  355. rtISession_Declare();
  356. #if COM_VISIBLE
  357. bool send(Platform::String^ payload, rtActionConfig^ config);
  358. bool send(Platform::String^ payload);
  359. #else
  360. [Windows::Foundation::Metadata::DefaultOverload]
  361. bool send(Platform::IntPtr payload, unsigned len, rtActionConfig^ config);
  362. bool send(Platform::IntPtr payload, unsigned len);
  363. #endif
  364. [Windows::Foundation::Metadata::DefaultOverload]
  365. bool accept(rtActionConfig^ config);
  366. bool accept();
  367. [Windows::Foundation::Metadata::DefaultOverload]
  368. bool reject(rtActionConfig^ config);
  369. bool reject();
  370. private:
  371. InfoSession* m_pSipSession;
  372. };
  373. /* ======================== rtOptionsSession ========================*/
  374. public ref class rtOptionsSession sealed : rtISipSession
  375. {
  376. internal:
  377. rtOptionsSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  378. public:
  379. rtOptionsSession(rtSipStack^ pStack);
  380. virtual ~rtOptionsSession();
  381. rtISession_Declare();
  382. [Windows::Foundation::Metadata::DefaultOverload]
  383. bool send(rtActionConfig^ config);
  384. bool send();
  385. [Windows::Foundation::Metadata::DefaultOverload]
  386. bool accept(rtActionConfig^ config);
  387. bool accept();
  388. [Windows::Foundation::Metadata::DefaultOverload]
  389. bool reject(rtActionConfig^ config);
  390. bool reject();
  391. private:
  392. OptionsSession* m_pSipSession;
  393. };
  394. /* ======================== rtPublicationSession ========================*/
  395. public ref class rtPublicationSession sealed : rtISipSession
  396. {
  397. internal:
  398. rtPublicationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  399. public:
  400. rtPublicationSession(rtSipStack^ pStack);
  401. virtual ~rtPublicationSession();
  402. rtISession_Declare();
  403. #if COM_VISIBLE
  404. bool publish(Platform::String^ payload, rtActionConfig^ config);
  405. bool publish(Platform::String^ payload);
  406. #else
  407. [Windows::Foundation::Metadata::DefaultOverload]
  408. bool publish(Platform::IntPtr payload, unsigned len, rtActionConfig^ config);
  409. bool publish(Platform::IntPtr payload, unsigned len);
  410. #endif
  411. [Windows::Foundation::Metadata::DefaultOverload]
  412. bool unPublish(rtActionConfig^ config);
  413. bool unPublish();
  414. private:
  415. PublicationSession* m_pSipSession;
  416. };
  417. /* ======================== rtRegistrationSession ========================*/
  418. public ref class rtRegistrationSession sealed : rtISipSession
  419. {
  420. internal:
  421. rtRegistrationSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  422. public:
  423. rtRegistrationSession(rtSipStack^ pStack);
  424. virtual ~rtRegistrationSession();
  425. rtISession_Declare();
  426. bool register_(rtActionConfig^ config);
  427. bool register_();
  428. bool unRegister(rtActionConfig^ config);
  429. bool unRegister();
  430. bool accept(rtActionConfig^ config);
  431. bool accept();
  432. bool reject(rtActionConfig^ config);
  433. bool reject();
  434. private:
  435. RegistrationSession* m_pSipSession;
  436. };
  437. /* ======================== rtSubscriptionSession ========================*/
  438. public ref class rtSubscriptionSession sealed : rtISipSession
  439. {
  440. internal:
  441. rtSubscriptionSession(SipStack* pStack, tsip_ssession_handle_t* pHandle);
  442. public:
  443. rtSubscriptionSession(rtSipStack^ pStack);
  444. virtual ~rtSubscriptionSession();
  445. rtISession_Declare();
  446. bool subscribe();
  447. bool unSubscribe();
  448. private:
  449. SubscriptionSession* m_pSipSession;
  450. };
  451. }
  452. }