A
download otdialei.cpp
Language: C++
Copyright: (c) 1995-99 OpenComm do Brasil Ltda.
LOC: 155
Project Info
Open Telephony Server(opentel)
Server: SourceForge
Type: cvs
...el\server\drivers\dialogic\
   dialogic.dsp
   otdialap.cpp
   otdialap.h
   otdialar.cpp
   otdialar.h
   otdialdev.h
   otdialdrv.cpp
   otdialdrv.h
   otdialdti.cpp
   otdialdti.h
   otdialdxx.cpp
   otdialdxx.h
   otdialei.cpp
   otdialei.h
   otdialev.cpp
   otdialev.h
   otdialex.cpp
   otdialex.h
   otdialgc.cpp
   otdialgc.h
   otdialmsi.cpp
   otdialmsi.h
   otdialogic.cpp
   otdialogic.h
   otdialsc.cpp
   otdialsc.h
   otdialtd.cpp
   otdialtd.h
   otdialtg.cpp
   otdialtg.h

/*****************************************************************************
* OpenTel Telephony Server & Framework
* Copyright (c) 1995-99 OpenComm do Brasil Ltda.
* Todos os direitos reservados.
* Este arquivo contem material confidencial de OpenComm do Brasil, e deve
* darse tratamento como tal.
******************************************************************************/


#ident "@(#) $Header: /cvsroot/opentel/opentel/server/drivers/dialogic/otdialei.cpp,v 1.2 2000/03/24 05:16:43 jbernab Exp $"

#include <otconfig.h>

#ifdef _WINDOWS
#include <windows.h>
#include <io.h>
#endif

#ifdef CONFIG_DIALOGIC_MSI

extern "C" {
#include <srllib.h>
#include <dtilib.h>
#include <msilib.h>
#include <dxxxlib.h>
#include <gclib.h>
#include <gcerr.h>
};


#include <otcallc.includes>
#include <dialogic/otdialogic.h>
#include <ottonegen.includes>
#include <dialogic/otdialmsi.h>
#include <dialogic/otdialei.h>
#include <otarchive.includes>


OT_IMPLEMENT_DYNAMIC(OtDialogicExtInterface,OtExtInterface);

OtDialogicExtInterface::OtDialogicExtInterface(OtDialogicMsiDev *msi) :
        OtExtInterface(),
        m_msidev(msi),
        m_defVolume(-3),                // Dialogic Default Volume
        m_volume(m_defVolume)
{
        m_msidev->addTarget(this);
        setName("OtDialogicExtInterface(" + OtString(ATDV_NAMEP(m_msidev->getFd()))+ ")");
}

OtDialogicExtInterface::~OtDialogicExtInterface(void)
{
        m_msidev->removeTarget(this);
}

OtTimeSlotListener *OtDialogicExtInterface::getListener()
{
        return m_msidev->getListener();
}

OtTimeSlotTransmitter *OtDialogicExtInterface::getTransmitter()
{
        return m_msidev->getTransmitter();
}

void OtDialogicExtInterface::genRing(long rings)
{
        // Dialogic Stuff
        if(ms_genring(m_msidev->getFd(), rings, EV_ASYNC)<0)
                throw OtDialogicException(m_msidev->getFd());

        // Framework specific
        m_extst=Ringing;
}

void OtDialogicExtInterface::stopRing(void)
{
        // Pre Framework Stuff
        if(m_extst!=Ringing) {
                throw OtException("Can only StopRing a ringing ExtInterface");
                }

        // Dialogic Stuff
        if(ms_stopfn(m_msidev->getFd(), MTF_RING)<0) {
                throw OtDialogicException(m_msidev->getFd());
                }

        // Post Framework specific
        m_extst=Idle;
}

void OtDialogicExtInterface::genZipTone(void)
{
        // Dialogic Stuff
        if(ms_genziptone(m_msidev->getFd())<0)
                throw OtDialogicException(m_msidev->getFd());
}

void OtDialogicExtInterface::setPower(int pow)
{
        // Dialogic Stuff
        int value;
        if(pow==true)
                value = MS_PWRON;
        else
                value = MS_PWROFF;

        if(ms_setstparm(m_msidev->getFd(), MSSP_STPWR, &value)<0)
                throw OtDialogicException(m_msidev->getFd());

        // Framework specific
        m_power=pow;
}

int OtDialogicExtInterface::getPower(void) const
{
        return m_power;
}

void OtDialogicExtInterface::adjustVolume(long db)
{
        // Pre conditions Framework
        long tmpvol=m_volume+db;
        if(tmpvol<-9 || tmpvol>3)
                throw OtException("AdjustVolume limits");

        // Dialogic Stuff
        if(ms_setvol(m_msidev->getFd(), VOLADJ, db)<0)
                throw OtDialogicException(m_msidev->getFd());

        // Framework specific
        m_volume+=db;
}

long OtDialogicExtInterface::getVolume(void) const
{
        return m_volume;
}

void OtDialogicExtInterface::resetVolume(void)
{
        // Dialogic Stuff
        if(ms_setvol(m_msidev->getFd(), VOLRES, 0)<0)
                throw OtDialogicException(m_msidev->getFd());

        // Framework specific
        m_volume=m_defVolume;
}

int OtDialogicExtInterface::onMessage(OtMessage *msg)
{
        OtDialogicEvent *e=(OtDialogicEvent *)((OtDlgMsg *)msg)->getEv();

        if(e->getClass()==OtDialogicEvent::eventClass) {
                switch(e->getType()) {
                        case DTEV_SIG:
                                {
                            int term =*(unsigned short *)e->getDatap();
                                switch(term) {
                                        case MSMM_ONHOOK:
                                                m_hook=OnHook;
                                                dispatchEvent(OtExtInterfaceEvent::eventOnHook);
                                                break;
                                        case MSMM_OFFHOOK:
                                                m_hook=OffHook;
                                                dispatchEvent(OtExtInterfaceEvent::eventOffHook);
                                                break;
                                        case MSMM_HOOKFLASH:
                                                dispatchEvent(OtExtInterfaceEvent::eventHookFlash);
                                                break;
                                        }
                                }
                                break;
                        case MSEV_RING:
                                {
                            int term =*(unsigned short *)e->getDatap();
                                switch(term) {
                                        case MSMM_RNGOFFHK:
                                                m_hook=OffHook;
                                                m_extst=InUse;
                                                dispatchEvent(OtExtInterfaceEvent::eventRingOffHook);
                                                break;
                                        case MSMM_TERM:
                                                m_extst=Idle;
                                                dispatchEvent(OtExtInterfaceEvent::eventRingTerm);
                                                break;
                                        case MSMM_RNGSTOP:
                                                m_extst=Idle;
                                                dispatchEvent(OtExtInterfaceEvent::eventRingStop);
                                                break;
                                        }

                                }
                                break;
                        case MSEV_NORING:
  //Glare Condition, answered at the same time as the ring, for us is answered
                                m_hook=OffHook;
                                m_extst=InUse;
                                dispatchEvent(OtExtInterfaceEvent::eventRingOffHook);
                                break;

                        }
                }
}

void OtDialogicExtInterface::dispatchEvent(OtEventType t)
{
        OtExtInterfaceEvent ev(*this,t);
        postEvent(ev);
}



#endif

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us