⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chvapi.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}
					break;
				}

				case VAPI_NOTIFY_STATUS_HANGUP:
				{
					VAPI_SESSION_INFO*	pSessionInfo;

					pSessionInfo = (VAPI_SESSION_INFO*)dwVapiParamTwo;

											// Clear the active session handle

					m_vapiSessions.ClearSessionHdl( pSessionInfo->hSession );

					TRACE( "VAPI: Hung up!\n" );
					break;
				}

				case VAPI_NOTIFY_STATUS_XMIT:
				{
					//SetDlgItemText(hNotifyDlg, IDC_SENDRECV, "TRANSMIT");
					return VAPI_NO_ERROR;
				}

				case VAPI_NOTIFY_STATUS_RECV:
				{
					//SetDlgItemText(hNotifyDlg, IDC_SENDRECV, "RECEIVE");
					return VAPI_NO_ERROR;
				}

				case VAPI_NOTIFY_STATUS_UNKNOWN:
				{
					//SendMessage(GetDlgItem(hNotifyDlg, IDC_NOTIFY_LIST), LB_INSERTSTRING, (WPARAM)-1, (long)"Unknown rejection from remote.");
					break;
				}

				default:
				{
					#if defined( CH_DEBUG )
					{
						//wsprintf(cBuffer, "Unknown response from remote user (%ld).", dwVapiParamOne);
						//SendMessage(GetDlgItem(hNotifyDlg, IDC_NOTIFY_LIST), LB_INSERTSTRING, (WPARAM)-1, (long)cBuffer);
					}
					#endif	// defined( CH_DEBUG )
					break;
				}
			}
			break;
		}	

		case VAPI_NOTIFY_LOCAL_MODE:
		{
			switch( dwVapiParamOne )
			{
				case VAPI_NOTIFY_LOCALMODE_LISTEN:
				{
					//SetDlgItemText(hNotifyDlg, IDC_TALKLSTN, "LISTEN");
					break;
				}

				case VAPI_NOTIFY_LOCALMODE_TALK:
				{
					//SetDlgItemText(hNotifyDlg, IDC_TALKLSTN, "TALK");
					break;
				}
			}
			break;
		}

		case VAPI_NOTIFY_INIT_STATUS:
		{
			if (!dwVapiParamOne)
			{
				VAPI_NET_INIT_INFO*		pInitInfo;

				pInitInfo = (VAPI_NET_INIT_INFO*)dwVapiParamTwo;

				SetVAPIPort( pInitInfo->usLocalPort );
				SetVAPILocalHost( pInitInfo->szLocalNetAddress );

				strcpy( m_userInfo.szNetAddress,
						pInitInfo->szLocalNetAddress );
				m_userInfo.usPort = pInitInfo->usLocalPort;

				vapiSetUserInfo( GetVAPIHandle(), &m_userInfo );

				#if defined( CH_DEBUG )
				{
					sprintf( cBuffer, "VAPI: Initialized for %s:%d\n",
										pInitInfo->szLocalNetAddress,
										(int)pInitInfo->usLocalPort );
					TRACE( cBuffer );
				}
				#endif	// defined( CH_DEBUG )
			}
			break;
		}

		case VAPI_NOTIFY_SESSION_RESPONSE:
		{
			if (VAPI_SESSION_RESPONSE_ACCEPT == dwVapiParamTwo)
			{
				#if defined( CH_DEBUG )
				{
											// Call accepted!

					strcpy( cBuffer, "VAPI: Call has been accepted." );
				}
				#endif	// defined( CH_DEBUG )
			}
			else
			{
				switch (dwVapiParamTwo)
				{
					case VAPI_SESSION_RESPONSE_REJECT:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: Call has not been accepted." );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}

					case VAPI_SESSION_RESPONSE_BUSY:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: Caller is busy." );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}

					case VAPI_SESSION_RESPONSE_NOANSWER:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: Caller did not answer." );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}

					case VAPI_SESSION_RESPONSE_BLOCK:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: Caller is blocking calls." );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}

					case VAPI_SESSION_RESPONSE_VOICEMAIL:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: Speech mail system." );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}

					default:
					{
						#if defined( CH_DEBUG )
						{
							strcpy( cBuffer, "VAPI: UNKNOWN CALL RESPONSE\n" );
						}
						#endif	// defined( CH_DEBUG )
						break;
					}
				}
			}

			#if defined( CH_DEBUG )
			{
				TRACE( cBuffer );
			}
			#endif	// defined( CH_DEBUG )
			break;
		}

		default:
		{
			#if defined( CH_DEBUG )
			{
				sprintf( cBuffer, "VAPI: Unknown notification message (%ld).",
									wMessage );
				TRACE( cBuffer );
			}
			#endif	// defined( CH_DEBUG )
			break;
		}
	}

	return VAPI_NO_ERROR;
}


/*----------------------------------------------------------------------------
	ChVAPISessionMgr public methods
----------------------------------------------------------------------------*/

ChVAPISessionMgr::ChVAPISessionMgr() :
						m_iSessions( 0 )
{
	for (int iLoop = 0; iLoop < SESSION_LIMIT; iLoop++)
	{
		SetInUse( iLoop, false );
	}
}


ChVAPISessionMgr::~ChVAPISessionMgr()
{
}


bool ChVAPISessionMgr::Set( const string& strCallId,
							VAPI_SESSION_HANDLE hSession,
							chflag32 flOptions )
{
	bool			boolSuccess = false;
	ChVAPISession*	pFoundSession = 0;
	int				iLoc;

	if (0 == (pFoundSession = Find( strCallId, &iLoc )))
	{
		if (SESSION_LIMIT > GetSessionCount())
		{
			iLoc = 0;

			while ((0 == pFoundSession) && (iLoc < SESSION_LIMIT))
			{
				if (!IsInUse( iLoc ))
				{
					pFoundSession = GetSession( iLoc );
				}
				else
				{
					iLoc++;
				}
			}
		}
	}

	if (pFoundSession)
	{
		SetInUse( iLoc );

		pFoundSession->Set( hSession, strCallId, flOptions );

		boolSuccess = true;
	}

	return boolSuccess;
}


VAPI_SESSION_HANDLE ChVAPISessionMgr::
						GetSessionHandle( const string& strCallId,
											chflag32* pflOptions )
{
	VAPI_SESSION_HANDLE		hSession = 0;
	ChVAPISession*			pSession;

	if (pSession = Find( strCallId ))
	{
		hSession = pSession->GetSessionHdl();

		if (pflOptions)
		{
			*pflOptions = pSession->GetOptions();
		}
	}

	return hSession;
}


bool ChVAPISessionMgr::Hangup( VAPI_HANDLE hVAPI, const string& strCallId )
{
	VAPI_SESSION_HANDLE		hSession = 0;
	bool					boolSuccess = true;

	if (!strCallId.IsEmpty())
	{										// Look up the session by call id

		hSession = GetSessionHandle( strCallId );
	}

	if (hSession)
	{
		boolSuccess = Hangup( hVAPI, hSession );
	}
	else
	{
		for (int iLoop = 0; iLoop < SESSION_LIMIT; iLoop++)
		{
			if (IsInUse( iLoop ))
			{
				boolSuccess = boolSuccess &&
								Hangup( hVAPI,
										GetSession( iLoop )->GetSessionHdl() );
			}
		}
	}

	return boolSuccess;
}


bool ChVAPISessionMgr::ClearSession( const string& strCallId )
{
	int		iLoc;
	bool	boolFound;

	if (boolFound = (0 != Find( strCallId, &iLoc )))
	{
		SetInUse( iLoc, false );
	}

	return boolFound;
}


bool ChVAPISessionMgr::ClearSessionHdl( VAPI_SESSION_HANDLE hSession )
{
	bool		boolFound = false;
	int			iLoop;

	for (iLoop = 0; iLoop < SESSION_LIMIT; iLoop++)
	{
		if (IsInUse( iLoop ) &&
			(GetSession( iLoop )->GetSessionHdl() == hSession))
		{
			SetInUse( iLoop, false );

			boolFound = true;
		}
	}

	return boolFound;
}


/*----------------------------------------------------------------------------
	ChVAPISessionMgr protected methods
----------------------------------------------------------------------------*/

ChVAPISession* ChVAPISessionMgr::Find( const string& strCallId, int* piLoc )
{
	ChVAPISession*	pFoundSession = 0;

	if (0 != GetSessionCount())
	{
		int		iLoop = 0;

		while ((0 == pFoundSession) && (iLoop < SESSION_LIMIT))
		{
			if (IsInUse( iLoop ))
			{
				if (GetSession( iLoop )->GetId() == strCallId)
				{
					pFoundSession = GetSession( iLoop );

					if (piLoc)
					{
						*piLoc = iLoop;
					}
				}
			}

			iLoop++;
		}
	}

	return pFoundSession;
}


ChVAPISession* ChVAPISessionMgr::Find( VAPI_SESSION_HANDLE hSession,
										int* piLoc )
{
	ChVAPISession*	pFoundSession = 0;

	if (0 != GetSessionCount())
	{
		int		iLoop = 0;

		while ((0 == pFoundSession) && (iLoop < SESSION_LIMIT))
		{
			if (IsInUse( iLoop ))
			{
				if (GetSession( iLoop )->GetSessionHdl() == hSession)
				{
					pFoundSession = GetSession( iLoop );

					if (piLoc)
					{
						*piLoc = iLoop;
					}
				}
			}

			iLoop++;
		}
	}

	return pFoundSession;
}


bool ChVAPISessionMgr::Hangup( VAPI_HANDLE hVAPI, VAPI_SESSION_HANDLE hSession )
{
	VAPI_RETCODE			retCode;
	VAPI_TRANSACTION_HANDLE	hTransaction;
	bool					boolSuccess = true;

	retCode = vapiHangupSession( hVAPI, &hTransaction, 0, hSession );
	if (VAPI_NO_ERROR != retCode)
	{
		#if defined( CH_DEBUG )
		{
			char		cBuffer[160];

			sprintf( cBuffer, "VAPI: Error calling vapiHangupSession (%hu)\n",
								retCode );
			TRACE( cBuffer );
		}
		#endif	// defined( CH_DEBUG )

		boolSuccess = false;
	}

	return boolSuccess;
}


/*----------------------------------------------------------------------------
	ChVAPISession public methods
----------------------------------------------------------------------------*/

ChVAPISession::ChVAPISession()
{
}


ChVAPISession::~ChVAPISession()
{
}


#endif	// defined( CH_USE_VAPI )


// Local Variables: ***
// tab-width:4 ***
// End: ***

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -