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

📄 chvapi.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Implementation of the ChVAPI object, which manages the interface between
	VAPI and the Sound Module.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChSound/ChVAPI.cpp,v 1.1 1996/09/26 17:32:05 coyote Exp $

#include "headers.h"

#if defined( CH_USE_VAPI )

#include <ChReg.h>

#include "ChVAPI.h"


/*----------------------------------------------------------------------------
	Constants
----------------------------------------------------------------------------*/

#define DEF_VAPI_PORT	12370
											/* This should be set to zero
												if Voxware ever fixes the
												problem of returning the
												correct port number */
#define VAPI_PORT		DEF_VAPI_PORT


/*----------------------------------------------------------------------------
	ChVAPI static member variables
----------------------------------------------------------------------------*/

ChVAPI*				ChVAPI::m_this = 0;
int					ChVAPI::m_iUsage = 0;
VAPI_HANDLE			ChVAPI::m_hVAPI = 0;

ChVAPISessionMgr	ChVAPI::m_vapiSessions;
chuint16			ChVAPI::m_suVAPIPort = 0;
string				ChVAPI::m_strVAPILocalHost;

VAPI_USER_INFO		ChVAPI::m_userInfo;

chuint32			ChVAPI::m_luMikeVolume;
chuint32			ChVAPI::m_luMikeSensitivity;
bool				ChVAPI::m_boolRejectCalls;


/*----------------------------------------------------------------------------
	ChVAPI public methods
----------------------------------------------------------------------------*/

ChVAPI::ChVAPI()
{
	if (0 == m_iUsage)
	{
		VAPI_INITIALIZE			vapiInit;
		VAPI_TRANSACTION_HANDLE	hTransaction;
		VAPI_RETCODE			retCode;

		m_this = this;

		ChMemClearStruct( &m_userInfo );
		m_userInfo.wSizeOfUserInfo = sizeof( VAPI_USER_INFO );

		ChMemClearStruct( &vapiInit );
		vapiInit.wSizeOfInitialize = sizeof( VAPI_INITIALIZE );
		vapiInit.usListenPort = VAPI_PORT;
		vapiInit.lpNotifyProc = NotifyProc;

		retCode = vapiInitialize( &m_hVAPI, &hTransaction, 0,
									&vapiInit );
		if (VAPI_NO_ERROR != retCode)
		{
			#if defined( CH_DEBUG )
			{
				char		cBuffer[160];

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

			m_hVAPI = 0;
		}
		else
		{
			UpdatePrefs();
		}
	}

	m_iUsage++;
}


ChVAPI::~ChVAPI()
{
	if (0 == --m_iUsage)
	{
		if (GetVAPIHandle())
		{
			VAPI_RETCODE			retCode;

			retCode = vapiCleanup( GetVAPIHandle() );
			if (VAPI_NO_ERROR != retCode)
			{
				#if defined( CH_DEBUG )
				{
					char		cBuffer[160];

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

		m_hVAPI = 0;
	}
}


/*----------------------------------------------------------------------------
	ChVAPI public methods
----------------------------------------------------------------------------*/

bool ChVAPI::MakeCall( const string& strCallId, const string& strHost,
						chuint16 suPort, chflag32 flOptions,
						chflag32 flRemoteOptions )
{
	VAPI_RETCODE			retCode;
	VAPI_TRANSACTION_HANDLE	hTransaction;
	bool					boolSuccess;
	chuint16				suFullDuplex;
	bool					boolFullDuplex;
											// Copy information to be shared

	ASSERT( VAPI_MAX_LASTNAME_LENGTH > sizeof( chflag32 ) );

	sprintf( m_userInfo.szLastName, "%d", flRemoteOptions );
	strncpy( m_userInfo.szFirstName, (const char*)strCallId, VAPI_MAX_LASTNAME_LENGTH );
	m_userInfo.szLocale2[VAPI_MAX_LASTNAME_LENGTH - 1] = '\0';

	vapiSetUserInfo( GetVAPIHandle(), &m_userInfo );

	retCode = vapiQuerySoundDevices( GetVAPIHandle(), 0, 0, &suFullDuplex );
	boolFullDuplex = !!suFullDuplex;
	retCode = vapiSetSoundDevices( GetVAPIHandle(), 0, 0, boolFullDuplex );
	if (VAPI_NO_ERROR != retCode)
	{
		#if defined( CH_DEBUG )
		{
			char		cBuffer[160];

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

		boolSuccess = false;
	}
	else
	{
		VAPI_USER_INFO		destUserInfo;

		ChMemClearStruct( &destUserInfo );
		destUserInfo.wSizeOfUserInfo = sizeof( VAPI_USER_INFO );
		strcpy( destUserInfo.szNetAddress, (const char*)strHost );
		destUserInfo.usPort = suPort;

		retCode = vapiEstablishSession(	GetVAPIHandle(), &hTransaction,
											0, &destUserInfo, USE_UDP );
		if (VAPI_NO_ERROR != retCode)
		{
			#if defined( CH_DEBUG )
			{
				char		cBuffer[160];

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

			boolSuccess = false;
		}
	}

	return boolSuccess;
}


bool ChVAPI::Hangup( const string& strCallId )
{
	return m_vapiSessions.Hangup( GetVAPIHandle(), strCallId );
}


void ChVAPI::UpdatePrefs()
{
	ChRegistry	reg( SOUND_PREFS_GROUP );
	chint32		lVolume;

	reg.ReadBool( SOUND_PREFS_REJECT_CALLS, m_boolRejectCalls,
					SOUND_PREFS_REJECT_CALLS_DEF );

	reg.Read( SOUND_PREFS_MIKE_VOLUME, m_luMikeVolume,
				SOUND_PREFS_MIKE_VOLUME_DEF );
	reg.Read( SOUND_PREFS_MIKE_SENSITIVITY, m_luMikeSensitivity,
				SOUND_PREFS_MIKE_SENSITIVITY_DEF );

	vapiSetRecordLevel( GetVAPIHandle(), GetMikeVolume() );

	if (0 == GetMikeVolume())
	{
		vapiMuteMike( GetVAPIHandle(), VAPI_MUTE_MIKE );
	}
	else
	{
		vapiMuteMike( GetVAPIHandle(), VAPI_UNMUTE_MIKE );
	}

	vapiSetVoiceActivationLevel( GetVAPIHandle(),
									(chuint16)GetMikeSensitivity() );

	reg.Read( SOUND_PREFS_SPEECH_VOLUME, lVolume, VOLUME_MAX_RANGE );
	if (lVolume < 0)
	{
		lVolume = 0;
	}
	else if (lVolume > VOLUME_MAX_RANGE)
	{
		lVolume = VOLUME_MAX_RANGE;
	}
	vapiSetSpeakerVolume( GetVAPIHandle(), lVolume );
}


/*----------------------------------------------------------------------------
	ChVAPI notification callback
----------------------------------------------------------------------------*/

VAPI_RETCODE ChVAPI::NotifyProc( unsigned short wMessage,
									unsigned long hTransaction,
				    				unsigned long dwVapiParamOne,
				    				unsigned long dwVapiParamTwo,
				    				unsigned long dwUserParam )
{
	VAPI_HANDLE			hVAPI;

	#if defined( CH_DEBUG )
	char				cBuffer[160];
	#endif	// defined( CH_DEBUG )

	hVAPI = GetVAPIHandle();

	switch (wMessage)
	{
		case VAPI_NOTIFY_MIC_VOLUME_CHANGE:
		{
			//UpdateRecordSlider(dwVapiParamOne);
			return VAPI_NO_ERROR;
		}

		case VAPI_NOTIFY_BUFFER_LEVEL_CHANGE:
		{
			//UpdateBufferScale(dwVapiParamOne);
			return VAPI_NO_ERROR;
		}

		case VAPI_NOTIFY_MIC_GAINMETER_CHANGE:
		{
			//UpdateXmitSpeechScale(dwVapiParamOne, 0);
			return VAPI_NO_ERROR;
		}

		case VAPI_NOTIFY_NEW_SESSION_STATUS:
		{
			switch( dwVapiParamOne )
			{
				case VAPI_NOTIFY_STATUS_ESTABLISHED:
				{
					VAPI_SESSION_INFO*	pSessionInfo;
					VAPI_RETCODE		retCode;
					VAPI_SESSION_HANDLE	hSession;
					string				strCallId;
					chflag32			flOptions;

					pSessionInfo = (VAPI_SESSION_INFO*)dwVapiParamTwo;
					hSession = pSessionInfo->hSession;

					strCallId = pSessionInfo->RemoteUserInfo.szFirstName;
					flOptions =
						atol( pSessionInfo->RemoteUserInfo.szLastName );

					TRACE( "VAPI: Call is established.\n" );

					m_vapiSessions.Set( strCallId, hSession, flOptions );

					retCode = vapiHandsOffMode( hVAPI, VAPI_HANDS_OFF_MODE );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiHandsOffMode (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}

					retCode = vapiSetInitialDelay( hVAPI, hSession, 100 );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSetInitialDelay (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}

					retCode = vapiSetSilentWindow( hVAPI, 0 );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSetSilentWindow (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}

					retCode = vapiSetSpeakerVolume( hVAPI, 50 );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSetSpeakerVolume (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}

					retCode = vapiSetRecordLevel( hVAPI, GetMikeVolume() );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSetRecordLevel (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}

					retCode = vapiSetVoiceActivationLevel( GetVAPIHandle(),
															(chuint16)GetMikeSensitivity() );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSetSpeechActivationLevel (%hu)\n",
										retCode );
							TRACE( cBuffer );
						}
						#endif	// defined( CH_DEBUG )
					}
					break;
				}

				case VAPI_NOTIFY_STATUS_RINGING:
				{
					TRACE( "VAPI: Ring!\n" );
					break;
				}

				case VAPI_NOTIFY_STATUS_INCOMING_CALL:
				{
					VAPI_TRANSACTION_HANDLE	hTransaction;
					LPVAPI_SESSION_INFO		pSessionInfo;
					VAPI_RETCODE			retCode;
					VAPI_SESSION_HANDLE		hSession;
					unsigned long			dwResponse;

					TRACE( "VAPI: Incoming call.\n" );

					pSessionInfo = (VAPI_SESSION_INFO*)dwVapiParamTwo;
					hSession = pSessionInfo->hSession;

					if (m_vapiSessions.AllSessionsInUse())
					{
						dwResponse = VAPI_SESSION_RESPONSE_BUSY;
					}
					else
					{
						dwResponse = VAPI_SESSION_RESPONSE_ACCEPT;
					}

					retCode =
						vapiSessionResponse( hVAPI, &hTransaction,
												0, hSession, dwResponse );
					if (VAPI_NO_ERROR != retCode)
					{
						#if defined( CH_DEBUG )
						{
							sprintf( cBuffer,
										"VAPI: Error calling "
										"vapiSessionResponse (%hu)\n",
										retCode );

⌨️ 快捷键说明

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