psphonetask.cpp
来自「基于sipfoundy 公司开发的sipx协议API」· C++ 代码 · 共 1,582 行 · 第 1/4 页
CPP
1,582 行
//// Copyright (C) 2004, 2005 Pingtel Corp.// //// $$//////////////////////////////////////////////////////////////////////////////// SYSTEM INCLUDES#include <assert.h>#include <time.h>#ifdef __pingtel_on_posix__#include <stdlib.h>#endif#ifdef _VXWORKS# include <hostLib.h># include <bootLib.h># include <sysLib.h># include <resolvLib.h># include <socket.h># include <../config/pingtel/pingtel.h># include <dosFsLib.h>#endif#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>// APPLICATION INCLUDES#ifdef _VXWORKS int touch(char *name);#endif#include "os/OsLock.h"#include "os/OsReadLock.h"#include "os/OsTime.h"#include "os/OsUtil.h"#include "os/OsWriteLock.h"#include "os/OsSocket.h"#include "ps/PsButtonId.h"#include "ps/PsButtonTask.h"#include "ps/PsHookswTask.h"#include "ps/PsLampTask.h"#include "ps/PsPhoneTask.h"#include "ps/PsButtonInfo.h"#include "ps/PsTaoComponent.h"#include "ps/PsTaoComponentGroup.h"#include "ps/PsTaoButton.h"#include "ps/PsTaoHookswitch.h"#include "ps/PsTaoDisplay.h"#include "ps/PsTaoLamp.h"#include "ps/PsTaoRinger.h"#include "ps/PsTaoMicrophone.h"#include "ps/PsTaoSpeaker.h"#include "ptapi/PtTerminalConnection.h"#include "ptapi/PtComponent.h"#include "ptapi/PtComponentGroup.h"#include "ptapi/PtConnection.h"#include "tao/TaoDefs.h"#include "tao/TaoMessage.h"#include "tao/TaoPhoneComponentAdaptor.h"#include "tao/TaoTerminalAdaptor.h"#include "tao/TaoObjectMap.h"// EXTERNAL FUNCTIONS// EXTERNAL VARIABLES// CONSTANTS// STATIC VARIABLE INITIALIZATIONSPsPhoneTask* PsPhoneTask::spInstance = 0;OsBSem PsPhoneTask::sLock(OsBSem::Q_PRIORITY, OsBSem::FULL);/* //////////////////////////// PUBLIC //////////////////////////////////// *//* ============================ CREATORS ================================== */// Return a pointer to the Phone task, creating it if necessaryPsPhoneTask* PsPhoneTask::getPhoneTask(void){ UtlBoolean isStarted; // If the task object already exists, and the corresponding low-level task // has been started, then use it if (spInstance != NULL && spInstance->isStarted()) return spInstance; // If the task does not yet exist or hasn't been started, then acquire // the lock to ensure that only one instance of the task is started sLock.acquire(); if (spInstance == NULL) spInstance = new PsPhoneTask(); isStarted = spInstance->isStarted(); if (!isStarted) { isStarted = spInstance->start(); assert(isStarted); } sLock.release(); return spInstance;}// DestructorPsPhoneTask::~PsPhoneTask(){ mpButtonTask->requestShutdown(); // shut down the button task delete mpButtonTask; mpHookswTask->requestShutdown(); // shut down the hookswitch task delete mpHookswTask; mpLampTask->requestShutdown(); // shut down the lamp task delete mpLampTask; delete mpListenerCnt; if (mpListeners) { delete mpListeners; mpListeners = 0; } if (mpActiveListeners) { delete[] mpActiveListeners; mpActiveListeners = 0; } spInstance = NULL;}/* ============================ MANIPULATORS ============================== */// Register as a listener for phone messages.// For now, the phone task allows at most one listener and forwards// all keypad and hookswitch messages to that listener.OsStatus PsPhoneTask::addListener(OsServerTask* pListener){ if (!mpListenerCnt) mpListenerCnt = new TaoReference(); if (!mpListeners) mpListeners = new TaoObjectMap(); int cnt = mpListenerCnt->add(); mpListeners->insert((TaoObjHandle)cnt, (TaoObjHandle)pListener); if (mpActiveListeners) delete[] mpActiveListeners; mpActiveListeners = new TaoObjHandle[cnt]; mpListeners->getActiveObjects(mpActiveListeners, cnt); return OS_SUCCESS;}// Create a phone message and post it to the Phone task// Return the result of the message send operation.OsStatus PsPhoneTask::postEvent(const int msg, void* source, const int param1, const int param2, const OsTime& rTimeout){ PsMsg phoneMsg(msg, source, param1, param2); OsStatus res; res = postMessage(phoneMsg, rTimeout); return res;}int PsPhoneTask::taoGetMicGain(int group){ OsStatus rc = OS_INVALID_ARGUMENT; int level = 0; switch(group) { case PtComponentGroup::HAND_SET: if (mpHandSetGroup) rc = mpHandSetGroup->getMicGain(PsTaoComponentGroup::HAND_SET, level); break; case PtComponentGroup::SPEAKER_PHONE: if (mpSpeakerPhoneGroup) rc = mpSpeakerPhoneGroup->getMicGain(PsTaoComponentGroup::SPEAKER_PHONE, level); break; case PtComponentGroup::RINGER: if (mpPhoneSetGroup) rc = mpPhoneSetGroup->getMicGain(PsTaoComponentGroup::PHONE_SET, level); break; case PtComponentGroup::PHONE_SET: if (mpPhoneSetGroup) rc = mpPhoneSetGroup->getMicGain(PsTaoComponentGroup::PHONE_SET, level); break; case PtComponentGroup::HEAD_SET: if (mpHeadSetGroup) rc = mpHeadSetGroup->getMicGain(PsTaoComponentGroup::HEAD_SET, level); break; default: level = getGain(); break; } return level;}OsStatus PsPhoneTask::taoSetMicGain(int group, int level){ OsStatus rc = OS_INVALID_ARGUMENT; switch(group) { case PtComponentGroup::HAND_SET: if (mpHandSetGroup) rc = mpHandSetGroup->setMicGain(PsTaoComponentGroup::HAND_SET, level); break; case PtComponentGroup::SPEAKER_PHONE: if (mpSpeakerPhoneGroup) rc = mpSpeakerPhoneGroup->setMicGain(PsTaoComponentGroup::SPEAKER_PHONE, level); break; case PtComponentGroup::RINGER: if (mpPhoneSetGroup) rc = mpPhoneSetGroup->setMicGain(PsTaoComponentGroup::PHONE_SET, level); break; case PtComponentGroup::PHONE_SET: if (mpPhoneSetGroup) rc = mpPhoneSetGroup->setMicGain(PsTaoComponentGroup::PHONE_SET, level); break; case PtComponentGroup::HEAD_SET: if (mpHeadSetGroup) rc = mpHeadSetGroup->setMicGain(PsTaoComponentGroup::HEAD_SET, level); break; default: setGain(level); break; } return rc;}// Set the microphone gain to a level between 0 (low) and 100 (high)OsStatus PsPhoneTask::setGain(int level){ OsStatus rc = OS_UNSPECIFIED; osPrintf("PsPhoneTask::setGain(%d)\n", level); if (level < 0) level = 0; // constrain level to be between if (level > mHigh) level = mHigh; // 0 and 100; switch(mSpkrMode) { case HANDSET_ENABLED: if (mpHandSetGroup) { rc = mpHandSetGroup->setMicGain(PsTaoComponentGroup::HAND_SET, level);#ifdef _VXWORKS MpCodec_setMicMode(CODEC_ENABLE_HANDSET_MIC);#endif } break; case SPEAKERPHONE_ENABLED: if (mpSpeakerPhoneGroup) { rc = mpSpeakerPhoneGroup->setMicGain(PsTaoComponentGroup::SPEAKER_PHONE, level);#ifdef _VXWORKS MpCodec_setMicMode(CODEC_ENABLE_BASE_MIC);#endif } break; case RINGER_ENABLED: if (mpPhoneSetGroup) { rc = mpPhoneSetGroup->setMicGain(PsTaoComponentGroup::PHONE_SET, level);#ifdef _VXWORKS MpCodec_setMicMode(CODEC_ENABLE_BASE_MIC);#endif } break; case SOUND_ENABLED: if (mpPhoneSetGroup) { rc = mpPhoneSetGroup->setMicGain(PsTaoComponentGroup::PHONE_SET, level);#ifdef _VXWORKS MpCodec_setMicMode(CODEC_ENABLE_BASE_MIC);#endif } break; case HEADSET_ENABLED: if (mpHeadSetGroup) { rc = mpHeadSetGroup->setMicGain(PsTaoComponentGroup::HEAD_SET, level);#ifdef _VXWORKS MpCodec_setMicMode(CODEC_ENABLE_HEADSET_MIC);#endif } break; default:// assert(FALSE); break; } osPrintf("PsPhoneTask::setGain - MpCodec_setGain(%d)\n", level); assert(false); return rc;}// Sets the speaker mode for the phone (which speakers are enabled).// and returns the previous setting.void PsPhoneTask::setSpeakerMode(int mode){ assert((mode & ~(HANDSET_ENABLED | SPEAKERPHONE_ENABLED | RINGER_ENABLED | HEADSET_ENABLED | SOUND_ENABLED | EXTSPEAKER_ENABLED)) == 0); mSpkrMode = mode;#ifdef _VXWORKS { if (mode & HANDSET_ENABLED) { MpCodec_setSpeakerMode(CODEC_ENABLE_HANDSET_SPKR); MpCodec_setMicMode(CODEC_ENABLE_HANDSET_MIC); return; } if (mode & SPEAKERPHONE_ENABLED) { MpCodec_setSpeakerMode(CODEC_ENABLE_BASE_SPKR); MpCodec_setMicMode(CODEC_ENABLE_BASE_MIC); return; } if (mode & RINGER_ENABLED) { MpCodec_setSpeakerMode(CODEC_ENABLE_RINGER_SPKR); MpCodec_setMicMode(CODEC_DISABLE_MIC); return; } if (mode & SOUND_ENABLED) { MpCodec_setSpeakerMode(CODEC_ENABLE_BASE_SPKR); MpCodec_setMicMode(CODEC_DISABLE_MIC); return; } if (mode & HEADSET_ENABLED) { MpCodec_setSpeakerMode(CODEC_ENABLE_HEADSET_SPKR); MpCodec_setMicMode(CODEC_ENABLE_HEADSET_MIC); return; } if (mode & EXTSPEAKER_ENABLED) { if (MpCodec_isExtSpkrPresent()) { MpCodec_setSpeakerMode(CODEC_ENABLE_EXTERNAL_SPKR_MONO); return; } else { MpCodec_setSpeakerMode(CODEC_ENABLE_BASE_SPKR); MpCodec_setMicMode(CODEC_ENABLE_BASE_MIC); return; } } MpCodec_setSpeakerMode(CODEC_DISABLE_SPKR); MpCodec_setMicMode(CODEC_DISABLE_MIC); }#endif}void PsPhoneTask::speakerModeEnable(int mode){ mode |= mSpkrMode; setSpeakerMode(mode);}void PsPhoneTask::speakerModeDisable(int mode){ mode = (mSpkrMode & (0xffffffff - mode)); if (mode == 0) { mSpkrMode = mode; #ifdef _VXWORKS MpCodec_setSpeakerMode(CODEC_DISABLE_SPKR); MpCodec_setMicMode(CODEC_DISABLE_MIC); #endif } else { setSpeakerMode(mode); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?