?? ptaddress.cpp
字號:
//// Copyright (C) 2004, 2005 Pingtel Corp.// //// $$//////////////////////////////////////////////////////////////////////////////// SYSTEM INCLUDES#include <assert.h>// APPLICATION INCLUDES#include "ptapi/PtAddress.h"#include "ptapi/PtTerminal.h"#include "ptapi/PtAddressForwarding.h"#include "tao/TaoReference.h"#include "tao/TaoClientTask.h"#include "tao/TaoServerTask.h"#include "tao/TaoEvent.h"#include "tao/TaoString.h"// EXTERNAL FUNCTIONS// EXTERNAL VARIABLES// CONSTANTS// STATIC VARIABLE INITIALIZATIONSOsBSem PtAddress::semInit(OsBSem::Q_PRIORITY, OsBSem::FULL) ;TaoReference *PtAddress::mpTransactionCnt = 0;unsigned int PtAddress::mRef = 0;PtAddressForwarding *PtAddress::mpAddressForwards = 0;int PtAddress::mAddressForwardCnt = 0;OsBSem PtAddress::mAddressForwardDbSem(OsBSem::Q_PRIORITY, OsBSem::FULL);PtBoolean PtAddress::mbMessageWaiting = FALSE;PtBoolean PtAddress::mbDoNotDisturb = FALSE;int PtAddress::mOfferedTimeout = 0;/* //////////////////////////// PUBLIC //////////////////////////////////// *//* ============================ CREATORS ================================== */// ConstructorPtAddress::PtAddress(){ mpClient = 0; mpEventMgr = OsProtectEventMgr::getEventMgr(); initialize();}PtAddress::PtAddress(TaoClientTask *pClient, const char* name){ mpClient = pClient; if (name) mAddress = name; mpEventMgr = OsProtectEventMgr::getEventMgr(); initialize();}// Copy constructorPtAddress::PtAddress(const PtAddress& rPtAddress){ mAddress = rPtAddress.mAddress; mpClient = rPtAddress.mpClient; mpTransactionCnt = rPtAddress.mpTransactionCnt; mpAddressForwards = rPtAddress.mpAddressForwards ; mAddressForwardCnt = rPtAddress.mAddressForwardCnt ; mpEventMgr = OsProtectEventMgr::getEventMgr(); initialize();}PtAddress::PtAddress(const char* address){ if (address) mAddress = address; mpClient = 0; mpEventMgr = OsProtectEventMgr::getEventMgr(); initialize();}PtAddress::PtAddress(PtProvider *pProvider, const char* address){ if (address) mAddress = address; mpClient = 0; mpEventMgr = OsProtectEventMgr::getEventMgr(); initialize();}// DestructorPtAddress::~PtAddress(){ semInit.acquire() ; mRef--; if (mRef < 1) { if (!mpTransactionCnt) { delete mpTransactionCnt; mpTransactionCnt = 0; } if (!mpAddressForwards) { mAddressForwardDbSem.acquire(); delete[] mpAddressForwards; mpAddressForwards = 0; mAddressForwardCnt = 0; mAddressForwardDbSem.release(); } } semInit.release() ;}void PtAddress::initialize(){ mTimeOut = OsTime(PT_CONST_EVENT_WAIT_TIMEOUT, 0); semInit.acquire() ; mRef++; if (!mpTransactionCnt) mpTransactionCnt = new TaoReference(); if (mpClient && !(mpClient->isStarted())) { mpClient->start(); } semInit.release() ;}/* ============================ MANIPULATORS ============================== */// Assignment operatorPtAddress&PtAddress::operator=(const PtAddress& rhs){ if (this == &rhs) // handle the assignment to self case return *this; mAddress = rhs.mAddress; mpTransactionCnt = rhs.mpTransactionCnt; mpClient = rhs.mpClient; mpAddressForwards = rhs.mpAddressForwards ; mAddressForwardCnt = rhs.mAddressForwardCnt ; // initialize(); return *this;}PtStatus PtAddress::addAddressListener(PtAddressListener& rAddressListener){ TaoObjHandle handle = (TaoObjHandle)&rAddressListener; char buff[MAXIMUM_INTEGER_STRING_LENGTH]; sprintf(buff, "%d", handle); UtlString arg(buff); mpTransactionCnt->add(); unsigned int transactionId = mpTransactionCnt->getRef(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_ADDRESS, TaoMessage::ADD_ADDRESS_LISTENER, transactionId, 0, (TaoObjHandle)pe, 1, 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_ADDRESS_LISTENER);#endif mpEventMgr->release(pe); return PT_SUCCESS;}PtStatus PtAddress::addCallListener(PtCallListener& rCallListener){ TaoObjHandle handle = (TaoObjHandle)&rCallListener; char buff[MAXIMUM_INTEGER_STRING_LENGTH]; sprintf(buff, "%d", handle); UtlString arg(buff); mpTransactionCnt->add(); unsigned int transactionId = mpTransactionCnt->getRef(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_ADDRESS, TaoMessage::ADD_CALL_LISTENER, transactionId, 0, (TaoObjHandle)pe, 1, 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); return PT_SUCCESS;}PtStatus PtAddress::cancelForwarding(){ mpTransactionCnt->add(); unsigned int transactionId = mpTransactionCnt->getRef(); OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_ADDRESS, TaoMessage::CANCEL_ALL_FORWARDING, transactionId, 0, (TaoObjHandle)pe, 0, ""); 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::CANCEL_ALL_FORWARDING);#endif mpEventMgr->release(pe); mAddressForwardDbSem.acquire(); if (mpAddressForwards) { delete[] mpAddressForwards; mpAddressForwards = 0; } mAddressForwardCnt = 0; mAddressForwardDbSem.release(); return PT_SUCCESS;}PtStatus PtAddress::cancelForwarding(PtAddressForwarding forwards[], int size){ char buff[MAXIMUM_INTEGER_STRING_LENGTH]; sprintf(buff, "%d", size); UtlString arg(buff); osPrintf("PtAddress::cancelForwarding(size=%d)\n", size) ; int i; for (i = 0; i < size; i++) { osPrintf("%02d: type=%d filter=%d, url=%s, caller=%s\n", i, forwards[i].mForwardingType, forwards[i].mFilterType, forwards[i].mDestinationUrl.data(), forwards[i].mCallerUrl.data()) ; sprintf(buff, "%d", forwards[i].mForwardingType); arg += TAOMESSAGE_DELIMITER + UtlString(buff); sprintf(buff, "%d", forwards[i].mFilterType); arg += TAOMESSAGE_DELIMITER + UtlString(buff); arg += TAOMESSAGE_DELIMITER + forwards[i].mDestinationUrl + TAOMESSAGE_DELIMITER + forwards[i].mCallerUrl; sprintf(buff, "%d", forwards[i].mNoAnswerTimeout); arg += TAOMESSAGE_DELIMITER + UtlString(buff); } unsigned int transactionId = 0; if (mpTransactionCnt) { mpTransactionCnt->add(); transactionId = mpTransactionCnt->getRef(); } else { // I HAVE NO IDEA WHAT THIS IS ABOUT, BUT THE FORMAT IS WRONG!!! // And, we only got here because mpTransactionCnt is NULL. osPrintf("\nPtAddress::cancelForwarding - mpTransactionCnt = %p\n", mpTransactionCnt); } OsProtectedEvent *pe = mpEventMgr->alloc(); TaoMessage msg(TaoMessage::REQUEST_ADDRESS,TaoMessage::CANCEL_FORWARDING, transactionId, 0, (TaoObjHandle)pe, (5 * size + 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; } int rc; pe->getEventData((int &)rc);#ifdef PTAPI_TEST int cmd; pe->getIntData2(cmd); assert(cmd == TaoMessage::CANCEL_FORWARDING);#endif mpEventMgr->release(pe); mAddressForwardDbSem.acquire(); if (mpAddressForwards) { for (i = 0; i < size; i++) { for (int j = 0; j < mAddressForwardCnt; j++) { if (forwards[i] == (PtAddressForwarding&) mpAddressForwards[j]) { mAddressForwardCnt--; for (int k = j; k < mAddressForwardCnt; k++) mpAddressForwards[k] = mpAddressForwards[k + 1]; break; } } } if (mAddressForwardCnt <= 0) { delete[] mpAddressForwards; mpAddressForwards = 0; mAddressForwardCnt = 0; } } mAddressForwardDbSem.release();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -