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

📄 uafacade.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        exit(-1);    }    if((myReadFd = open(myReadPath.c_str(), O_RDWR)) < 0)    {        cpLog(LOG_ERR, "Can not continute, failed to open the named pipes, reason %s", strerror(errno));        exit(-1);    }    if((myWriteFd = open(myWritePath.c_str(), O_RDWR)) < 0)    {        cpLog(LOG_ERR, "Can not continute, failed to open the named pipes, reason %s", strerror(errno));        exit(-1);    }#ifndef __FreeBSD__    ioctl(myWriteFd, I_FLUSH, FLUSHRW);#endif    //Create the GuiEventThread to receive GUI events    myGuiEventThread = new GuiEventThread(myInputEventFifo, myReadFd);    myGuiEventThread->run();    cpLog(LOG_INFO, "GuiEventThread started...");}voidUaFacade::run(){    assert( myWorkerThread != 0 );    assert( mySipThread != 0 );    myWorkerThread->run();    mySipThread->run();    myRegistrationManager->startRegistration();    if(mySipThread != 0) mySipThread->join();    if(myWorkerThread != 0) myWorkerThread->join();    if(myGuiEventThread != 0) myGuiEventThread->join();}UaFacade::~UaFacade(){    if(myReadPath.size()) unlink(myReadPath.c_str());    if(myWritePath.size()) unlink(myWritePath.c_str());}voidUaFacade::postMsg(Sptr<SipMsg> sMsg){    assert(sMsg != 0);    strstream s;cpLog(LOG_DEBUG,  "MSG :%s" , sMsg->encode().logData());    if(sMsg->getType() == SIP_STATUS)    {         Sptr<StatusMsg> statusMsg;        statusMsg.dynamicCast(sMsg);         assert(statusMsg != 0);        int statusCode = statusMsg->getStatusLine().getStatusCode();        if((statusMsg->getCSeq().getMethod() != INVITE_METHOD) &&           (statusMsg->getCSeq().getMethod() != CANCEL_METHOD))        {             s << "INFO ";        }        else        {            switch(statusCode)            {                case 100:                {                    s << "TRYING ";                }                break;                case 180:                case 183:                {                   cerr << "RINGING:" << endl;                    s << "RINGING ";                }                break;                case 200:                {                    s << "INCALL ";                }                break;               case 302:               {                  cerr << "In REDIRECT:" << endl;                  s << "REDIRECT ";               }               break;                case 480:                case 486:                {                    s << "BUSY ";                }                break;                case 404:                {                    strstream s2;                    s2 << "ERROR " << "User not found" << endl;                    s2 << endl << ends;                    postMsg(s2.str());                    s2.freeze(false);                    s << "INFO ";                }                break;                case 403:                {                    strstream s2;                    s2 << "ERROR " << "Host unreachable or connection refused";                    s2 << endl << ends;                    postMsg(s2.str());                    s2.freeze(false);                    s << "INFO ";                }                break;                case 408:                {                    strstream s2;                     s2 << "ERROR " << "Request timed out, check if Proxy_Server/URL is reachable";                    s2 << endl << ends;                    postMsg(s2.str());                    s2.freeze(false);                    s << "INFO ";                }                break;                case 407:                case 487:                {                    s << "INFO ";                }                break;                case 401:                {                    s << "UNAUTHORIZED ";                }                break;                case 603:                {                    strstream s2;                     s2 << "ERROR  " << "Request declined by the callee";                    s2 << endl << ends;                    postMsg(s2.str());                    s2.freeze(false);                    s << "INFO ";                }                break;                default:                {                    s << "ERROR ";                }                break;            }        }        s << sMsg->encode().logData() << endl << ends;    }    else    {        if((sMsg->getType() == SIP_BYE) ||                (sMsg->getType() == SIP_CANCEL))        {            s << "R_HANGUP " << sMsg->encode().logData() << endl << ends;        }        else        {            s << "INFO " << sMsg->encode().logData() << endl << ends;        }    }    postMsg(s.str());    s.freeze(false);}voidUaFacade::postInfo(Sptr<SipMsg> sMsg){    assert(sMsg != 0);    strstream s;    s << "INFO " << sMsg->encode().logData() << endl << ends;    postMsg(s.str());    s.freeze(false);}voidUaFacade::postMsg(const string msg){    if(myMode == CALL_MODE_UA)    {        string lstr(msg);        lstr += "|";        cpLog(LOG_DEBUG, "Posting to GUI:[%s]", lstr.c_str());        if(write(myWriteFd, lstr.c_str(), lstr.size()) < 0)        {            cpLog(LOG_ERR, "Failed to write data to named pipe");        }    }}voidUaFacade::shutdown(){    if(mySipStack ==0)    {	//shutdown already	return;    }    mySipThread->shutdown();    myWorkerThread->shutdown();    myGuiEventThread->shutdown();    if(myMediaDevice != 0) myMediaDevice->shutdownThreads();    if(mySipThread != 0) mySipThread->join();    if(myWorkerThread != 0) myWorkerThread->join();    if(myGuiEventThread != 0) myGuiEventThread->join();    mySipStack = 0;}Sptr<MediaDevice> UaFacade::getMediaDevice(int id) {    if((myMode == CALL_MODE_ANNON)||      (myMode == CALL_MODE_VMAIL))   {        //Devices are created/destroyed per call basis        Sptr<MediaDevice> retDev = 0;        Lock lock(myMutex);        MediaDeviceMap::iterator itr = myMediaDeviceMap.find(id);        if(itr != myMediaDeviceMap.end())        {            return (itr->second);        }        if(myMode == CALL_MODE_ANNON)        {            retDev = new FileMediaDevice(id);        }#ifdef USE_VM        else if(myMode == CALL_MODE_VMAIL)        {            cpLog(LOG_DEBUG, "Creating new VoiceMail device");            retDev = new VmcpDevice(id);        }#endif        assert(retDev != 0);        myMediaDeviceMap[id] = retDev;        return retDev;   }   //For UA mode, myMediaDevice should have been initialised   //to a sound card    bool cmdLineMode = false;    if(UaCommandLine::instance()->getIntOpt("cmdline"))    {        cmdLineMode = true;    }#ifdef USE_MPEGLIB   int video  = atoi(UaConfiguration::instance().getValue(VideoTag).c_str());   if(video && (!cmdLineMode) && (myMediaDevice == 0))   {       myMediaDevice = new VideoDevice(0);   }#endif   //set the sound-card media device   string devName = UaConfiguration::instance().getValue(DeviceNameTag);   if(myMediaDevice ==0)   {        if(cmdLineMode) cerr << "Opening audio device " << devName.c_str() << endl;        cpLog(LOG_INFO, "Using sound device [%s]", devName.c_str());	if(devName == "/dev/null") 	{            cpLog(LOG_INFO, "Opening NULL device");            myMediaDevice = new NullDevice();	}	else	{#if defined(__linux__)            myMediaDevice = new LinAudioDevice( devName.c_str());#endif	}   }   cpLog(LOG_DEBUG, "returning MediaDevice");   return myMediaDevice; }voidUaFacade::releaseMediaDevice(int id){    Lock lock(myMutex);    MediaDeviceMap::iterator itr = myMediaDeviceMap.find(id);    if(itr != myMediaDeviceMap.end())    {        cpLog(LOG_DEBUG, "Releasing device with Id:%d", id);	if(itr->second != 0)	{	    (itr->second)->shutdownThreads();	}        myMediaDeviceMap.erase(itr);    }}

⌨️ 快捷键说明

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