示例#1
0
CNetCom* CNetMgr::AddSession( const GUID *guidId, CNetCom* pNc )
{_STT();
	if ( pNc == NULL ) return FALSE;

	{ // Lock scope
	
		// Acquire lock
		CTlLocalLock ll( *this );
		if ( !ll.IsLocked() ) return NULL;

		// Set the connection id
		pNc->Tx()->SetConnectionId( guidId );

		// Set global description if applicable
		if ( m_sGlobalDescription.size() )
			pNc->Tx()->SetConnectionDescription( m_sGlobalDescription );

		// Save session pointer into list	
		m_lstSession.push_back( *( (GUID*)guidId ), pNc );

	} // End lock scope

	// Notify of new node
	MMessage( NetCmd::efNodeAdded, (LPARAM)this, &NetCmd::IID );

	// Return a pointer to the session object
	return pNc;
}
示例#2
0
BOOL CNetCmd::NotifyDisconnect(long lError)
{_STT();
	// Save error code
	m_lError = lError;

	// Dispatch the message to interested parties
	return MMessage( NetCmd::efDisconnect, (LPARAM)this, &NetCmd::IID );
}
示例#3
0
文件: NetMgr.cpp 项目: aminsyed/rulib
THList< GUID, CNetCom>::iterator CNetMgr::RemoveNode( THList< GUID, CNetCom>::iterator itNode )
{_STT();
	// Acquire lock
	CTlLocalLock ll( *this );
	if ( !ll.IsLocked() ) return NULL;
	
	// Erase this session
	THList< GUID, CNetCom>::iterator itPrev = m_lstSession.erase( itNode );

	// Notify of node change
	MMessage( NetCmd::efNodeRemoved, (LPARAM)this, &NetCmd::IID );

	return itPrev;
}
示例#4
0
文件: NetMgr.cpp 项目: aminsyed/rulib
long CNetMgr::OnNetMsg(WPARAM wParam, LPARAM lParam, const GUID *pGuid)
{_STT();
	CNetCom *pNc = (CNetCom*)lParam;
	if ( pNc == NULL ) return E_FAIL;

	// Authenticate the connection
	if ( !OnAuthenticate( pNc ) ) return E_FAIL;
	
	// Hook NetCmd messages
	if ( pGuid != NULL && IsEqualGUID( NetCmd::IID, *pGuid ) )
	{
		// Save network error if any
		if ( pNc->GetNetError() )
			SetNetError( pNc->GetNetError() );

		// Cleanup if node is disconnecting
		// +++ This doesn't work because it causes the calling 
		// class to delete itself.  For now, Cleanup() must be 
		// called from the outside.  This is just to remind me 
		// to come up with something.
//		if ( wParam == NetCmd::efDisconnect ) Cleanup();

	} // end if

	// Check for update request
	if ( ( wParam & CNetMsg::fWantUpdate ) != 0 )
	{	AddUpdateNotification(	pNc->Tx()->GetConnectionId(), pGuid, 
								wParam & CNetMsg::fMask );

	} // end if

	// Check for remove notification command
	if ( ( wParam & CNetMsg::fCancelUpdate ) != 0 )
	{	RemoveUpdateNotification(	pNc->Tx()->GetConnectionId(), pGuid, 
									wParam & CNetMsg::fMask );

		// Don't process this message
		return S_OK;

	} // end if

	// Turn off internal flags
	wParam &= CNetMsg::fCmdMask;
	pNc->SMsg().dwFunction &= CNetMsg::fCmdMask;

	// Pass on the message
	return MMessage( wParam, lParam, pGuid );
}
示例#5
0
BOOL CNetCom::OnRx()
{_STT();

	// Read dst
	if ( !m_prx->ReadPacketData( 0, NETMSGDT_DSTADDRESS, &m_conn.addrNext, sizeof( m_conn.addrNext ) ) )
		return FALSE;

	// Read src
	if ( !m_prx->ReadPacketData( 0, NETMSGDT_SRCADDRESS, &m_conn.addrThis, sizeof( m_conn.addrThis ) ) )
		return FALSE;
		
	// Read message data
	if ( !m_prx->ReadPacketData( 0, NETMSGDT_MSG, &m_msg, sizeof( m_msg ) ) )
		return FALSE;

	// Authenticate the connection
	if ( !OnRxAuthenticate( &m_conn.addrNext.guidNode, &m_conn.addrNext.guidClass, m_msg.dwFunction ) ) 
		return FALSE;

	// Hook NetCmd messages
	if ( IsEqualGUID( NetCmd::IID, m_conn.addrNext.guidClass ) )
	{
		// Look for remote information packet
		if ( m_msg.dwFunction == NetCmd::efGetConnectionInfo )
		{
			// Send connection information
			Msg( NULL, &NetCmd::IID, CNetMsg::fReply | NetCmd::efGetConnectionInfo, NULL,
					1, 1, m_ptx->GetConnectionDescription(), 0 );

		} // end if

		// Look for remote information packet
		else if ( m_msg.dwFunction == ( CNetMsg::fReply | NetCmd::efGetConnectionInfo ) )
		{
			// Read remote information
			char szDescription[ 512 ];
			if ( m_prx->ReadPacketString( 0, 1, szDescription, sizeof( szDescription ) ) )
				m_prx->SetConnectionDescription( szDescription );

		} // end if

	} // end if

	// Dispatch the message to interested parties
	return MMessage( m_msg.dwFunction, (LPARAM)this, &m_conn.addrNext.guidClass );
}
示例#6
0
BOOL CNetCmd::LocalMsg(const GUID *pguidClass, DWORD dwFunction)
{_STT();
	// Dispatch the message to interested parties
	return MMessage( dwFunction, (LPARAM)this, pguidClass );
}