psphonetask.cpp

来自「基于sipfoundy 公司开发的sipx协议API」· C++ 代码 · 共 1,582 行 · 第 1/4 页

CPP
1,582
字号
      {/*         cout << "Phone message:" << endl;         cout << "  type="   << msgType <<                 ", source=" << msgSrc <<                 ", param1=" << param1 <<                 ", param2=" << param2 << endl;*/      }      break;   case PsMsg::BUTTON_SET_INFO:      if (mpTaoButton)      {         char buf[MAXIMUM_INTEGER_STRING_LENGTH];         sprintf(buf, "%d", param1);         if (mpTaoButton->setInfo(buf) && mpListeners != NULL)            postListenerMessage(rMsg);      }      else if (mpListeners != NULL)      {         postListenerMessage(rMsg);      }      break;   case PsMsg::HOOKSW_STATE:   case PsMsg::HOOKSW_SET_STATE:      if (mpListeners != NULL)         postListenerMessage(rMsg);      else      {/*         cout << "Phone message:" << endl;         cout << "  type="   << msgType <<                 ", source=" << msgSrc <<                 ", param1=" << param1 <<                 ", param2=" << param2 << endl;*/      }      break;   case PsMsg::TERMINAL_GET_COMPONENT:      processed = getComponent((PsMsg&)rMsg);      break;   case PsMsg::TERMINAL_GET_COMPONENTS:      processed = getComponents((PsMsg&)rMsg);      break;   case PsMsg::TERMINAL_GET_COMPONENTGROUPS:      processed = getComponentGroups((PsMsg&)rMsg);      break;   case PsMsg::HOOKSW_GET_CALL:   case PsMsg::HOOKSW_GET_STATE:      if (mpListeners != NULL)      {         postListenerMessage(rMsg);      }      break;   case PsMsg::MIC_GET_GAIN:      {         int gain = getGain();         char buf[MAXIMUM_INTEGER_STRING_LENGTH];         sprintf(buf, "%d", gain);         osPrintf("->>PsPhoneTask::MIC_GET_GAIN: %d<<-\n", gain);         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         pMsg->setArgList(buf);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::MIC_SET_GAIN:      osPrintf("->>PsPhoneTask::MIC_SET_GAIN: %d<<-\n", param1);      setGain(param1);      pMsg->setCmd(TaoMessage::COMPONENT_RESULT);      ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      break;/* ----------------------------- PHONERINGER --------------------------------- */   case PsMsg::RINGER_SET_INFO:      {         // do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);         break;      }   case PsMsg::RINGER_SET_PATTERN:      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_SET_VOLUME:   case PsMsg::SPEAKER_SET_VOLUME:      {         osPrintf("->>PsPhoneTask::SPEAKER/RINGER_SET_VOLUME: %d<<-\n", param1);         setVolume(param1);         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_GET_INFO:      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_GET_PATTERN:      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_GET_VOLUME:   case PsMsg::SPEAKER_GET_VOLUME:      {         int volume = getVolume();         char buf[MAXIMUM_INTEGER_STRING_LENGTH];         sprintf(buf, "%d", volume);         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         pMsg->setArgList(buf);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_GET_MAX_PATTERN_INDEX:      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_GET_NUMBER_OF_RINGS:      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::RINGER_IS_ON:/* ----------------------------- PHONESPEAKER --------------------------------- */      {// do nothing for now         pMsg->setCmd(TaoMessage::COMPONENT_RESULT);         ((TaoPhoneComponentAdaptor*) msgSrc)->postMessage(*pMsg);      }      break;   case PsMsg::LAMP_SET_MODE:      {         UtlString buttonInfo;         ((PsMsg) rMsg).getStringParam1(buttonInfo);         mpLampTask->setMode(buttonInfo.data(), (PsLampInfo::LampMode) param1);      }      break;   default:      assert(FALSE);      processed = FALSE;            // unexpected message      break;   }   return processed;}// getComponent just checks if the required component is in the// list ps supports, if supported, it returns the type back.UtlBoolean PsPhoneTask::getComponent(PsMsg& rMsg){        UtlString arg;        rMsg.getStringParam1(arg);        int type;        if (!arg.compareTo("button", UtlString::ignoreCase))                type = PtComponent::BUTTON;        else if (!arg.compareTo("display", UtlString::ignoreCase))                type = PtComponent::DISPLAY;        else if(!arg.compareTo("graphic_display", UtlString::ignoreCase))                type = PtComponent::GRAPHIC_DISPLAY;        else if(!arg.compareTo("hookswitch", UtlString::ignoreCase))                type = PtComponent::HOOKSWITCH;        else if(!arg.compareTo("lamp", UtlString::ignoreCase))                type = PtComponent::LAMP;        else if(!arg.compareTo("microphone", UtlString::ignoreCase))                type = PtComponent::MICROPHONE;        else if(!arg.compareTo("ringer", UtlString::ignoreCase))                type =  PtComponent::RINGER;        else if(!arg.compareTo("speaker", UtlString::ignoreCase))                type = PtComponent::SPEAKER;        else if(!arg.compareTo("text_display", UtlString::ignoreCase))                type = PtComponent::TEXT_DISPLAY;        else                type = PtComponent::UNKNOWN;        char buf[MAXIMUM_INTEGER_STRING_LENGTH];        sprintf(buf, "%d", type);        TaoMessage *pMsg = (TaoMessage *) &rMsg;        pMsg->setArgCnt(2);        arg = UtlString("1") + TAOMESSAGE_DELIMITER + UtlString(buf);        pMsg->setArgList(arg);        return TRUE;}UtlBoolean PsPhoneTask::getComponents(PsMsg& rMsg){        UtlString arg;        char buf[MAXIMUM_INTEGER_STRING_LENGTH];        int platformType = OsUtil::getPlatformType();        int cnt;        sprintf(buf, "%d", (int)PsTaoComponent::DISPLAY);        arg = UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::GRAPHIC_DISPLAY);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::HOOKSWITCH);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::LAMP);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::MICROPHONE);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::RINGER);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::SPEAKER);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponent::BUTTON);        arg += UtlString(buf);        if ((platformType == OsUtil::PLATFORM_TCAS5) ||            (platformType == OsUtil::PLATFORM_TCAS6) ||            (platformType == OsUtil::PLATFORM_TCAS7))        {                sprintf(buf, "%d", (int)PsTaoComponent::EXTERNAL_SPEAKER);                arg += TAOMESSAGE_DELIMITER + UtlString(buf);                cnt = 8;        }        else                cnt = 7;        int numButtons = mpButtonTask->getMaxButtonIndex() + 1;        PsButtonInfo btnInfo;        char *name;        for (int i = 0; i < numButtons; i++)        {                btnInfo = mpButtonTask->getButtonInfo(i);                name = btnInfo.getName();                arg += TAOMESSAGE_DELIMITER + UtlString(name);        }        TaoMessage *pMsg = (TaoMessage *) &rMsg;        pMsg->setArgCnt(numButtons + cnt);        pMsg->setArgList(arg);    return TRUE;}UtlBoolean PsPhoneTask::numComponents(PsMsg& rMsg){        int cnt = mpButtonTask->getMaxButtonIndex();        int platformType = OsUtil::getPlatformType();        if ((platformType == OsUtil::PLATFORM_TCAS5) ||            (platformType == OsUtil::PLATFORM_TCAS6) ||            (platformType == OsUtil::PLATFORM_TCAS7))                cnt += 9;        else                cnt += 8;        UtlString arg;        char buf[MAXIMUM_INTEGER_STRING_LENGTH];        sprintf(buf, "%d", cnt);        arg = UtlString(buf);        TaoMessage *pMsg = (TaoMessage *) &rMsg;        pMsg->setArgCnt(1);        pMsg->setArgList(arg);    return TRUE;}UtlBoolean PsPhoneTask::getComponentGroups(PsMsg& rMsg){        UtlString arg;        char buf[MAXIMUM_INTEGER_STRING_LENGTH];        int platformType = OsUtil::getPlatformType();        int cnt;        sprintf(buf, "%d", (int)PsTaoComponentGroup::HEAD_SET);        arg = UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponentGroup::HAND_SET);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponentGroup::SPEAKER_PHONE);        arg += UtlString(buf) + TAOMESSAGE_DELIMITER;        sprintf(buf, "%d", (int)PsTaoComponentGroup::PHONE_SET);        arg += UtlString(buf);        if ((platformType == OsUtil::PLATFORM_TCAS5) ||            (platformType == OsUtil::PLATFORM_TCAS6) ||            (platformType == OsUtil::PLATFORM_TCAS7))        {                sprintf(buf, "%d", (int)PsTaoComponentGroup::EXTERNAL_SPEAKER);                arg += TAOMESSAGE_DELIMITER + UtlString(buf);                cnt = 5;        }        else                cnt = 4;        TaoMessage *pMsg = (TaoMessage *) &rMsg;        sprintf(buf, "%d", cnt);        UtlString argList = UtlString(buf) + TAOMESSAGE_DELIMITER + arg;        pMsg->setArgCnt(cnt + 1);        pMsg->setArgList(argList);    return TRUE;}int PsPhoneTask::activateGroup(PsMsg& rMsg){        TaoMessage *pMsg = (TaoMessage *) &rMsg;        int type = atoi(pMsg->getArgList());        return activateGroup(type);}int PsPhoneTask::activateGroup(int type){        UtlBoolean rc = FALSE;        int level = 0;        switch(type)        {        case PtComponentGroup::HEAD_SET:                if (mpHeadSetGroup)                {                        rc = mpHeadSetGroup->activate();                        speakerModeEnable(HEADSET_ENABLED);                        mpHeadSetGroup->getVolume(PsTaoComponentGroup::HEAD_SET, level);                        setVolume(level);                        mpHeadSetGroup->getMicGainValue(PsTaoComponentGroup::HEAD_SET, level);                        setGainValue(level);                }                break;        case PtComponentGroup::HAND_SET:                if (mpHandSetGroup)                {                        rc = mpHandSetGroup->activate();                        speakerModeEnable(HANDSET_ENABLED);                        mpHandSetGroup->getVolume(PsTaoComponentGroup::HAND_SET, level);                        setVolume(level);                        mpHandSetGroup->getMicGainValue(PsTaoComponentGroup::HAND_SET, level);                        setGainValue(level);                }                break;        case PtComponentGroup::SPEAKER_PHONE:                if (mpSpeakerPhoneGroup)                {                        rc = mpSpeakerPhoneGroup->activate();                        speakerModeEnable(SPEAKERPHONE_ENABLED);                        mpSpeakerPhoneGroup->getVolume(PsTaoComponentGroup::SPEAKER_PHONE, level);                        setVolume(level);                        mpSpeakerPhoneGroup->getMicGainValue(PsTaoComponentGroup::SPEAKER_PHONE, level);                        setGainValue(level);                }                break;        case PtComponentGroup::EXTERNAL_SPEAKER:                if (mpExtSpeakerGroup)                {                        rc = mpExtSpeakerGroup->activate();                        speakerModeEnable(EXTSPEAKER_ENABLED);                        mpExtSpeakerGroup->getVolume(PsTaoComponentGroup::EXTERNAL_SPEAKER, level);                        setVolume(level);                        mpExtSpeakerGroup->getMicGainValue(PsTaoComponentGroup::EXTERNAL_SPEAKER, level);                        setGainValue(level);                }                break;        case PtComponentGroup::RINGER:        case PtComponentGroup::PHONE_SET:        if (mpPhoneSetGroup)        {            assert(false);        }        break;        case PtComponentGroup::SOUND:                if (mpSpeakerPhoneGroup)                {                   //int low;                   //int high;                   //int nominal;     // low <= nominal <= high                   //int stepsize;    // in .1 dB                   //int mute;

⌨️ 快捷键说明

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