📄 voipapp.hpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#pragma once
#ifndef __VOIPAPP_HPP__
#define __VOIPAPP_HPP__
#include "CommonFunctions.hpp"
#include "UIManager.hpp"
#include "Timers.hpp"
#include "Settings.hpp"
#include "DialEngine.hpp"
#include "ProxyServices.hpp"
#include "AudioManager.hpp"
#include "Database.hpp"
#include "Phone.hpp" //PH_VERB
#include "rtccore.h"
#include "PhoneAPI.hpp"
#include "HotKeys.hpp"
#include "Poom.hpp"
#include "SettingsAPI.hpp"
#define WM_DEBUG_PHONE_STATE (WM_APP + 1)
#define WM_RTC_SHUTDOWN_COMPLETE (WM_APP + 2)
#define WM_DIALED_DIGIT (WM_APP + 3)
#define WM_AUTH_COMPLETE (WM_APP + 4)
//error codes
//Too many active calls
const HRESULT VOIP_E_REACHMAXNUMBEROFCALLS = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0001);
class Call_t;
typedef ce::list<Call_t*> CallList_t;
//Main engine class for the application
class VoIPApp_t :
public ITimerHandler_t,
public IRTCEventNotification
{
public:
//ctors
VoIPApp_t();
~VoIPApp_t();
//static functions
static
HRESULT
s_SendCommandLine(
__in_opt const WCHAR* c_CommandLine
);
static
LRESULT WINAPI
s_NotificationWindowProc(
HWND,
UINT,
WPARAM,
LPARAM
);
//IUnknown for all inherited interfaces
ULONG STDMETHODCALLTYPE AddRef();
ULONG STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, VOID** ppvObj);
//public Non-COM API's
HRESULT
Run(
__in_opt const WCHAR* c_pCommandLine
);
HRESULT
Shutdown(
void
);
DWORD
PumpMessages(
void
);
HRESULT
PlayProgressTone(
AudioManager_t::ProgressToneType_e ProgressToneType
);
HRESULT
StopActiveTone(
void
);
HRESULT
StartRing(
__in Call_t* pIncomingCall
);
HRESULT
StopRing(
void
);
//Handles hotkey presses
LRESULT
HotkeyListenerWindowProc(
HWND hwnd,
UINT message,
WPARAM wParam ,
LPARAM lParam
);
HRESULT
OnHoldPress(
BOOL fKeyup
);
HRESULT
OnTransferPress(
BOOL fKeyup
);
HRESULT
OnMutePress(
BOOL fKeyup
);
HRESULT
OnRedialPress(
BOOL fKeyup
);
HRESULT
OnVoicemailPress(
BOOL fKeyup
);
HRESULT
OnHookModeChange(
HotKeys_t::HotKeyId_e HotkeyName,
BOOL KeyIsUp
);
//misc
HRESULT
EnsureOffHook(
void
);
HRESULT
ForegroundExistingApp(
void
);
//static WNDPROC function for the listener window - delegates the work
//to the instance function
LRESULT
NotificationWindowProc(
HWND,
UINT,
WPARAM,
LPARAM
);
//IRTCEventNotification implementation
HRESULT STDMETHODCALLTYPE
Event(
RTC_EVENT RTCEvent,
__in IDispatch* piEvent
);
//ITimerHandler_t implementation
void
OnTimerExpires(
UINT TimerID
);
HRESULT
EnableCalling(
void
);
HRESULT
RegisterCallbackInterface(
void
);
HRESULT
UnregisterCallbackInterface(
void
);
HRESULT
DisableCalling(
void
);
HRESULT
DoPhoneVerb(
PH_VERB Verb,
VPARAM VerbParam
);
HRESULT
Call(
__in const WCHAR* pDialString,
__in_opt const WCHAR* pFriendlyName,
__deref_out_opt Call_t** ppCall = NULL
);
void
FindCallBySession(
__in IRTCSession* pSession,
__deref_out_opt Call_t** ppCall
);
HRESULT
CreateIncomingCall(
__in IRTCSession* pSession,
__deref_out_opt Call_t** ppCall
);
HRESULT
PlaceActiveSessionOnHold(
void
);
//inline functions
BOOL IsOffHook() { return (m_AudioMode != e_vamIdle); };
Timers_t& GetTimers() { return m_Timers; };
Settings_t& GetSettings() { return m_Settings; };
DialEngine_t& GetDialEngine() { return m_DialEngine; };
CallList_t& GetCallList() { return m_CallList; };
AudioManager_t& GetAudioManager() { return m_AudioManager; };
Database_t& GetDatabase() { return m_Database; };
UIManager_t& GetUIManager() { return m_UIManager; };
Poom_t& GetPoom() { return m_Poom; };
ProxyServices_t& GetProxyServices() { return m_ProxyServices; };
IRTCClient* GetRTCClientPointer() { return m_cpRTCClient; };
bool OffHookByMakingCall() { return m_OffHookByMakingCall; };
private:
enum AutoHandledReason_e
{
AutoForwarded, // the call is auto forwarded
DoNotDisturb, // the call is auto forwarded because of 'Do NOT Disturb'
IsBlocked // the call is blocked
};
enum ProtectedAction_e
{
ActionInvalid = 0,
ActionVoicemail,
ActionRedial,
};
HRESULT
CreateNotificationWindow(
void
);
//RTC Event Handlers
HRESULT
OnRTCClientEvent(
__in IRTCClientEvent* piEvent
);
HRESULT
OnParticipantStateChangeEvent(
__in IRTCParticipantStateChangeEvent* piEvent
);
HRESULT
OnSessionStateChangeEvent(
__in IRTCSessionStateChangeEvent* piEvent
);
HRESULT
OnRegistrationStateChangeEvent(
__in IRTCRegistrationStateChangeEvent* piEvent
);
HRESULT
OnSessionReferStatusChangeEvent(
__in IRTCSessionReferStatusEvent* piEvent
);
HRESULT
OnSessionReferredEvent(
__in IRTCSessionReferredEvent* piEvent
);
HRESULT
OnSubscriptionStateChangeEvent(
__in IRTCSubscriptionStateChangeEvent* piEvent
);
HRESULT
OnSubscriptionNotificationEvent(
__in IRTCSubscriptionNotificationEvent* piEvent
);
bool
AreThereAnyCurrentCalls(
void
);
bool
AreThereAnyActiveCalls(
void
);
void
FindCallWithStatus(
RTC_SESSION_STATE CallStatus,
__deref_out_opt Call_t** ppCall
);
bool
AreThereCallWithStatus(
RTC_SESSION_STATE CallStatus
);
//Hotkey handlers
LRESULT RespondToHotKey(
INT idHotkey,
UINT uVirtKey,
BOOL fKeyup
);
// play sound
HRESULT
PlayProgressToneForDisconnectedCall(
__in Call_t* pCall,
__in bool* pPlayingTone
);
HRESULT
PlayDTMF(
UINT vkKeyCode
);
HRESULT
UpdateKeyupDownState(
BOOL fKeyUp,
UINT virtKey
);
HRESULT
PossiblyGenerateKeydown(
void
);
HRESULT
ForwardSession(
__in IRTCSession* pSession
);
HRESULT
GetAppropriateRingTone(
__in Call_t* pCall,
__in_ecount(BufferSize) WCHAR* pBuffer,
unsigned int BufferSize
);
bool
ShouldRejectIncomingCall(
__in Call_t* pCall
);
HRESULT
MakePhoneCall(
__in PH_MAKEPHONECALL_PARAMETERS* pParameters
);
HRESULT
SaveCallForwardedInfoInRegistry(
__in IRTCSession* pRTCSession
);
HRESULT
SaveAutoHandledCallInfoInRegistry(
AutoHandledReason_e Reason,
__in const WCHAR* c_pCallerId
);
void
OnHibernate(
void
);
void
UpdatePhoneAppStatus(
void
);
HRESULT
Redial(
void
);
HRESULT
DialVoicemail(
void
);
HRESULT
AuthenticateAction(
ProtectedAction_e action
);
HRESULT
OnUserAuthenticated(
ProtectedAction_e Action
);
HRESULT
OnAuthRequestComplete(
AuthenticationResult_e result
);
private:
//Hookmode change handlers
HRESULT InitializeHookState();
HRESULT OnNewlyOffHook();
HRESULT OnNewlyOnHook ();
private:
HRESULT Uninitialize();
private:
#ifdef ENABLE_VOIP_TEST_HOOKS
HRESULT
TestGetFormattedNumber(
__in const WCHAR* pDialString,
int pDialStringLength,
int FormatType
);
BOOL
TestGetIsNumberAutodialable(
__in const WCHAR* pString
);
#endif
#ifdef DEBUG
void
DebugPhoneState(
void
);
#endif
private:
enum VoIPAudioMode
{
e_vamIdle = 0, // The phone is not being used (on-hook).
e_vamHandset, // The phone is being used via the handset.
e_vamSpeakerPhone, // The phone is being used via the speaker phone.
};
VoIPAudioMode m_AudioMode;
bool m_HookSwitchIsUp;
UINT m_cRefs ;
BOOL m_fWaitingForPressAndHold;
BOOL m_fAlreadyRefreshed;
UINT m_vkLastKeyPressed;
DWORD m_tickLastUserAction;
DWORD m_tickLastKeydown;
CComPtr<Call_t> m_cpActiveVoicemailCall;
ProtectedAction_e m_PendingAuthAction;
CComPtr<IRTCClient> m_cpRTCClient;
CComPtr<IConnectionPoint> m_cpConnectionPt;
DWORD m_ConnectionPtCookie;
CallList_t m_CallList;
DialEngine_t m_DialEngine;
ProxyServices_t m_ProxyServices;
Settings_t m_Settings;
Timers_t m_Timers;
AudioManager_t m_AudioManager;
Database_t m_Database;
UIManager_t m_UIManager;
Poom_t m_Poom;
HWND m_NotificationWindow;
bool m_PlayingProgressTone;
bool m_DoNotPlayDialTone;
bool m_OffHookByMakingCall;
PH_MAKEPHONECALL_PARAMETERS m_AsyncMakePhoneCallParameters;
int m_MaxNumberOfCalls;
};
#endif /* __VOIPAPP_HPP__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -