📄 detectcfg.cpp
字号:
/**********@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********************************
* DIALOGIC CONFIDENTIAL
*
* Copyright (C) 2006-2007 Dialogic Corporation. All Rights Reserved.
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Dialogic Corporation or its
* suppliers or licensors. Title to the Material remains with Dialogic Corporation
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Dialogic or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Dialogic's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Dialogic in writing.
*
***********************************@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********/
//***********************************************************************
//***********************************************************************
// DetectCfg.cpp: implementation of the CDetectCfg class.
//
//////////////////////////////////////////////////////////////////////
#include "pdl.h"
# ifdef WIN32
# include <WinSock.h>
# include <NCMApi.h>
# include <NCMTypes.h>
# else
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
# include <iostream>
# include <dasi.h>
# endif
static const char *CFG_MODULE_NAME = "CDetectCfg";
//*****************************************************************************
// Purpose :
// CDetectInet constructor
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
CDetectInet::CDetectInet(){
*m_host_name = 0;
m_host_addr = 0;
int rc = gethostname(m_host_name, sizeof(m_host_name));
if (rc != 0){
GLBLOG(LOG_ERR1,CFG_MODULE_NAME,
"%d = gethostname('%s', %d)",
rc, m_host_name, sizeof(m_host_name));
}else {
hostent * hent = gethostbyname(m_host_name);
if (hent == 0) {
GLBLOG(LOG_ERR1,CFG_MODULE_NAME,
"0 = gethostbyname('%s')",
m_host_name);
}else {
if (hent->h_length == 0){
GLBLOG(LOG_ERR1,CFG_MODULE_NAME,
"hostent *hent = gethostbyname('%s'); hent->h_length = 0",
m_host_name);
}else {
struct in_addr addr;
memcpy(&addr,hent->h_addr_list[0],4);
str_storestring(&m_host_addr,
inet_ntoa(addr));
GLBLOG(LOG_DBG, CFG_MODULE_NAME, "HostName = %s", m_host_name);
GLBLOG(LOG_DBG, CFG_MODULE_NAME, "HostAddr = %s", m_host_addr);
} // hent->length
} // hent != 0
} // GetHostName
}
//*****************************************************************************
// Purpose :
// Dump names of all detected devices
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
void CDetectCfg::Dump(){
GLBLOG(LOG_APP, CFG_MODULE_NAME, "=== Detected Configuration ===");
m_DxxDevices.Dump();
m_DtiDevices.Dump();
m_IpmDevices.Dump();
m_CnfBoards.Dump();
m_IptDevices.Dump();
return;
} // End of Dump()
//*****************************************************************************
// Purpose :
// Dump number of detected devices (by type)
// Parameters:
// none
// Returns:
// none
//*****************************************************************************
void CDetectCfg::DumpSize(){
GLBLOG(LOG_DBG, CFG_MODULE_NAME, "=== Detected Configuration ===");
GLBLOG(LOG_DBG, CFG_MODULE_NAME, " %s: %4u devices",
m_DxxDevices.GetName(),
m_DxxDevices.ReservedSize() + m_DxxDevices.UnReservedSize());
GLBLOG(LOG_DBG, CFG_MODULE_NAME, " %s: %4u timeslots",
m_DtiDevices.GetName(),
m_DtiDevices.ReservedSize() + m_DtiDevices.UnReservedSize());
GLBLOG(LOG_DBG, CFG_MODULE_NAME, " %s: %4u devices",
m_IpmDevices.GetName(),
m_IpmDevices.ReservedSize() + m_IpmDevices.UnReservedSize());
GLBLOG(LOG_DBG, CFG_MODULE_NAME, " %s: %4u devices",
m_IptDevices.GetName(),
m_IptDevices.ReservedSize() + m_IptDevices.UnReservedSize());
GLBLOG(LOG_DBG, CFG_MODULE_NAME, " %s: %4u boards",
m_CnfBoards.GetName(),
m_CnfBoards.ReservedSize() + m_CnfBoards.UnReservedSize());
return;
} // End of DumpSize()
//*****************************************************************************
// Purpose :
// Get Number of available devices of given type
// Parameters:
// [int] type
// Returns:
// number of devices
// 0 if not found or invalid type
//*****************************************************************************
size_t CDetectCfg::GetNumberOf(DLG_DEVICE_TYPE type){
size_t ret = 0;
switch (type){
case DEV_DX:
ret = m_DxxDevices.GetSize();
break;
case DEV_IPM:
ret = m_IpmDevices.GetSize();
break;
case DEV_DTI:
ret = m_DtiDevices.GetSize();
break;
case DEV_IPT:
ret = m_IptDevices.GetSize();
break;
case DEV_CNFBOARD:
ret = m_CnfBoards.GetSize();
break;
case DEV_CNFCONFERENCE:
case DEV_CNFPARTY:
// Party and Conferenve names are not known before open,
// Return 0
ret = 0;
break;
case DEV_REST:
ret = m_OtherDevices.GetSize();
break;
// just for the records and to make g++ happy:
case DEV_NONE:
ret = 0;
break;
} // switch type
return ret;
} // End of GetNumberOf()
//*****************************************************************************
// Purpose :
// Declare device in use (don't allow other object to Reserve)
// Parameters:
// [in] device type
// [in/out] device name (pass 0 to reserve ANY available )
// pass 0 means:
// const char *name = 0;
// Pass &name;
// Returns:
// true success, false if not found
//*****************************************************************************
bool CDetectCfg::Reserve(DLG_DEVICE_TYPE type, const char **name){
bool brc = false;
switch (type){
case DEV_NONE:
brc = true;
*name = "Container";
break;
case DEV_DX:
brc = m_DxxDevices.Reserve(name);
break;
case DEV_IPM:
brc = m_IpmDevices.Reserve(name);
break;
case DEV_DTI:
brc = m_DtiDevices.Reserve(name);
break;
case DEV_IPT:
brc = m_IptDevices.Reserve(name);
break;
case DEV_CNFBOARD:
brc = m_CnfBoards.Reserve(name);
break;
case DEV_CNFCONFERENCE:
case DEV_CNFPARTY:
// Party and Conferenve names are not known before open,
// Return NULL name
*name = 0;
brc = true;
break;
case DEV_REST:
brc = m_OtherDevices.Reserve(name);
break;
default:
GLBLOG(LOG_ERR1, CFG_MODULE_NAME, "Reserve:: cannot handle device type %d, see DLG_DEVICE_TYPE in DetectCfg.h", type);
brc = false;
break;
} // switch type
return brc;
} // End of Reserve()
//*****************************************************************************
// Purpose :
// Declare device is not in use (allow other object to Reserve)
// Parameters:
// [in] device type
// [in] and device name
// Returns:
// true success, false if not reserved
//*****************************************************************************
bool CDetectCfg::UnReserve(DLG_DEVICE_TYPE type, const char *name){
bool brc = false;
switch (type){
case DEV_NONE:
brc = true;
break;
case DEV_DX:
brc = m_DxxDevices.UnReserve(name);
break;
case DEV_IPM:
brc = m_IpmDevices.UnReserve(name);
break;
case DEV_IPT:
brc = m_IptDevices.UnReserve(name);
break;
case DEV_CNFBOARD:
brc = m_CnfBoards.UnReserve(name);
break;
case DEV_CNFCONFERENCE:
case DEV_CNFPARTY:
brc = true;
break;
case DEV_DTI:
brc = m_DtiDevices.UnReserve(name);
break;
case DEV_REST:
brc = m_OtherDevices.UnReserve(name);
break;
default:
GLBLOG(LOG_ERR1, CFG_MODULE_NAME, "Reserve:: cannot handle device type %d, see DLG_DEVICE_TYPE in DetectCfg.h", type);
brc = false;
break;
} // switch type
return brc;
} // End of UnReserve()
//*****************************************************************************
// Purpose :
// Declare all devices from given type are not in use (allow other object to Reserve)
// Parameters:
// [in] device type
// Returns:
// true success, false if not reserved
//*****************************************************************************
bool CDetectCfg::UnReserve(DLG_DEVICE_TYPE type){
bool brc = false;
switch (type){
case DEV_NONE:
brc = true;
break;
case DEV_DX:
brc = m_DxxDevices.UnReserve();
break;
case DEV_IPM:
brc = m_IpmDevices.UnReserve();
break;
case DEV_CNFBOARD:
brc = m_CnfBoards.UnReserve();
break;
case DEV_CNFCONFERENCE:
case DEV_CNFPARTY:
brc = true;
break;
case DEV_IPT:
brc = m_IptDevices.UnReserve();
break;
case DEV_DTI:
brc = m_DtiDevices.UnReserve();
break;
case DEV_REST:
brc = m_OtherDevices.UnReserve();
break;
default:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -