📄 rtcoutgoingdlg.cpp
字号:
/**********************************************************
//@StateDisconnectIDC
//
//@Description
//
// Enables /Disables the Disconnect Button
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void
CRTCOutgoingDlg::StateDisconnectIDC(VARIANT_BOOL fEnable)
{
if (VARIANT_TRUE == fEnable)
{
m_btnDisconnect.ModifyStyle( WS_DISABLED , 0 , 0);
RedrawWindow();
}
else
{
m_btnDisconnect.ModifyStyle(0, WS_DISABLED , 0);
RedrawWindow();
}
}
/**********************************************************
//@StateTuneIDC
//
//@Description
//
// Enable /Disable Tunning Wizard
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void
CRTCOutgoingDlg::StateTuneIDC(VARIANT_BOOL fEnable)
{
if (VARIANT_TRUE == fEnable)
{
m_btnTune.ModifyStyle( WS_DISABLED , 0 , 0);
RedrawWindow();
}
else
{
m_btnTune.ModifyStyle( 0 , WS_DISABLED , 0);
RedrawWindow();
}
}
/**********************************************************
//@StateDUriIDC
//
//@Description
//
// Enable / Disable Destination URI
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void
CRTCOutgoingDlg::StateDUriIDC(VARIANT_BOOL fEnable)
{
if (VARIANT_TRUE == fEnable)
{
m_editDURI.ModifyStyle( WS_DISABLED , 0 , 0);
RedrawWindow();
}
else
{
m_editDURI.ModifyStyle( 0 , WS_DISABLED , 0);
RedrawWindow();
}
}
/**********************************************************
//@UI Event Handlers and Message Handlers
//*********************************************************/
/**********************************************************
//@WindowProc
//
//@Description
//
// Overriding to Process the WM_RTCCOREEVENT only
// for the RTCCE_ASYNC_CLEANUP event
//
//
//*********************************************************/
LRESULT CRTCOutgoingDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
HRESULT hr = S_OK;
switch(message)
{
case WM_RTCCORE_EVENT:
{
ShutdownRTCApp();
break;
}
default : return CDialog::WindowProc(message, wParam, lParam);
}
return CDialog::WindowProc(message, wParam, lParam);
}
/**********************************************************
//@OnClose()
//
//@Description
//
// On Close Event Handler
//
//
//*********************************************************/
void CRTCOutgoingDlg::OnClose()
{
HRESULT hr = S_OK;
_ASSERTE(NULL != m_pIRTCClient);
// SAving form elements to the registry
WCHAR szText[MAX_STRING];
m_editSipUser.GetWindowText(szText, MAX_STRING);
RegistrySet(L"SipUser", szText);
m_editSipDomain.GetWindowText(szText, MAX_STRING);
RegistrySet(L"SipDomain", szText);
m_editSipObp.GetWindowText(szText, MAX_STRING);
RegistrySet(L"SipObp", szText);
//
// Need to call PrepareForShutdown Before shutdown
//
hr = m_pIRTCClient->PrepareForShutdown();
if (FAILED(hr))
{
LOGMSGERROR(_T("IRTCClient::PrepareForShutdown Failed 0x%x"), hr);
m_pIRTCClient->Shutdown();
return;
}
ShowWindow( SW_HIDE );
}
/**********************************************************
//@OnConnect
//
//@Description
//
// Called / EventHandler for Connect Button Clicked
//
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void CRTCOutgoingDlg::OnConnect()
{
StateSessionControl(STO_CREATE);
}
void CRTCOutgoingDlg::OnEnum()
{
// configure the ENUM tree
//m_EnumObject.SetDNS(L"192.92.138.35");
m_editEnumStatus.SetWindowText(_T("setting TLD..."));
m_EnumObject.SetENUMTLD(L"e164.arpa");
// fetch the phone number and set AUS
CString textString;
m_editDURI.GetWindowText(textString);
m_editEnumStatus.SetWindowText(_T("setting AUS..."));
m_EnumObject.SetAUS(textString);
// check if debug mode enabled and print all NAPTRs in a debug Window
if (m_editNAPTR.GetCheck()) {
if (this->dlgNaptr == NULL) {
dlgNaptr = new CDialogNaptr;
dlgNaptr->Create(IDD_NAPTR);
dlgNaptr->parentDlg = this;
dlgNaptr->ShowWindow(1);
//CFont font;
//font.CreatePointFont(120,_T("Arial"));
//dlgNaptr->m_EditText.SetFont(&font);
}
CString oldText, debugText;
dlgNaptr->m_EditText.GetWindowText(oldText);
// fetch all NAPTRs and write to the debug windows
m_editEnumStatus.SetWindowText(_T("lookup all services..."));
m_EnumObject.ENUMQuery(_T("sip|h323|x-skype:callto|voice:sip|voice:h323|voice:tel|video:sip|video:h323|video:tel|email:mailto|fax:tel|sms:tel|sms:sip|sms:sips|sms:mailto|ems:tel|ems:sip|ems:sips|ems:mailto|mms:tel|mms:sip|mms:sips|mms:mailto|ifax:mailto|web:http|web:https|ft:ftp|pres|ann:sip|ann:h323|ann:tel|ann:http|ann:ftp|enum|void:mailto|void:http|void:mailto|loc:http|key:ldap|key:http"));
// m_EnumObject.ENUMQuery(ALL_ENUM_SERVICES);
// fetch result from activeX object
short count;
count=m_EnumObject.GetDataCount();
CString temp;
debugText.Format(_T("\r\nfound %d NAPTRs!\r\n"), count);
debugText += m_EnumObject.GetDomain() + _T("\r\n");
int i;
for (i=0; i < count; i++) {
m_EnumObject.ENUMGetData(i);
temp.Format(_T(" %d %d %s "), m_EnumObject.Getorder(),
//temp.Format(_T(" %d %d %15s "), m_EnumObject.Getorder(),
m_EnumObject.Getpreference(), m_EnumObject.Getservice());
debugText += temp;
//temp.Format(_T("pref: %d "), );
//debugText += temp;
//temp.Format(_T("pref: %d "), m_EnumObject.Getservice());
//debugText += temp;
//debugText += + _T(" ");
debugText += m_EnumObject.GetURI() + _T("\r\n");
}
debugText = oldText + debugText;
dlgNaptr->m_EditText.SetWindowText(debugText);
}
//++++++++++++++++ fetch SIP URI
// perform ENUM lookup
m_editEnumStatus.SetWindowText(_T("lookup service type voice:sip ..."));
m_EnumObject.ENUMQuery(_T("voice:sip"));
// fetch result from activeX object
if (m_EnumObject.GetDataCount() > 0) {
m_EnumObject.ENUMGetData(0);
textString = m_EnumObject.GetURI();
// write SIP uri into the SIP URI field
m_editSIP.SetWindowText(textString);
} else {
m_editEnumStatus.SetWindowText(_T("lookup service type sip ..."));
m_EnumObject.ENUMQuery(_T("sip"));
// fetch result from activeX object
if (m_EnumObject.GetDataCount() > 0) {
m_EnumObject.ENUMGetData(0);
textString = m_EnumObject.GetURI();
// write SIP uri into the SIP URI field
m_editSIP.SetWindowText(textString);
} else {
m_editSIP.SetWindowText(_T(""));
}
}
//++++++++++++++++ fetch email address
// perform ENUM lookup
m_editEnumStatus.SetWindowText(_T("lookup service type email:mailto..."));
m_EnumObject.ENUMQuery(_T("email:mailto"));
// fetch result from activeX object
if (m_EnumObject.GetDataCount() > 0) {
m_EnumObject.ENUMGetData(0);
textString = m_EnumObject.GetURI();
// write SIP uri into the SIP URI field
m_editEMAIL.SetWindowText(textString);
} else {
m_editEMAIL.SetWindowText(_T(""));
}
//++++++++++++++++ fetch homepage address
// perform ENUM lookup
m_editEnumStatus.SetWindowText(_T("lookup service type web:http..."));
m_EnumObject.ENUMQuery(_T("web:http"));
// fetch result from activeX object
if (m_EnumObject.GetDataCount() > 0) {
m_EnumObject.ENUMGetData(0);
textString = m_EnumObject.GetURI();
// write SIP uri into the SIP URI field
m_editWEB.SetWindowText(textString);
} else {
m_editWEB.SetWindowText(_T(""));
}
//++++++++++++++++ fetch skype address
// perform ENUM lookup
m_editEnumStatus.SetWindowText(_T("lookup service type x-skype:callto..."));
m_EnumObject.ENUMQuery(_T("x-skype:callto"));
// fetch result from activeX object
if (m_EnumObject.GetDataCount() > 0) {
m_EnumObject.ENUMGetData(0);
textString = m_EnumObject.GetURI();
// write SIP uri into the SIP URI field
m_editSKYPE.SetWindowText(textString);
} else {
m_editSKYPE.SetWindowText(_T(""));
}
m_editEnumStatus.SetWindowText(_T("ENUM lookup done!"));
return;
}
void CRTCOutgoingDlg::OnSip()
{
StateSessionControl(STO_CREATE_SIP);
return;
}
void CRTCOutgoingDlg::OnEmail()
{
CString textString;
m_editEMAIL.GetWindowText(textString);
std::wstring convstring (textString);
static const boost::wregex e(L"mailto:[^\\|;:\"'碻 \\\\]+");
if (boost::regex_match(convstring, e)) {
ShellExecute(NULL, L"open", textString, NULL, NULL, SW_RESTORE);
} else {
MessageBox(_T("Error: Not a valid mailto URI!"),
_T("ENUM Softphone"));
}
return;
}
void CRTCOutgoingDlg::OnWeb()
{
CString textString;
m_editWEB.GetWindowText(textString);
std::wstring convstring (textString);
static const boost::wregex e(L"(http|https)://[^\\|;\"'碻 \\\\]+");
if (boost::regex_match(convstring, e)) {
ShellExecute(NULL, L"open", textString, NULL, NULL, SW_RESTORE);
} else {
MessageBox(_T("Error: Not a valid http(s) URI!"),
_T("ENUM Softphone"));
}
return;
}
/**********************************************************
//@OnDisconnect
//
//@Description
//
// Called / EventHandler for Disconnect Button Clicked
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void CRTCOutgoingDlg::OnDisconnect()
{
StateSessionControl(STO_TERMINATE);
StateConnectIDC(VARIANT_TRUE);
}
/**********************************************************
//@OnTune
//
//@Description
//
// Called / EventHandler for Tune Button Clicked
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
void CRTCOutgoingDlg::OnTune()
{
StateStartTunning();
}
/**********************************************************
//@RTC Application Entry / Exit Points
//*********************************************************/
/**********************************************************
//@InitializeRTCApp()
//
//@Description
//
// - CoCreating CLSID_RTCClient object and getting
// the IRTCClient Interface
// - Initializing the Client interface
// - Setting the Event Call Back Connection Point for
// the Source sink
// - Setting the Listen mode (opening SIP ports)
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
HRESULT
CRTCOutgoingDlg::InitializeRTCApp()
{
HRESULT hr = S_OK;
//
// CoCreating CLSID_RTCClient object and getting
// the IRTCClient Interface
//
hr = StateCoCreateClient();
if (FAILED(hr))
{
return hr;
}
//
// Initializing the Client
//
hr = StateInitClient();
if (FAILED(hr))
{
return hr;
}
// Setting the Event Call Back Connection Point for
// the Source sink
hr = StateSinkEvent(0);
if (FAILED(hr))
{
return hr;
}
//
// Setting the Listen mode to
// receive incoming calls event notifications
//
hr = StateListenMode( RTCLM_DYNAMIC );
if (FAILED(hr))
{
return hr;
}
m_ctrlEditStatus.SetWindowText(_T("Initialized ..."));
return hr;
}
/**********************************************************
//@ShutdownRTCApp()
//
//@Description
//
//
//
//@Args In: Void
//@Args Out: Void
//
//
//*********************************************************/
HRESULT
CRTCOutgoingDlg::ShutdownRTCApp()
{
HRESULT hr = S_OK;
_ASSERTE(NULL != m_pIRTCClient);
StateUnSinkEvent();
hr = m_pIRTCClient->Shutdown();
if (FAILED(hr))
{
LOGMSGERROR(_T("IRTCClient::Shutdown() Failed 0x%x"), hr);
}
ReleaseStateMachine();
CoUninitialize();
DestroyWindow();
return S_OK;
}
/**********************************************************
//@RTC State Machine Methods for RTC Core Operations
//*********************************************************/
/**********************************************************
//@StateCoCreateClient()
//
//@Description
//
// CoCreate the RTC Client COM Object
//
//@Args In: None
//@Args Out: None
//
//
//*********************************************************/
HRESULT
CRTCOutgoingDlg::StateCoCreateClient()
{
HRESULT hr = S_OK;
_ASSERTE(NULL != this);
hr = CoCreateInstance(CLSID_RTCClient,
NULL,
CLSCTX_INPROC_SERVER,
IID_IRTCClient,
reinterpret_cast<void **> (&m_pIRTCClient)
);
if (FAILED(hr))
{
LOGMSGERROR(_T("CoCreateInstance(CLSID_RTCClient) : Failed 0x%x"), hr);
return hr;
}
return hr;
}
/**********************************************************
//@StateInitClient
//
//@Description
//
// Initialize the RTCClient Interface
//
//@Args In: None
//@Args Out: None
//
//
//*********************************************************/
HRESULT
CRTCOutgoingDlg::StateInitClient()
{
HRESULT hr = S_OK;
_ASSERTE(NULL != this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -