mozilla::ipc::IPCResult
DocAccessibleParent::RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID)
{
  // One document should never directly be the child of another.
  // We should always have at least an outer doc accessible in between.
  MOZ_ASSERT(aID);
  if (!aID)
    return IPC_FAIL(this, "ID is 0!");

  if (mShutdown) {
    return IPC_OK();
  }

  MOZ_ASSERT(CheckDocTree());

  auto childDoc = static_cast<DocAccessibleParent*>(aChildDoc);
  childDoc->Unbind();
  ipc::IPCResult result = AddChildDoc(childDoc, aID, false);
  MOZ_ASSERT(result);
  MOZ_ASSERT(CheckDocTree());
#ifdef DEBUG
  if (!result) {
    return result;
  }
#else
  result = IPC_OK();
#endif

  return result;
}
bool
DocAccessibleParent::RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID)
{
  auto childDoc = static_cast<DocAccessibleParent*>(aChildDoc);
  DebugOnly<bool> result = AddChildDoc(childDoc, aID, false);
  MOZ_ASSERT(result);
  return true;
}
bool
DocAccessibleParent::RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID)
{
  // One document should never directly be the child of another.
  // We should always have at least an outer doc accessible in between.
  MOZ_ASSERT(aID);
  if (!aID)
    return false;

  MOZ_DIAGNOSTIC_ASSERT(CheckDocTree());

  auto childDoc = static_cast<DocAccessibleParent*>(aChildDoc);
  childDoc->Unbind();
  bool result = AddChildDoc(childDoc, aID, false);
  MOZ_ASSERT(result);
  MOZ_DIAGNOSTIC_ASSERT(CheckDocTree());
  return result;
}
//*=================================================================================
//*原型: void TSmartServer::InitSmartDocList()
//*功能: 初始化设备档案信息
//*参数: 无
//*返回: 无
//*说明: 前置采集服务器类
//*=================================================================================
void TSmartServer::InitSmartDocList()
{
	TSSmartDoc *pSmartDoc = NULL;
	long nRecCount = 0 ;
	
	m_DocList.Clear();

	try
	{
		pSmartDoc = new TSSmartDoc[MAX_SMART_DOC];
		if( pSmartDoc == NULL )
		{
			ReportLog("不能读入设备档案表!请检查数据库连接与业务层是否正确!");
			return ;
		}

		ZeroMemory(pSmartDoc, sizeof(TSSmartDoc)*MAX_SMART_DOC);

		if( !m_Channels.ReadSmartDoc(pSmartDoc, &nRecCount) )
		{
			delete [] pSmartDoc;
			ReportLog("不能读入设备档案表!请检查数据库连接与业务层是否正确!");
			return ;
		}

		if( nRecCount <= 0 )
		{
			delete [] pSmartDoc;
			ReportLog("警告: 没有任何设备档案信息!");
			return ;
		}
		printf("-----------设备档案信息----------\n");
		for(long mm=0;mm<nRecCount;mm++)
		{
			printf("授权号			= %.8X\n",pSmartDoc[mm].m_nAuthID);
			printf("ID号			= %s\n",pSmartDoc[mm].m_szDeviceID);
			printf("服务器端口总数	= %d\n",pSmartDoc[mm].m_nPortCount);
			printf("服务器端口号	= %d\n",pSmartDoc[mm].m_nSMTPort);
			printf("设备级联级数	= %d\n",pSmartDoc[mm].m_nLevel);
			printf("设备级联参数	= %s\n",pSmartDoc[mm].m_szLevelArray);
			Sleep(50);
		}
		long  k = 0 ;
		for(long i=0; i<nRecCount; i++) 
		{
			TSmartDocObj *pObj = CreateSmartDoc(&pSmartDoc[i]);
			if( pObj != NULL )
			{
				printf("i= %d pObj->m_szDeviceID=%.8X\n",i,pObj->m_nAuthID);  
				pObj->SetServer(this);
				pObj->AssignBy(&pSmartDoc[i]);
				AddChildDoc(pObj, pSmartDoc, nRecCount);

				//没有父设备, 有可能是总线上的设备
				if( pObj->IsParent() )
				{
					long iIndex = FindBusFromDocList(pObj);
					if( iIndex >= 0 )
					{
						TSmartDocObj *pBus = (TSmartDocObj*)m_DocList.Get(iIndex);
						pObj->SetShare(*pBus);
					}
					else
					{
						iIndex = FindBusFromDocArray(pSmartDoc, i, nRecCount);
						if( iIndex >= 0 )
						{
							pObj->SetFirstShare();
						}
					}
				}

				try
				{
					pObj->Start();
					m_DocList.Add(pObj);
					k++;
				}
				catch(TException& e)
				{
					OnError((char*)e.GetText());
					delete pObj;
				}
			}
		}

		if( !k )
		{
			ReportLog("没有任务终端设备被加入!");
		}

		if( pSmartDoc != NULL )
		{
			delete [] pSmartDoc;
			pSmartDoc = NULL ;
		}
	}
	catch(...)
	{
		if( pSmartDoc != NULL )
			delete [] pSmartDoc;

		OnError("读入设备档案表异常! 请检查业务模块是否正确!");
	}
}