ptterminal.cpp
来自「基于sipfoundy 公司开发的sipx协议API」· C++ 代码 · 共 1,679 行 · 第 1/5 页
CPP
1,679 行
//// Copyright (C) 2004, 2005 Pingtel Corp.// //// $$//////////////////////////////////////////////////////////////////////////////// SYSTEM INCLUDES#include <assert.h>#include <string.h>#ifdef __pingtel_on_posix__#include <stdlib.h>#endif// APPLICATION INCLUDES#include "cp/CpGatewayManager.h"#include "os/OsStatus.h"#include "ptapi/PtTerminal.h"#include "ptapi/PtDefs.h"#include "ptapi/PtProvider.h"#include "ptapi/PtAddress.h"#include "ptapi/PtCallListener.h"#include "ptapi/PtPhoneButton.h"#include "ptapi/PtPhoneDisplay.h"#include "ptapi/PtPhoneGraphicDisplay.h"#include "ptapi/PtPhoneHookswitch.h"#include "ptapi/PtPhoneLamp.h"#include "ptapi/PtPhoneMicrophone.h"#include "ptapi/PtPhoneRinger.h"#include "ptapi/PtPhoneSpeaker.h"#include "ptapi/PtPhoneExtSpeaker.h"#include "ptapi/PtTerminalListener.h"#include "ptapi/PtComponent.h"#include "ptapi/PtComponentGroup.h"#include "ptapi/PtTerminalConnection.h"#include "tao/TaoClientTask.h"#include "tao/TaoServerTask.h"#include "tao/TaoEvent.h"#include "tao/TaoString.h"#include "tao/TaoObjectMap.h"#include "ps/PsTaoComponent.h"#include "ps/PsTaoComponentGroup.h"// EXTERNAL FUNCTIONS// EXTERNAL VARIABLES// CONSTANTS// STATIC VARIABLE INITIALIZATIONSOsBSem PtTerminal::semInit(OsBSem::Q_PRIORITY, OsBSem::FULL) ;TaoReference *PtTerminal::mpTransactionCnt = 0;TaoObjectMap *PtTerminal::mpComponents = 0;TaoObjectMap *PtTerminal::mpComponentGroups = 0;int PtTerminal::mRef = 0;/* //////////////////////////// PUBLIC //////////////////////////////////// *//* ============================ CREATORS ================================== */// Default ConstructorPtTerminal::PtTerminal() : mpClient(NULL){ initialize(NULL);}// Protected constructor.PtTerminal::PtTerminal(const char* name, TaoClientTask *pClient){ mpClient = pClient; if (mpClient && !(mpClient->isStarted())) { mpClient->start(); } initialize(name);}// Copy constructorPtTerminal::PtTerminal(const PtTerminal& rPtTerminal) : mpClient(NULL){ const char *name = NULL; if (rPtTerminal.mTerminalName[0]) { name = rPtTerminal.mTerminalName; } mpClient = rPtTerminal.mpClient; initialize(name);}// DestructorPtTerminal::~PtTerminal(){ semInit.acquire() ; mRef--; if (mRef < 1) { if (mpComponents) { int num = mpComponents->numEntries(); TaoObjHandle *objs; objs = new TaoObjHandle[num]; mpComponents->getActiveObjects(objs, num); for (int i = 0; i < num; i++) delete (PtComponent *) objs[i]; delete[] objs; delete mpComponents; mpComponents = 0; } if (mpComponentGroups) { int num = mpComponentGroups->numEntries(); TaoObjHandle *objs; objs = new TaoObjHandle[num]; mpComponentGroups->getActiveObjects(objs, num); for (int i = 0; i < num; i++) delete (PtComponentGroup *) objs[i]; delete[] objs; delete mpComponentGroups; mpComponentGroups = 0; } if (mpTransactionCnt) { delete mpTransactionCnt; mpTransactionCnt = 0; } } semInit.release() ;}/* ============================ MANIPULATORS ============================== */// Assignment operatorPtTerminal&PtTerminal::operator=(const PtTerminal& rhs){ if (this == &rhs) // handle the assignment to self case return *this; setName(rhs.mTerminalName); mpClient = rhs.mpClient; mTimeOut = rhs.mTimeOut; return *this;}PtStatus PtTerminal::addCallListener(PtCallListener& rCallListener){ if (!mpClient) { return PT_NOT_FOUND; } UtlString arg; UtlString local; rCallListener.getLocation(&local); arg = local.data() + TAOMESSAGE_DELIMITER + mTerminalName; unsigned int transactionId = mpTransactionCnt->add(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_TERMINAL, TaoMessage::ADD_CALL_LISTENER, transactionId, 0, //NULL (TaoObjHandle)pe, 2, arg); mpClient->sendRequest(msg); int rc; if (OS_SUCCESS != pe->wait(msg.getCmd(), mTimeOut)) { mpClient->resetConnectionSocket(msg.getMsgID()); // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == pe->signal(0)) { mpEventMgr->release(pe); } return PT_BUSY; } pe->getEventData((int &)rc);#ifdef PTAPI_TEST int cmd; pe->getIntData2(cmd); assert(cmd == TaoMessage::ADD_CALL_LISTENER);#endif mpEventMgr->release(pe); mpClient->addEventListener(&rCallListener); return PT_SUCCESS;}PtStatus PtTerminal::addTerminalListener(PtTerminalListener& rTerminalListener){ if (!mpClient) { return PT_NOT_FOUND; } int argCnt = 1; TaoObjHandle handle = (TaoObjHandle) &rTerminalListener; char buff[128]; UtlString name; UtlString arg; if (PT_SUCCESS == rTerminalListener.getTerminalName(buff, 127)) // must have the terminal name { name.append(buff); argCnt = 2; sprintf(buff, "%d", handle); arg = name + TAOMESSAGE_DELIMITER + buff; } mpTransactionCnt->add(); unsigned int transactionId = mpTransactionCnt->getRef(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_TERMINAL, TaoMessage::ADD_TERM_LISTENER, transactionId, 0, //NULL (TaoObjHandle)pe, argCnt, arg); mpClient->sendRequest(msg); int rc; if (OS_SUCCESS != pe->wait(msg.getCmd(), mTimeOut)) { mpClient->resetConnectionSocket(msg.getMsgID()); // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == pe->signal(0)) { mpEventMgr->release(pe); } return PT_BUSY; } pe->getEventData((int &)rc);#ifdef PTAPI_TEST int cmd; pe->getIntData2(cmd); assert(cmd == TaoMessage::ADD_TERM_LISTENER);#endif mpEventMgr->release(pe); mpClient->addEventListener(&rTerminalListener); return PT_SUCCESS;}/*** getAddresses() basically does the same thing as* PtProvider:getAddresses() in this implementation.* It returns the user lines as addresses.*/PtStatus PtTerminal::getAddresses(PtAddress arAddresses[], int size, int& nItems){ if (!mpClient) { return PT_NOT_FOUND; } char buff[MAXIMUM_INTEGER_STRING_LENGTH]; sprintf(buff, "%d", size); UtlString arg(buff); mpTransactionCnt->add(); unsigned int transactionId = mpTransactionCnt->getRef(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_TERMINAL, TaoMessage::GET_ADDRESSES, transactionId, 0, (TaoObjHandle)pe, 1, arg); mpClient->sendRequest(msg); if (OS_SUCCESS != pe->wait(msg.getCmd(), mTimeOut)) { mpClient->resetConnectionSocket(msg.getMsgID()); // If the event has already been signalled, clean up if(OS_ALREADY_SIGNALED == pe->signal(0)) { mpEventMgr->release(pe); } return PT_BUSY; } pe->getEventData(nItems); pe->getStringData((UtlString &)arg);#ifdef PTAPI_TEST int cmd; pe->getIntData2(cmd); assert(cmd == TaoMessage::GET_ADDRESSES);#endif mpEventMgr->release(pe); int actual = ((size < nItems) ? size : nItems); TaoString taoStr(arg, TAOMESSAGE_DELIMITER); for (int i = 0; i < actual; i++) { arAddresses[i] = PtAddress(mpClient, taoStr[i]); } return PT_SUCCESS;}PtStatus PtTerminal::getCallListeners(PtCallListener aCallListeners[], int size, int& nItems){ if (!mpClient)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?