📄 basiccall.cxx
字号:
#include "resip/stack/SdpContents.hxx"#include "resip/stack/SipMessage.hxx"#include "resip/stack/ShutdownMessage.hxx"#include "resip/stack/SipStack.hxx"#include "resip/dum/ClientAuthManager.hxx"#include "resip/dum/ClientInviteSession.hxx"#include "resip/dum/ClientRegistration.hxx"#include "resip/dum/DialogUsageManager.hxx"#include "resip/dum/DumShutdownHandler.hxx"#include "resip/dum/InviteSessionHandler.hxx"#include "resip/dum/MasterProfile.hxx"#include "resip/dum/RegistrationHandler.hxx"#include "resip/dum/ServerInviteSession.hxx"#include "resip/dum/ServerOutOfDialogReq.hxx"#include "resip/dum/OutOfDialogHandler.hxx"#include "resip/dum/AppDialog.hxx"#include "resip/dum/AppDialogSet.hxx"#include "resip/dum/AppDialogSetFactory.hxx"#include "rutil/Log.hxx"#include "rutil/Logger.hxx"#include "rutil/Random.hxx"#include "rutil/WinLeakCheck.hxx"#include <sstream>#include <time.h>#define RESIPROCATE_SUBSYSTEM Subsystem::TEST#define NO_REGISTRATION 1using namespace resip;using namespace std;void sleepSeconds(unsigned int seconds){#ifdef WIN32 Sleep(seconds*1000);#else sleep(seconds);#endif}///////////////////////////////////////////////////////////////////////////////////// Classes that provide the mapping between Application Data and DUM // dialogs/dialogsets// // The DUM layer creates an AppDialog/AppDialogSet object for inbound/outbound// SIP Request that results in Dialog creation.// /////////////////////////////////////////////////////////////////////////////////class testAppDialog : public AppDialog{public: testAppDialog(HandleManager& ham, Data &SampleAppData) : AppDialog(ham), mSampleAppData(SampleAppData) { cout << mSampleAppData << ": testAppDialog: created." << endl; } virtual ~testAppDialog() { cout << mSampleAppData << ": testAppDialog: destroyed." << endl; } Data mSampleAppData;};class testAppDialogSet : public AppDialogSet{public: testAppDialogSet(DialogUsageManager& dum, Data SampleAppData) : AppDialogSet(dum), mSampleAppData(SampleAppData) { cout << mSampleAppData << ": testAppDialogSet: created." << endl; } virtual ~testAppDialogSet() { cout << mSampleAppData << ": testAppDialogSet: destroyed." << endl; } virtual AppDialog* createAppDialog(const SipMessage& msg) { return new testAppDialog(mDum, mSampleAppData); } virtual SharedPtr<UserProfile> selectUASUserProfile(const SipMessage& msg) { cout << mSampleAppData << ": testAppDialogSet: UAS UserProfile requested for msg: " << msg.brief() << endl; return mDum.getMasterUserProfile(); } Data mSampleAppData;};class testAppDialogSetFactory : public AppDialogSetFactory{public: virtual AppDialogSet* createAppDialogSet(DialogUsageManager& dum, const SipMessage& msg) { return new testAppDialogSet(dum, Data("UAS") + Data("(") + getMethodName(msg.header(h_RequestLine).getMethod()) + Data(")")); } // For a UAS the testAppDialogSet will be created by DUM using this function. If you want to set // Application Data, then one approach is to wait for onNewSession(ServerInviteSessionHandle ...) // to be called, then use the ServerInviteSessionHandle to get at the AppDialogSet or AppDialog, // then cast to your derived class and set the desired application data.};// Generic InviteSessionHandlerclass TestInviteSessionHandler : public InviteSessionHandler, public ClientRegistrationHandler, public OutOfDialogHandler{ public: Data name; bool registered; ClientRegistrationHandle registerHandle; TestInviteSessionHandler(const Data& n) : name(n), registered(false) { } virtual ~TestInviteSessionHandler() { } virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response) { registerHandle = h; assert(registerHandle.isValid()); cout << name << ": ClientRegistration-onSuccess - " << response.brief() << endl; registered = true; } virtual void onFailure(ClientRegistrationHandle, const SipMessage& msg) { cout << name << ": ClientRegistration-onFailure - " << msg.brief() << endl; throw; // Ungracefully end } virtual void onRemoved(ClientRegistrationHandle, const SipMessage& response) { cout << name << ": ClientRegistration-onRemoved" << endl; } virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response) { cout << name << ": ClientRegistration-onRequestRetry (" << retrySeconds << ") - " << response.brief() << endl; return -1; } virtual void onNewSession(ClientInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg) { cout << name << ": ClientInviteSession-onNewSession - " << msg.brief() << endl; } virtual void onNewSession(ServerInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg) { cout << name << ": ServerInviteSession-onNewSession - " << msg.brief() << endl; } virtual void onFailure(ClientInviteSessionHandle, const SipMessage& msg) { cout << name << ": ClientInviteSession-onFailure - " << msg.brief() << endl; } virtual void onProvisional(ClientInviteSessionHandle, const SipMessage& msg) { cout << name << ": ClientInviteSession-onProvisional - " << msg.brief() << endl; } virtual void onConnected(ClientInviteSessionHandle, const SipMessage& msg) { cout << name << ": ClientInviteSession-onConnected - " << msg.brief() << endl; } virtual void onStaleCallTimeout(ClientInviteSessionHandle handle) { cout << name << ": ClientInviteSession-onStaleCallTimeout" << endl; } virtual void onConnected(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onConnected - " << msg.brief() << endl; } virtual void onRedirected(ClientInviteSessionHandle, const SipMessage& msg) { cout << name << ": ClientInviteSession-onRedirected - " << msg.brief() << endl; } virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg) { cout << name << ": InviteSession-onTerminated - " << msg->brief() << endl; assert(0); // This is overrideen in UAS and UAC specific handlers } virtual void onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents& sdp) { cout << name << ": InviteSession-onAnswer(SDP)" << endl; //sdp->encode(cout); } virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp) { cout << name << ": InviteSession-onOffer(SDP)" << endl; //sdp->encode(cout); } virtual void onEarlyMedia(ClientInviteSessionHandle, const SipMessage& msg, const SdpContents& sdp) { cout << name << ": InviteSession-onEarlyMedia(SDP)" << endl; //sdp->encode(cout); } virtual void onOfferRequired(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onOfferRequired - " << msg.brief() << endl; } virtual void onOfferRejected(InviteSessionHandle, const SipMessage* msg) { cout << name << ": InviteSession-onOfferRejected" << endl; } virtual void onDialogModified(InviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg) { cout << name << ": InviteSession-onDialogModified - " << msg.brief() << endl; } virtual void onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onRefer - " << msg.brief() << endl; } virtual void onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onReferAccepted - " << msg.brief() << endl; } virtual void onReferRejected(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onReferRejected - " << msg.brief() << endl; } virtual void onReferNoSub(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onReferNoSub - " << msg.brief() << endl; } virtual void onInfo(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onInfo - " << msg.brief() << endl; } virtual void onInfoSuccess(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onInfoSuccess - " << msg.brief() << endl; } virtual void onInfoFailure(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onInfoFailure - " << msg.brief() << endl; } virtual void onMessage(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onMessage - " << msg.brief() << endl; } virtual void onMessageSuccess(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onMessageSuccess - " << msg.brief() << endl; } virtual void onMessageFailure(InviteSessionHandle, const SipMessage& msg) { cout << name << ": InviteSession-onMessageFailure - " << msg.brief() << endl; } virtual void onForkDestroyed(ClientInviteSessionHandle) { cout << name << ": ClientInviteSession-onForkDestroyed" << endl; } // Out-of-Dialog Callbacks virtual void onSuccess(ClientOutOfDialogReqHandle, const SipMessage& successResponse) { cout << name << ": ClientOutOfDialogReq-onSuccess - " << successResponse.brief() << endl; } virtual void onFailure(ClientOutOfDialogReqHandle, const SipMessage& errorResponse) { cout << name << ": ClientOutOfDialogReq-onFailure - " << errorResponse.brief() << endl; } virtual void onReceivedRequest(ServerOutOfDialogReqHandle ood, const SipMessage& request) { cout << name << ": ServerOutOfDialogReq-onReceivedRequest - " << request.brief() << endl; // Add SDP to response here if required cout << name << ": Sending 200 response to OPTIONS." << endl; ood->send(ood->answerOptions()); }};class TestUac : public TestInviteSessionHandler{ public: bool done; SdpContents* sdp; HeaderFieldValue* hfv; Data* txt; TestUac() : TestInviteSessionHandler("UAC"), done(false), sdp(0), hfv(0), txt(0) { txt = new Data("v=0\r\n" "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n" "s=X-Lite\r\n" "c=IN IP4 192.168.2.15\r\n" "t=0 0\r\n" "m=audio 8000 RTP/AVP 8 3 98 97 101\r\n" "a=rtpmap:8 pcma/8000\r\n" "a=rtpmap:3 gsm/8000\r\n" "a=rtpmap:98 iLBC\r\n" "a=rtpmap:97 speex/8000\r\n" "a=rtpmap:101 telephone-event/8000\r\n" "a=fmtp:101 0-15\r\n"); hfv = new HeaderFieldValue(txt->data(), txt->size()); Mime type("application", "sdp"); sdp = new SdpContents(hfv, type); } virtual ~TestUac() { delete sdp; delete txt; delete hfv; } virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp) { cout << name << ": InviteSession-onOffer(SDP)" << endl; //sdp->encode(cout); is->provideAnswer(sdp); } virtual void onConnected(ClientInviteSessionHandle is, const SipMessage& msg) { cout << name << ": ClientInviteSession-onConnected - " << msg.brief() << endl; cout << "Connected now - requestingOffer from UAS" << endl; is->requestOffer(); } virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg) { cout << name << ": InviteSession-onTerminated - " << msg->brief() << endl; done = true; }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -