Exemple #1
0
struct state* CMailChannel::RcvFxByte_cmplt(EVTBLK *evtblk)
{
	int nChan = evtblk->nReference;
	
	if ( evtblk->wEventCode == E_PROC_PlayEnd )
	{
		UsrLvFax   = MakeUsrFaxFile( "tif" );
		
		CChannel* pChannel = Network.FindChannel( m_nTaskId );
		if ( ! pChannel ) throw "Invalid channel";
		
		if ( pChannel->RecordFax( UsrLvFax, NULL ) )
		{
			CHAR sError[1024];
			SsmGetLastErrMsg( sError );
			theApp.Message( MSG_ERROR, sError );
		}
	}
///////////////////////////	
	if ( evtblk->wEventCode == E_PROC_FaxEnd )//&& m_bPending == TRUE )
	{
		if ( ! RepackFile( (LPCTSTR)UsrLvFax ) )
		{
			CHAR sError[1024];
			fBmp_GetErrMsg( sError );
			theApp.Message( MSG_ERROR, sError );
		}
		
		PutUsrRecord( UsrLvFax ); SetEvent( Traffic.m_pWakeup );
	}
	
	return ChkDTSignal( evtblk, &RcvFxByte );
}
Exemple #2
0
BOOL CNetwork::RunNeighbours()
{
	for ( POSITION posNext = m_pList.GetStartPosition(); posNext; )
	{
		CString xJobId;
		CChannel* pChannel;
		
		m_pList.GetNextAssoc( posNext, xJobId, (void*&)pChannel );
		ASSERT( pChannel != NULL );
		
		try
		{
			if ( pChannel ) pChannel->OnRun();
		}
		catch( CHAR* sError )
		{
			theApp.Message( MSG_ERROR, "error on channel %s: %s", xJobId, sError );
			return FALSE;
		}
#ifndef _DEBUG
		catch(_com_error e) 
		{ 
			theApp.Message( MSG_ERROR, "error on channel '%s': %s", xJobId, e.ErrorMessage() );
			return FALSE;
		}
		catch(...)
		{
			theApp.Message( MSG_ERROR, "error on channel '%s': %s", xJobId, "a fatal error" );
			return FALSE;
		}
#endif
	}
	
	return TRUE;
}
Exemple #3
0
CChannel* CCallerChannel::ReadOperUser(LPCTSTR xLocalId, LPCTSTR xOper)
{
	int nCount = 0; m_pUserWnd->IsWellAlived( &nCount );
	
	for ( CChannel* pChannel = m_pUserWnd->ReadItem( xLocalId ); pChannel && nCount > 0; nCount -- )
	{
		if ( _tcsicmp( xOper, pChannel->m_xFeeCode ) ) continue;
		
		if ( SsmGetChState( pChannel->m_nChan ) == S_CALL_STANDBY &&
			 pChannel->m_nTaskId == -1 )
		{
			SsmPutUserEvent( E_CHG_ChState, pChannel->m_nChan,
				MAKEVENT(m_nChan & 0xFFFF, S_CALL_RINGING) );
		}
		else
		{
			pChannel->SendPacket( new CRingPacket( RemoteId, LocalId, m_nChan ) );
//			pChannel->SendPacket( new CByePacket );
			SetTimer( 5 * 1000 );
		}
		
		return pChannel;
	}
	
	return NULL;
}
Exemple #4
0
void CShowVideo::Play(LPCTSTR strIp, LONG nPort, SHORT nNum)
{
	CRect rect;
	GetClientRect(&rect);
	CString url(strIp);
	int nBasePort = nPort;
	int nLoop = (int)sqrt((float)nNum);

	//
	m_strLog.Format(_T("控件Play,正在运行,rect=%d,%d,%d,%d"), rect.left, rect.right, rect.Width(),
		rect.Height());
	CWinLog::GetInstance()->WriteLog(m_strLog, emRunLog);

	int xGap = 0, yGap = 0;
	int width = rect.Width()-0;
	int height = rect.Height()-0;
	int x = rect.left + xGap;
	int y = rect.top + yGap;
	int video_width, audio_width = 40, video_height, audio_height;
	video_width = (width - (audio_width*nLoop + xGap*(nLoop + 1))) / nLoop;
	video_height = audio_height = (height - yGap*(nLoop + 1)) / nLoop;

	for (int i = 0; i < nLoop; ++i)
		for (int j = 0; j < nLoop; ++j)
		{
			CChannel* pchannel = NULL;

			pchannel = new CChannel(GetSafeHwnd()/*, i*/);

			int video_x = x + i%nLoop*(video_width + audio_width + xGap);
			int video_y = y + (i + j) % nLoop*(video_height + yGap);
			int audio_x = x + video_width + i%nLoop*(video_width + audio_width + xGap);
			int audio_y = video_y;
			pchannel->putVideoOrAudioRect(video_x, video_y, video_width, video_height, TRUE);//设置视频位置
			pchannel->putVideoOrAudioRect(audio_x, audio_y, audio_width, audio_height, FALSE);//设置音频位置
#if _DEBUG
			m_strLog.Format(_T("视频频位置,video_x:%d, video_y:%d, video_width:%d, video_height:%d"),
				video_x, video_y, video_width, video_height);
			CWinLog::GetInstance()->WriteLog(m_strLog, emRunLog);
			m_strLog.Format(_T("音频位置,audio_x:%d, audio_y:%d, audio_width:%d, audio_height:%d"),
				audio_x, audio_y, audio_width, audio_height);
			CWinLog::GetInstance()->WriteLog(m_strLog, emRunLog);
#endif
			
			BOOL bRet = pchannel->InitAV(url, nBasePort);
			if (!bRet)
			{
				delete pchannel;
				m_strLog.Format(_T("%s:%d 初始化InitAV失败"), url, nBasePort);
				CWinLog::GetInstance()->WriteLog(m_strLog, emErrorLog);
				continue;
			}
			//初始化成功,加入CChannel数组中
			m_vtrChannel.push_back(pchannel);
			++nBasePort;
		}
	m_strLog.Format(_T("控件Play,运行完毕,Channel size=%d"), m_vtrChannel.size());
	CWinLog::GetInstance()->WriteLog(m_strLog, emRunLog);
}
Exemple #5
0
void CXEPxibb::SendStreamData(const CJid& rJid, u16 localCid, u16 localSid, CBuffer* pBuffer)
{
	u16 remoteCid;
	u16 remoteSid;
	MutexOnChannelManager.Lock();

	try
	{
		// we are looking for the channelmanager associate to the Jid 
		
		CChannelManager* pChannelManager = GetChannelManager(rJid);
				
		if(pChannelManager == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_SENDSTREAMDATAERROR);
		
		// we are looking for the channel associate to the localCid
		CChannel* pChannel = pChannelManager->GetChannelByLocalCid(localCid);

		if(pChannel == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_SENDSTREAMDATAERROR);
				
		remoteCid = pChannel->GetRemoteCid();

		// we are looking for the stream associate to the localSid
		CStream* pStream = pChannel->GetStreamByLocalSid(localSid);

		if(pStream == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_SENDSTREAMDATAERROR);

		remoteSid = pStream->GetRemoteSid();
	}
	
	catch(exception& e)
	{
		MutexOnChannelManager.UnLock();
		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_SENDSTREAMDATAERROR);
	}
	
	MutexOnChannelManager.UnLock();

	CStreamDataStanza StreamDataStanza(rJid, remoteCid, remoteSid);

	CXMLNode* pData = StreamDataStanza.GetChild("stream-data");
	
	string data;
	CBase64 Base64;
	
	Base64.To64(pBuffer, data);
	pData->SetData(data.c_str(), data.size());

	if(!pXMPPCore->Send(&StreamDataStanza))
	throw CXEPxibbException(CXEPxibbException::XEPXEC_SENDSTREAMDATAERROR);
}
Exemple #6
0
int CPagerChannel::bkIdle_init(EVTBLK *evtblk)
{
	int nChan = evtblk->nReference;
	
	CChannel* pChannel = new CChannel( nChan );
	pChannel->Clone( this ); Network.SetChannel( pChannel );

	return (pChannel->*(pChannel->fcnp)->initiate)(evtblk);
}
Exemple #7
0
void CNetwork::Clear()
{
	for ( POSITION posNext = m_pList.GetStartPosition(); posNext; )
	{
		CString xJobId;
		CChannel* pChannel;
		
		m_pList.GetNextAssoc( posNext, xJobId, (void*&)pChannel );
		
		if ( pChannel ) pChannel->Release();
	}
}
Exemple #8
0
void* CXEPxibb::OnStreamCloseJob(void* pvThis) throw()
{
	CXEPxibb* pXEPxibb = (CXEPxibb*) pvThis;
	CStreamCloseHandler* pStreamCloseHandler = &(pXEPxibb->StreamCloseHandler);
	CXMPPCore* pXMPPCore = pXEPxibb->pXMPPCore;

	CStreamCloseStanza StreamCloseStanza;

	while(pXMPPCore->Receive(pStreamCloseHandler, &StreamCloseStanza))
	{
		pXEPxibb->MutexOnChannelManager.Lock();
		
		try
		{
			CChannelManager* pChannelManager = pXEPxibb->GetChannelManager(StreamCloseStanza.GetRemoteJid());

			if(pChannelManager != NULL)
			{
				CChannel* pChannel = pChannelManager->GetChannelByRemoteCid(StreamCloseStanza.GetChannelId());

				if(pChannel != NULL)
				{
					CStream* pStream = pChannel->GetStreamByRemoteSid(StreamCloseStanza.GetStreamId());
						
					if(pStream != NULL)
					{
						pXMPPCore->CommitHandler(pStream->GetStreamDataHandler());
						pChannel->RemoveStreamByRemoteSid(StreamCloseStanza.GetStreamId());
					}
				}
			}
		}
		
		catch(exception& e)
		{
			#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		}

		pXEPxibb->MutexOnChannelManager.UnLock();

		CIQResultStanza IQResultStanza;		
		IQResultStanza.SetTo(StreamCloseStanza.GetRemoteJid());
		IQResultStanza.SetId(StreamCloseStanza.GetId());
		 
		if(!pXMPPCore->Send(&IQResultStanza))
		return NULL;
	}
	
	return NULL;
}
Exemple #9
0
int CCallerChannel::bkIdle_init(EVTBLK *evtblk)
{
	int nChan = evtblk->nReference;
	
	KillLinker();
	SsmSetPlayDest( nChan, 0 );	// 取消上总线
	
	CChannel* pChannel = new CChannel( nChan );
	pChannel->Clone( this ); Network.SetChannel( pChannel );
	
	return (pChannel->*(pChannel->fcnp)->initiate)(evtblk);
}
Exemple #10
0
int OnRequestInitializeInt( LPSOCKETCONTEXT lpSockContext, char *cpPacket )
{
    CCoder					coder;
    CChannel				*pChannel = &Server.ch[lpSockContext->iChannel];
    CRoom					*pRoom;
    char					cPacket[32];
    int						iSize,
                            iNext;



#ifdef _LOGLEVEL3_
    DConsole.Output( "OnRequestInitializeInt(%d) : %d\n", lpSockContext->index,
                     lpSockContext->iChannel );
#endif

    // ---- 초기화 응답 ----
    coder.SetBuf( cPacket );
    coder.PutChar( lpSockContext->iChannel );		// 채널 번호
    coder.PutChar( Server.iMaxChannel );			// 최대 채널수
    coder.PutShort( pChannel->iUserNum + 1 );		// 채널에 있는 유저수
    iSize = coder.SetHeader( ANSWER_INITIALIZE );
    PostTcpSend( 1, (int *)&lpSockContext, cPacket, iSize );

    // ---- 룸 리스트 전달 ----
    OnNotifyRoomList( lpSockContext, NULL );

    // ---- 유저 리스트 전달 ----
    OnNotifyUserList( lpSockContext, NULL );

    // ---- 유저를 링크에 연결 ----
    pChannel->SetUserLink( lpSockContext->index );

    // ---- 유저 입장을 통지 ----
    coder.SetBuf( cPacket );
    coder.PutChar( 1 );	// userNum
    coder.PutChar( lpSockContext->idLen );
    coder.PutText( lpSockContext->cID, lpSockContext->idLen );
    coder.PutChar( WH_LOBBY ); // Where
    iSize = coder.SetHeader( NOTIFY_USERLIST );

    PostTcpSend( pChannel->iUserBegin, cPacket, iSize );
    iNext = pChannel->iUsedRoomBegin;
    while( iNext != NOTLINKED )
    {
        pRoom = &Server.rm[iNext];
        PostTcpSend( pRoom->iUserBegin, cPacket, iSize );
        iNext = Server.rn[iNext].next;
    }

    return 1;
}
Exemple #11
0
CFormListItemDlg *CMixereView::OnNewItem()
{
	// create channel as a modeless dialog
	CChannel	*Chan = new CChannel(*this);
	if (!Chan->Create(IDD_CHANNEL)) {
		delete Chan;
		return(NULL);
	}
	Chan->SetTitleFont(m_TitleFont);	// set channel's title font
	if (m_HasToolTips)					// optionally enable its tooltips
		Chan->EnableToolTips(TRUE);
	return(Chan);
}
Exemple #12
0
void CXEPxibb::ReceiveStreamData(const CJid& rJid, u16 localCid, u16 localSid, CBuffer* pBuffer)
{
	CStreamDataHandler* pStreamDataHandler;
	MutexOnChannelManager.Lock();

	try
	{
		// we are looking for the channelmanager associate to the Jid 		
		CChannelManager* pChannelManager = GetChannelManager(rJid);
				
		if(pChannelManager == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_RECEIVESTREAMDATAERROR);
		
		// we are looking for the channel associate to the localCid
		CChannel* pChannel = pChannelManager->GetChannelByLocalCid(localCid);

		if(pChannel == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_RECEIVESTREAMDATAERROR);

		// we are looking for the stream associate to the localSid
		CStream* pStream = pChannel->GetStreamByLocalSid(localSid);

		if(pStream == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_RECEIVESTREAMDATAERROR);

		pStreamDataHandler = pStream->GetStreamDataHandler();
	}
	
	catch(exception& e)
	{
		MutexOnChannelManager.UnLock();
		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_RECEIVESTREAMDATAERROR);
	}

	MutexOnChannelManager.UnLock();

	CStreamDataStanza StreamDataStanza;

	if(!pXMPPCore->Receive(pStreamDataHandler, &StreamDataStanza))
	throw CXEPxibbException(CXEPxibbException::XEPXEC_RECEIVESTREAMDATAERROR);
	
	CXMLNode* pData = StreamDataStanza.GetChild("stream-data");

	CBase64 Base64;		
	Base64.From64(pData->GetData(), pBuffer);
}
BOOL CNetworkMonitorBox::ProcessXML(POSITION posNext)
{
	CXMLElement* pXML = Profiles.FindProcess( NULL, posNext );
	if ( pXML == NULL ) return FALSE;
	
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CString strValue = pXML->GetAttributeValue( "Host" );
	
	if ( CChannel* pChannel = Network.FindChannel( strValue ) )
	{
		if ( pChannel->m_hSocket == INVALID_SOCKET && pChannel->TimeOut( 60 * 1000 ) ) 
		{
			CXMLAttribute* pAttri = pXML->GetAttribute( "Retry" );
			if ( ! pAttri ) pAttri = pXML->AddAttribute( "Retry" );
			
			if ( _ttoi( pAttri->GetValue() ) >= 2 )
			{
				AlarmToShortMessage( (LPCTSTR)strValue );
				strValue = pXML->GetAttributeValue( _T("Path") );
				RestartMachine( (LPCTSTR)strValue );
				
				pXML->DeleteAttribute( "Retry" );
			}
			else
			{
				strValue.Format( "%i", _ttoi( pAttri->GetValue() ) + 1 );
				pAttri->SetValue( (LPCTSTR)strValue );
				
				pChannel->LinkRestart();
				pChannel->m_tConnected	= GetTickCount();
			}
		}
		else
		if ( pChannel->IsConnected() )
		{
			pXML->DeleteAttribute( "Retry" );
		}
	}
	else
	{
		CChannel* pChannel = new CSentryChannel( pXML );
		Network.SetChannel( pChannel );
		
		pChannel->LinkRestart();
	}
	
	if ( posNext ) return ProcessXML( posNext );
	return TRUE;
}
Exemple #14
0
void CNeighbour::OnEchnPacket(IEchnPacket* pPacket)
{
	for ( POSITION posNext = GetIterator(); posNext; )
	{
		CChannel* pChannel = GetNext( posNext );
		if ( pPacket->ChNum < pChannel->m_nChan ) continue;
		
		for ( ; pChannel; pChannel = pChannel->m_pChNext )
		{
			if ( pPacket->ChNum != pChannel->m_nChan ) continue;
			pChannel->SetChState( pPacket->ChState );
		}
	}
}
BOOL CNetworkMonitorBox::ClearProcess(POSITION posNext)
{
	CXMLElement* pXML = Profiles.FindProcess( NULL, posNext );
	if ( pXML == NULL ) return FALSE;
	
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CString strValue = pXML->GetAttributeValue( "Host" );
	
	CChannel* pChannel = Network.FindChannel( strValue );
	if ( pChannel ) pChannel->Release();
	
	if ( posNext ) return ProcessXML( posNext );
	return TRUE;
}
Exemple #16
0
struct state* CCallerChannel::CallRemoteUser(LPCTSTR xRemoteId, LPCTSTR xCallerId, struct state* lpszDefaultState)
{
	CSettings::Item* pItem = Settings.GetSetting( _T("Trunk.TrunkFind") );
	
	CChannel* pChannel = Network.LookOutPcm( *pItem->m_pString );
	if ( pChannel == NULL ) return lpszDefaultState;
	
	CDialPacket* pPacket = new CDialPacket;
	pPacket->SetLocalId( "057496031" );	pPacket->SetRemoteId( xRemoteId );
	pPacket->SetCallerId( xCallerId );
	
	pChannel->OnDialPacket(pPacket); pPacket->Release();
	SetLinker( pChannel->m_nChan );
	
	return lpszDefaultState;
}
Exemple #17
0
struct state* CMailChannel::GetFxByte_cmplt(EVTBLK *evtblk)
{
	int nChan = evtblk->nReference;
	
	if ( evtblk->wEventCode == E_PROC_PlayEnd )
	{
		CChannel* pChannel = Network.FindChannel( m_nTaskId );
		if ( ! pChannel ) throw "Invalid channel";
		
		_variant_t TheValue = m_pRecordset->GetCollect( "xfaxpath" );
		pChannel->SendFax( (LPCTSTR)(_bstr_t)TheValue, NULL );
	}
	
	if ( evtblk->wEventCode == E_CHG_FaxPages && m_pRecordset != NULL )
	{
		m_pRecordset->PutCollect( "xstate", _variant_t("1") );
		
		COleDateTime tt = COleDateTime::GetCurrentTime();
		m_pRecordset->PutCollect( "xsenddate", _variant_t(tt) );
		
		m_pRecordset->Update();
		
		for ( m_pRecordset->MoveNext(); !m_pRecordset->adoEOF; m_pRecordset->MoveNext() )
		{
			CChannel* pChannel = Network.FindChannel( m_nTaskId );
			if ( ! pChannel ) throw "Invalid channel";
			
			_variant_t TheValue = m_pRecordset->GetCollect( "xfaxpath" );
			pChannel->SendFax( (LPCTSTR)(_bstr_t)TheValue, NULL, TRUE );
			
			m_pRecordset->PutCollect( "xstate", _variant_t("1") );
			
			COleDateTime tt = COleDateTime::GetCurrentTime();
			m_pRecordset->PutCollect( "xsenddate", _variant_t(tt) );
			
			m_pRecordset->Update();
		}
	}
	
	return ChkDTSignal( evtblk, &GetFxByte );
}
Exemple #18
0
void* CXEPxibb::OnPresenceJob(void* pvThis) throw()
{
	CXEPxibb* pXEPxibb = (CXEPxibb*) pvThis;
	CPresenceHandler* pPresenceHandler = &(pXEPxibb->PresenceHandler);
	CXMPPCore* pXMPPCore = pXEPxibb->pXMPPCore;

	CPresenceStanza PresenceStanza;

	while(pXMPPCore->Receive(pPresenceHandler, &PresenceStanza))
	{
		pXEPxibb->MutexOnChannelManager.Lock();
		
		try
		{
			CChannelManager* pChannelManager = pXEPxibb->GetChannelManager(PresenceStanza.GetFrom());

			if(pChannelManager != NULL)
			{
				for(u16 i = 0 ; i < pChannelManager->GetMaxChannel() ; i++)
				{
					CChannel* pChannel = pChannelManager->GetChannelByLocalCid(i);
					
					if(pChannel != NULL)
					{
						pXMPPCore->CommitHandler(pChannel->GetStreamOpenHandler());
						pXMPPCore->CommitHandler(pChannel->GetChannelDataHandler());
					
						for(u16 j = 0 ; j < pChannel->GetMaxStream() ; j++)
						{
							CStream* pStream = pChannel->GetStreamByLocalSid(j);
							
							if(pStream != NULL)
							{
								pXMPPCore->CommitHandler(pStream->GetStreamDataHandler());
								pChannel->RemoveStreamByLocalSid(j);
							}
						}
						
						pChannelManager->RemoveChannelByLocalCid(i);
					}
				}

				pXEPxibb->RemoveChannelManager(PresenceStanza.GetFrom());
			}
		}
		
		catch(exception& e)
		{
			#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		}
		
		pXEPxibb->MutexOnChannelManager.UnLock();
	}
	
	return NULL;
}
Exemple #19
0
BOOL CCircuitry::OnDialPacket(CDialPacket* pPacket)
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CHAR xRemoteId[MAX_PHONE + 1];
	xRemoteId[ pPacket->GetRemoteId( xRemoteId ) ] = '\0';
	
	CChannel* pChannel = Network.LookOutPhs( xRemoteId );
	if ( ! pChannel ) return SendPacket( new CErrPacket( ECore_Busy ) );
	
	int nChan = pChannel->m_nChan;
	SsmSetRecMixer( nChan, FALSE, 0 );
	SsmSetDTMFStopRecCharSet( nChan, "" );
	
	SsmSetDtmfStopPlay( nChan, FALSE );
	
	pChannel->OnDialPacket( pPacket );
	
	NewBuffer( nChan );
	Start( nChan );
	
	return TRUE;
}
Exemple #20
0
/**
 * ParseLineArgV
 *
 * Parses and processes a line which was sent by the server.
 *
 * @param argc number of tokens
 * @param argv the tokens
 */
bool CIRCConnection::ParseLineArgV(int argc, const char **argv) {
	CChannel *Channel;
	CClientConnection *Client;

	m_LastResponse = g_CurrentTime;

	if (argc < 2) {
		return true;
	}

	const char *Reply = argv[0];
	const char *Raw = argv[1];
	char *Nick = ::NickFromHostmask(Reply);
	int iRaw = atoi(Raw);

	bool b_Me = false;
	if (m_CurrentNick != NULL && Nick != NULL && strcasecmp(Nick, m_CurrentNick) == 0) {
		b_Me = true;
	}

	free(Nick);

	Client = GetOwner()->GetClientConnectionMultiplexer();

	// HASH values
	CHashCompare hashRaw(argv[1]);
	static CHashCompare hashPrivmsg("PRIVMSG");
	static CHashCompare hashNotice("NOTICE");
	static CHashCompare hashJoin("JOIN");
	static CHashCompare hashPart("PART");
	static CHashCompare hashKick("KICK");
	static CHashCompare hashNick("NICK");
	static CHashCompare hashQuit("QUIT");
	static CHashCompare hashMode("MODE");
	static CHashCompare hashTopic("TOPIC");
	static CHashCompare hashPong("PONG");
	// END of HASH values

	if (argc > 3 && iRaw == 433) {
		bool ReturnValue = ModuleEvent(argc, argv);

		if (ReturnValue) {
			if (GetCurrentNick() == NULL) {
				WriteLine("NICK :%s_", argv[3]);
			}

			if (m_NickCatchTimer == NULL) {
				m_NickCatchTimer = new CTimer(30, false, NickCatchTimer, this);
			}
		}

		return ReturnValue;
	} else if (argc > 3 && hashRaw == hashPrivmsg && Client == NULL) {
		const char *Host;
		const char *Dest = argv[2];
		char *Nick = ::NickFromHostmask(Reply);

		Channel = GetChannel(Dest);

		if (Channel != NULL) {
			CNick *User = Channel->GetNames()->Get(Nick);

			if (User != NULL) {
				User->SetIdleSince(g_CurrentTime);
			}

			Channel->AddBacklogLine(argv[0], argv[3]);
		}

		if (!ModuleEvent(argc, argv)) {
			free(Nick);
			return false;
		}

		/* don't log ctcp requests */
		if (argv[3][0] != '\1' && argv[3][strlen(argv[3]) - 1] != '\1' && Dest != NULL &&
				Nick != NULL && m_CurrentNick != NULL && strcasecmp(Dest, m_CurrentNick) == 0 &&
				strcasecmp(Nick, m_CurrentNick) != 0) {
			char *Dup;
			char *Delim;

			Dup = strdup(Reply);

			if (AllocFailed(Dup)) {
				free(Nick);

				return true;
			}

			Delim = strchr(Dup, '!');

			if (Delim != NULL) {
				*Delim = '\0';

				Host = Delim + 1;
			}

			GetOwner()->Log("%s (%s): %s", Dup, Delim ? Host : "<unknown host>", argv[3]);

			free(Dup);
		}

		free(Nick);

		UpdateHostHelper(Reply);

		return true;
	} else if (argc > 3 && hashRaw == hashPrivmsg && Client != NULL) {
		Channel = GetChannel(argv[2]);

		if (Channel != NULL) {
			Channel->AddBacklogLine(argv[0], argv[3]);
		}
	} else if (argc > 3 && hashRaw == hashNotice && Client == NULL) {
		const char *Dest = argv[2];
		char *Nick;
		
		if (!ModuleEvent(argc, argv)) {
			return false;
		}

		Nick = ::NickFromHostmask(Reply);

		/* don't log ctcp replies */
		if (argv[3][0] != '\1' && argv[3][strlen(argv[3]) - 1] != '\1' && Dest != NULL &&
				Nick != NULL && m_CurrentNick != NULL && strcasecmp(Dest, m_CurrentNick) == 0 &&
				strcasecmp(Nick, m_CurrentNick) != 0) {
			GetOwner()->Log("%s (notice): %s", Reply, argv[3]);
		}

		free(Nick);

		return true;
	} else if (argc > 2 && hashRaw == hashJoin) {
		if (b_Me) {
			AddChannel(argv[2]);

			/* GetOwner() can be NULL if AddChannel failed */
			if (GetOwner() != NULL && Client == NULL) {
				WriteLine("MODE %s", argv[2]);
			}
		}

		Channel = GetChannel(argv[2]);

		if (Channel != NULL) {
			Nick = NickFromHostmask(Reply);

			if (AllocFailed(Nick)) {
				return false;
			}

			Channel->AddUser(Nick, '\0');
			free(Nick);
		}

		UpdateHostHelper(Reply);
	} else if (argc > 2 && hashRaw == hashPart) {
		bool bRet = ModuleEvent(argc, argv);

		if (b_Me) {
			RemoveChannel(argv[2]);
		} else {
			Channel = GetChannel(argv[2]);

			if (Channel != NULL) {
				Nick = ::NickFromHostmask(Reply);

				if (AllocFailed(Nick)) {
					return false;
				}

				Channel->RemoveUser(Nick);

				free(Nick);
			}
		}

		UpdateHostHelper(Reply);

		return bRet;
	} else if (argc > 3 && hashRaw == hashKick) {
		bool bRet = ModuleEvent(argc, argv);

		if (m_CurrentNick != NULL && strcasecmp(argv[3], m_CurrentNick) == 0) {
			RemoveChannel(argv[2]);

			if (Client == NULL) {
				char *Dup = strdup(Reply);

				if (AllocFailed(Dup)) {
					return bRet;
				}

				char *Delim = strchr(Dup, '!');
				const char *Host = NULL;

				if (Delim) {
					*Delim = '\0';

					Host = Delim + 1;
				}

				GetOwner()->Log("%s (%s) kicked you from %s (%s)", Dup, Delim ? Host : "<unknown host>", argv[2], argc > 4 ? argv[4] : "");

				free(Dup);
			}
		} else {
			Channel = GetChannel(argv[2]);

			if (Channel != NULL) {
				Channel->RemoveUser(argv[3]);
			}
		}

		UpdateHostHelper(Reply);

		return bRet;
	} else if (argc > 2 && iRaw == 1) {
		if (Client != NULL) {
			if (strcmp(Client->GetNick(), argv[2]) != 0) {
				Client->WriteLine(":%s!%s NICK :%s", Client->GetNick(), m_Site ? m_Site : "*****@*****.**", argv[2]);
			}
		}

		free(m_CurrentNick);
		m_CurrentNick = strdup(argv[2]);

		free(m_Server);
		m_Server = strdup(Reply);
	} else if (argc > 2 && hashRaw == hashNick) {
		if (b_Me) {
			free(m_CurrentNick);
			m_CurrentNick = strdup(argv[2]);
		}

		Nick = NickFromHostmask(argv[0]);

		int i = 0;

		if (!b_Me && GetOwner()->GetClientConnectionMultiplexer() == NULL) {
			const char *AwayNick = GetOwner()->GetAwayNick();

			if (AwayNick != NULL && strcasecmp(AwayNick, Nick) == 0) {
				WriteLine("NICK %s", AwayNick);
			}
		}

		while (hash_t<CChannel *> *ChannelHash = m_Channels->Iterate(i++)) {
			ChannelHash->Value->RenameUser(Nick, argv[2]);
		}

		free(Nick);
	} else if (argc > 1 && hashRaw == hashQuit) {
		bool bRet = ModuleEvent(argc, argv);

		Nick = NickFromHostmask(argv[0]);

		int i = 0;

		while (hash_t<CChannel *> *ChannelHash = m_Channels->Iterate(i++)) {
			ChannelHash->Value->RemoveUser(Nick);
		}

		free(Nick);

		return bRet;
	} else if (argc > 1 && (iRaw == 422 || iRaw == 376)) {
		int DelayJoin = GetOwner()->GetDelayJoin();
		if (m_State != State_Connected) {
			const CVector<CModule *> *Modules = g_Bouncer->GetModules();

			for (int i = 0; i < Modules->GetLength(); i++) {
				(*Modules)[i]->ServerLogon(GetOwner()->GetUsername());
			}

			const char *ClientNick;

			if (Client != NULL) {
				ClientNick = Client->GetNick();

				if (strcmp(m_CurrentNick, ClientNick) != 0) {
					Client->ChangeNick(m_CurrentNick);
				}
			}

			GetOwner()->Log("You were successfully connected to an IRC server.");
			g_Bouncer->Log("User %s connected to an IRC server.",
				GetOwner()->GetUsername());
		}

		if (DelayJoin == 1) {
			m_DelayJoinTimer = g_Bouncer->CreateTimer(5, false, DelayJoinTimer, this);
		} else if (DelayJoin == 0) {
			JoinChannels();
		}

		if (Client == NULL) {
			bool AppendTS = (GetOwner()->GetConfig()->ReadInteger("user.ts") != 0);
			const char *AwayReason = GetOwner()->GetAwayText();

			if (AwayReason != NULL) {
				WriteLine(AppendTS ? "AWAY :%s (Away since the dawn of time)" : "AWAY :%s", AwayReason);
			}
		}

		const char *AutoModes = GetOwner()->GetAutoModes();
		const char *DropModes = GetOwner()->GetDropModes();

		if (AutoModes != NULL) {
			WriteLine("MODE %s +%s", GetCurrentNick(), AutoModes);
		}

		if (DropModes != NULL && Client == NULL) {
			WriteLine("MODE %s -%s", GetCurrentNick(), DropModes);
		}

		m_State = State_Connected;
	} else if (argc > 1 && strcasecmp(Reply, "ERROR") == 0) {
		if (strstr(Raw, "throttle") != NULL) {
			GetOwner()->ScheduleReconnect(120);
		} else {
			GetOwner()->ScheduleReconnect(5);
		}

		if (GetCurrentNick() != NULL && GetSite() != NULL) {
			g_Bouncer->LogUser(GetUser(), "Error received for user %s [%s!%s]: %s",
				GetOwner()->GetUsername(), GetCurrentNick(), GetSite(), argv[1]);
		} else {
			g_Bouncer->LogUser(GetUser(), "Error received for user %s: %s",
				GetOwner()->GetUsername(), argv[1]);
		}
	} else if (argc > 3 && iRaw == 465) {
		if (GetCurrentNick() != NULL && GetSite() != NULL) {
			g_Bouncer->LogUser(GetUser(), "G/K-line reason for user %s [%s!%s]: %s",
				GetOwner()->GetUsername(), GetCurrentNick(), GetSite(), argv[3]);
		} else {
			g_Bouncer->LogUser(GetUser(), "G/K-line reason for user %s: %s",
				GetOwner()->GetUsername(), argv[3]);
		}
	} else if (argc > 5 && iRaw == 351) {
		free(m_ServerVersion);
		m_ServerVersion = strdup(argv[3]);

		free(m_ServerFeat);
		m_ServerFeat = strdup(argv[5]);
	} else if (argc > 3 && iRaw == 5) {
		for (int i = 3; i < argc - 1; i++) {
			char *Dup = strdup(argv[i]);

			if (AllocFailed(Dup)) {
				return false;
			}

			char *Eq = strchr(Dup, '=');

			if (strcasecmp(Dup, "NAMESX") == 0) {
				WriteLine("PROTOCTL NAMESX");
			}

			char *Value;

			if (Eq) {
				*Eq = '\0';

				Value = strdup(++Eq);
			} else {
				Value = strdup("");
			}

			m_ISupport->Add(Dup, Value);

			free(Dup);
		}
	} else if (argc > 4 && iRaw == 324) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->ClearModes();
			Channel->ParseModeChange(argv[0], argv[4], argc - 5, &argv[5]);
			Channel->SetModesValid(true);
		}
	} else if (argc > 3 && hashRaw == hashMode) {
		Channel = GetChannel(argv[2]);

		if (Channel != NULL) {
			Channel->ParseModeChange(argv[0], argv[3], argc - 4, &argv[4]);
		} else if (strcmp(m_CurrentNick, argv[2]) == 0) {
			bool Flip = true, WasNull;
			const char *Modes = argv[3];
			size_t Length = strlen(Modes) + 1;

			if (m_Usermodes != NULL) {
				Length += strlen(m_Usermodes);
			}

			WasNull = (m_Usermodes != NULL) ? false : true;
			m_Usermodes = (char *)realloc(m_Usermodes, Length);

			if (AllocFailed(m_Usermodes)) {
				return false;
			}

			if (WasNull) {
				m_Usermodes[0] = '\0';
			}

			while (*Modes != '\0') {
				if (*Modes == '+') {
					Flip = true;
				} else if (*Modes == '-') {
					Flip = false;
				} else {
					if (Flip) {
						size_t Position = strlen(m_Usermodes);
						m_Usermodes[Position] = *Modes;
						m_Usermodes[Position + 1] = '\0';
					} else {
						char *CurrentModes = m_Usermodes;
						size_t a = 0;

						while (*CurrentModes != '\0') {
							*CurrentModes = m_Usermodes[a];

							if (*CurrentModes != *Modes) {
								CurrentModes++;
							}

							a++;
						}
					}
				}

				Modes++;
			}
		}

		UpdateHostHelper(Reply);
	} else if (argc > 4 && iRaw == 329) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetCreationTime(atoi(argv[4]));
		}
	} else if (argc > 4 && iRaw == 332) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetTopic(argv[4]);
		}
	} else if (argc > 5 && iRaw == 333) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetTopicNick(argv[4]);
			Channel->SetTopicStamp(atoi(argv[5]));
		}
	} else if (argc > 3 && iRaw == 331) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetNoTopic();
		}
	} else if (argc > 3 && hashRaw == hashTopic) {
		Channel = GetChannel(argv[2]);

		if (Channel != NULL) {
			Channel->SetTopic(argv[3]);
			Channel->SetTopicStamp(g_CurrentTime);
			Channel->SetTopicNick(argv[0]);
		}

		UpdateHostHelper(Reply);
	} else if (argc > 5 && iRaw == 353) {
		Channel = GetChannel(argv[4]);

		if (Channel != NULL) {
			const char *nicks;
			const char **nickv;

			nicks = ArgTokenize(argv[5]);

			if (AllocFailed(nicks)) {
				return false;
			}

			nickv = ArgToArray(nicks);

			if (AllocFailed(nickv)) {
				ArgFree(nicks);

				return false;
			}

			int nickc = ArgCount(nicks);

			for (int i = 0; i < nickc; i++) {
				char *Nick = strdup(nickv[i]);
				char *BaseNick = Nick;

				if (AllocFailed(Nick)) {
					ArgFree(nicks);

					return false;
				}

				StrTrim(Nick, ' ');

				while (IsNickPrefix(*Nick)) {
					Nick++;
				}

				char *Modes = NULL;

				if (BaseNick != Nick) {
					Modes = (char *)malloc(Nick - BaseNick + 1);

					if (!AllocFailed(Modes)) {
						strmcpy(Modes, BaseNick, Nick - BaseNick + 1);
					}
				}

				Channel->AddUser(Nick, Modes);

				free(BaseNick);
				free(Modes);
			}

			ArgFreeArray(nickv);
			ArgFree(nicks);
		}
	} else if (argc > 3 && iRaw == 366) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetHasNames();
		}
	} else if (argc > 9 && iRaw == 352) {
		const char *Ident = argv[4];
		const char *Host = argv[5];
		const char *Server = argv[6];
		const char *Nick = argv[7];
		const char *Realname = argv[9];
		char *Mask;

		int rc = asprintf(&Mask, "%s!%s@%s", Nick, Ident, Host);

		if (!RcFailed(rc)) {
			UpdateHostHelper(Mask);
			UpdateWhoHelper(Nick, Realname, Server);

			free(Mask);
		}
	} else if (argc > 6 && iRaw == 367) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->GetBanlist()->SetBan(argv[4], argv[5], atoi(argv[6]));
		}
	} else if (argc > 3 && iRaw == 368) {
		Channel = GetChannel(argv[3]);

		if (Channel != NULL) {
			Channel->SetHasBans();
		}
	} else if (argc > 3 && iRaw == 396) {
		free(m_Site);
		m_Site = strdup(argv[3]);

		if (AllocFailed(m_Site)) {}
	} else if (argc > 3 && hashRaw == hashPong && m_Server != NULL && strcasecmp(argv[2], m_Server) == 0 && m_EatPong) {
		m_EatPong = false;

		return false;
	} else if (argc > 3 && iRaw == 421) {
		m_FloodControl->Unplug();

		return false;
	}

	if (GetOwner() != NULL) {
		return ModuleEvent(argc, argv);
	} else {
		return true;
	}
}
Exemple #21
0
void CXEPxibb::OpenStream(const CJid& rJid, u16 localCid, u16* pLocalSid, u16 blockSize, u32 byteRate)
{
	u16 localSid;
	
	MutexOnChannelManager.Lock();

	try
	{		
		// we are looking for the channelmanager associate to the Jid 		
		CChannelManager* pChannelManager = GetChannelManager(rJid);
				
		if(pChannelManager == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENSTREAMERROR);
		
		// we are looking for the channel associate to the localCid
		CChannel* pChannel = pChannelManager->GetChannelByLocalCid(localCid);

		if(pChannel == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENSTREAMERROR);

		// we build and add the new stream
		CStream* pStream = new CStream();
		localSid = pChannel->AddStream(pStream);
		pStream->Init(rJid, pChannel->GetRemoteCid(), localSid, blockSize, byteRate);

		pXMPPCore->RequestHandler(pStream->GetStreamDataHandler());
		
		*pLocalSid = localSid;
	}

	catch(exception& e)
	{
		MutexOnChannelManager.UnLock();
		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENCHANNELERROR);
	}
	
	MutexOnChannelManager.UnLock();

	// we build the stream:open iqstanza
	string id;
	CHandler IQHandler;
	CIQStanza IQStanza;

	CXMLFilter* pXMLFilter;
	CStreamOpenStanza StreamOpenStanza;
	pXMPPCore->GenerateId(id);

	try
	{
		StreamOpenStanza.Init(rJid, localCid, localSid, blockSize, byteRate, id);				
	
		// we build the handler associate to the iqstanza response
		pXMLFilter = new CXMLFilter("iq");
		pXMLFilter->SetAttribut("from", rJid.GetFull());
		pXMLFilter->SetAttribut("id", id);			
		IQHandler.AddXMLFilter(pXMLFilter);
	}

	catch(exception& e)
	{
		pXMPPCore->RemoveId(id);
		
		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENCHANNELERROR);
	}

	pXMPPCore->RequestHandler(&IQHandler);

	try
	{
		// we send the stream:open iqstanza
		if(!pXMPPCore->Send(&StreamOpenStanza))
		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENSTREAMERROR);

		// we receive the iq result
		if(!pXMPPCore->Receive(&IQHandler, &IQStanza))
		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENSTREAMERROR);

		if(IQStanza.GetKindOf() != CIQStanza::SIQKO_RESULT)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENSTREAMERROR);
	}
	
	catch(exception& e)
	{
		pXMPPCore->CommitHandler(&IQHandler);
		pXMPPCore->RemoveId(id);

		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_OPENCHANNELERROR);
	}

	pXMPPCore->CommitHandler(&IQHandler);
	pXMPPCore->RemoveId(id);
}
Exemple #22
0
void CPatch::Calculate (ubyte nChnlNo) {
	uvar16_32	nDimX = *(m_pImg->m_pnDimX),
			nDimY = *(m_pImg->m_pnDimY);
	uvar32_64	nValue, j;
	uvar32_64	dwConPtr;
	ubyte		nAlpha;
	rtbyte		rValue;
	rtbyte		rPI = 3.1415926535897932384626433832795,
			rRotAngle = rPI / 32.0;
	rtbyte		rDiamMin, rDiamMax, rDiamSum2,
			rX, rY, rXX, rYY,
			rTopX, rTopY, rBottomX, rBottomY,
			rFeretY, rAngle;
	rtbyte		prFactors[3];
	CVector<rtbyte> vA, vB, vC;
	CChannel* pChnl = &(m_pImg->Channels[nChnlNo]);

	// #### TODO: Put geometric scaling factors here
	prFactors[0] = theApp.GeomScales[aimActive].GetCoefX ();
	prFactors[1] = theApp.GeomScales[aimActive].GetCoefY ();
	prFactors[2] = pow ( prFactors[0] * prFactors[0] + prFactors[1] * prFactors[1], 0.5 );
	m_rArea = m_nArea * prFactors[0] * prFactors[1];
	m_rPerimX = m_nPerimX * prFactors[0];
	m_rPerimY = m_nPerimY * prFactors[1];
	m_rPerimXY = m_nPerimXY * prFactors[0] * prFactors[1];
	m_rPerim = m_rPerimX + m_rPerimY + m_rPerimXY;
	m_rGravCntX = m_pntGravCnt.x * prFactors[0];
	m_rGravCntY = m_pntGravCnt.y * prFactors[1];

	// #### TODO: Allocate memory for m_prDistrib

	// Determining densitometric parameters
	m_rSum = m_rSum2 = m_rMax = 0;
	m_rMin = 1e100; // #### TODO: Place max real value here
	m_prDistrib = (rtbyte*)aimMemoryCommit (m_pImg->m_pDoc->m_nBPP, "CPatch::Measure", "m_prDistrib");
	for (uvar32_64 n = 0 ; n < m_pImg->m_pDoc->m_nBPP ; ++n)
		m_prDistrib[n] = 0;
	for (uvar32_64 dwCntPtr = 0 ; dwCntPtr < m_dwCntLen ; ++dwCntPtr) {
		nValue = pChnl->GetPixel (m_pdwContent[dwCntPtr], false);
		rValue = pChnl->GetPixel (m_pdwContent[dwCntPtr], true);
		m_rSum += rValue;
		m_rSum2 += rValue * rValue;
		m_rMin = (rValue < m_rMin) ? rValue : m_rMin;
		m_rMax = (rValue > m_rMax) ? rValue : m_rMax;
		++m_prDistrib[nValue];
	}
	m_rMean = m_rSum / m_dwCntLen;
	if (m_dwCntLen != 1)
		m_rStdDev = pow ((m_rSum2 * m_dwCntLen - m_rSum * m_rSum) / (m_dwCntLen * (m_dwCntLen - 1)), 0.5);
	else
		m_rStdDev = 0.;
	for (n = 0 ; n < m_pImg->m_pDoc->m_nBPP ; ++n)
		m_prDistrib[n] /= rtbyte (m_dwCntLen);

	// Rotating
	m_prFeretsX[0] = m_pntApex.x * prFactors[0];
	m_prFeretsY[0] = m_pntApex.y * prFactors[1];
	m_prDiameters[0] = (m_rectPatch.bottom - m_rectPatch.top) * prFactors[0];
	m_nDiamMin = m_nDiamMax = 0;
	m_rDiamMean = rDiamMin = rDiamMax = m_prDiameters[0];
	rDiamSum2 = m_prDiameters[0] * m_prDiameters[0];
	for (ubyte rot = 1; rot < 64; ++rot) {
		rTopX = rTopY = rFeretY = 0x7FFFFFFF;
		rBottomX = rBottomY = -0x7FFFFFFF;
		for (dwConPtr = 0; dwConPtr < m_dwConLen; ++dwConPtr) {
			rXX = SRCOFFSET_TO_COORDX (m_pdwContour[dwConPtr]) - m_pntGravCnt.x;
			rYY = SRCOFFSET_TO_COORDY (m_pdwContour[dwConPtr]) - m_pntGravCnt.y;
			rX = rXX * cosl (rRotAngle * rot) - rYY * sinl (rRotAngle * rot);
			rY = rXX * sinl (rRotAngle * rot) + rYY * cosl (rRotAngle * rot);
			if (rX < rTopX) rTopX = rX;
			if (rY < rTopY) rTopY = rY;
			if (rX > rBottomX) rBottomX = rX;
			if (rY > rBottomY) rBottomY = rY;
			if (rY < rFeretY) {
				rFeretY = rY;
				m_prFeretsX[rot] = SRCOFFSET_TO_COORDX (m_pdwContour[dwConPtr]);
				m_prFeretsY[rot] = SRCOFFSET_TO_COORDY (m_pdwContour[dwConPtr]);
				if (m_prFeretsX[rot] - m_pntGravCnt.x < 0) m_prFeretsX[rot] -= .5;
				if (m_prFeretsX[rot] - m_pntGravCnt.x > 0) m_prFeretsX[rot] += .5;
				if (m_prFeretsY[rot] - m_pntGravCnt.y < 0) m_prFeretsY[rot] -= .5;
				if (m_prFeretsY[rot] - m_pntGravCnt.y > 0) m_prFeretsY[rot] += .5;
			}
		}
		if (rot >= 32)
			continue;
		nAlpha = (rot <= 16) ? rot : (32 - rot);
		rAngle = rRotAngle * nAlpha;
		m_prDiameters[rot] = rBottomX - rTopX + sinl (rAngle) + cosl (rAngle);
		m_prDiameters[rot] *= pow (prFactors[1]*sinl(rAngle) * prFactors[1]*sinl(rAngle) + prFactors[0]*cosl(rAngle) * prFactors[0]*cosl(rAngle), 0.5);
		m_prAngles[rot] = rot * rRotAngle * 180.0 / rPI;
		m_rDiamMean += m_prDiameters[rot];
		rDiamSum2 += m_prDiameters[rot] * m_prDiameters[rot];
		if (rDiamMin > m_prDiameters[rot]) {
			rDiamMin = m_prDiameters[rot];
			m_nDiamMin = rot;
		}
		if (rDiamMax < m_prDiameters[rot]) {
			rDiamMax = m_prDiameters[rot];
			m_nDiamMax = rot;
		}
	}
	m_rDiamSigma = pow ((32.0*rDiamSum2 - m_rDiamMean*m_rDiamMean) / 992.0, 0.5);
	m_rDiamMean /= 32.0;
	
	// Calculating circumscribed shape parameters
	m_rCscArea = m_rCscPerim = 0.0;
	for (rot = 0 ; rot < 64 ; ++rot) {
		j = (rot == 63) ? 0 : rot + 1;
		vA(1) = (m_prFeretsX[j] - m_prFeretsX[rot]) * prFactors[0];
		vA(2) = (m_prFeretsY[j] - m_prFeretsY[rot]) * prFactors[1];
		vB(1) = (m_prFeretsX[rot] - m_pntGravCnt.x) * prFactors[0];
		vB(2) = (m_prFeretsY[rot] - m_pntGravCnt.y) * prFactors[1];
		vC(1) = (m_prFeretsX[j] - m_pntGravCnt.x) * prFactors[0];
		vC(2) = (m_prFeretsY[j] - m_pntGravCnt.y) * prFactors[1];
		rtbyte rp = ( vA.Module() + vB.Module() + vC.Module() ) / 2;
		m_rCscArea += pow ( rp*(rp-vA.Module())*(rp-vB.Module())*(rp-vC.Module()), 0.5 );
		m_rCscPerim += vA.Module ( );
	}

	aimMemoryRelease (m_prDistrib, "CPatch::Measure", "m_prDistrib");
/*
	int		rot;
	ubyte		bAlpha;
	uvar16_32	wX, wY;
	uvar32_64	i, j, c;
	uvar32_64	dwSumX, dwSumY,
			dwSumGreyX, dwSumGreyY, dwSumGrey;
	uvar32_64	dwMskPtr,
			dwCntPtr,
			dwConPtr,
			dwSrcPtr,
			dwSrcLen = m_pDoc->GetDimX () * m_pDoc->GetDimY ();
	rtbyte		rPlane,
			rX, rY, rXX, rYY, rFeretY,
			rDimMin, rDimMax, rDiamSum2,
			rAngle,
			rPI,
			rRotAngle;
	rtbyte		lrTop[2], lrBottom[2];
	rtbyte		lrFactors[4];
	CVector<rtbyte> vA, vB, vC;

	// #### TODO: Put geometric scaling factors here
	lrFactors[0] = 1; //wieConfig.m_cfgGeomScales[wieConfig.m_cfgGeomScale].m_scaleFactorX;
	lrFactors[1] = 1; //wieConfig.m_cfgGeomScales[wieConfig.m_cfgGeomScale].m_scaleFactorY;
	lrFactors[2] = pow ( lrFactors[0] * lrFactors[0] + lrFactors[1] * lrFactors[1], 0.5 );

	// Determing statistics and bounding rectangle
	dwSumX = dwSumY = 0;
	dwSumGrey = dwSumGreyX = dwSumGreyY = 0;
	m_lwApex[0] = m_lwApex[1] = 0xFFFF;
	m_lwTop[0] = m_lwTop[1] = 0xFFFF;
	m_lwBottom[0] = m_lwBottom[1] = 0x0000;
	for (j = 0 ; j < 4 ; ++j) {
		m_lrSum[j] = m_lrSum2[j] = 0;
		m_lrMin[j] = 0xFF;
		m_lrMax[j] = 0;
		m_ldwCount[j] = m_dwCntLen;
		for (c = 0 ; c < 256 ; ++c)
			m_llrDistrib[j][c] = 0;
	}
	for (dwCntPtr = 0 ; dwCntPtr < m_dwCntLen ; ++dwCntPtr) {
		// #### TODO: Put dens transform function here
		rPlane = (MEANCOLOR (m_pdwPixels[m_pdwContent[dwCntPtr]]));
		m_lrSum[0] += rPlane;
		m_lrSum2[0] += rPlane * rPlane;
		m_lrMin[0] = (rPlane < m_lrMin[0]) ? rPlane : m_lrMin[0];
		m_lrMax[0] = (rPlane > m_lrMax[0]) ? rPlane : m_lrMax[0];
		++m_llrDistrib[0][MEANCOLOR (m_pdwPixels[m_pdwContent[dwCntPtr]])];
		wX = SRCOFFSET_TO_COORDX (m_pdwContent[dwCntPtr]);
		wY = SRCOFFSET_TO_COORDY (m_pdwContent[dwCntPtr]);
		dwSumX += wX;
		dwSumY += wY;
		dwSumGreyX += wX * SUMCOLOR (m_pdwPixels[m_pdwContent[dwCntPtr]]);
		dwSumGreyY += wY * SUMCOLOR (m_pdwPixels[m_pdwContent[dwCntPtr]]);
		dwSumGrey += SUMCOLOR (m_pdwPixels[m_pdwContent[dwCntPtr]]);
		for (j = 1 ; j < 4 ; ++j) {
			// #### TODO: Put dens transform function here
			rPlane = ((BYTE) GET_COLOR (m_pdwPixels[m_pdwContent[dwCntPtr]], j - 1));
			m_lrSum[j] += rPlane;
			m_lrSum2[j] += rPlane * rPlane;
			m_lrMin[j] = (rPlane < m_lrMin[j]) ? rPlane : m_lrMin[j];
			m_lrMax[j] = (rPlane > m_lrMax[j]) ? rPlane : m_lrMax[j];
			++m_llrDistrib[j][(BYTE) GET_COLOR (m_pdwPixels[m_pdwContent[dwCntPtr]], j - 1)];
		}
		if (wX < m_lwTop[0]) m_lwTop[0] = wX;
		if (wY < m_lwTop[1]) m_lwTop[1] = wY;
		if (wX > m_lwBottom[0]) m_lwBottom[0] = wX;
		if (wY > m_lwBottom[1]) m_lwBottom[1] = wY;
		if (m_pdwContent[dwCntPtr] < COORD_TO_SRCOFFSET (m_lwApex[0], m_lwApex[1])) {
			m_lwApex[0] = wX; m_lwApex[1] = wY;
		}
	}
	// Determing mean and deviance parameters
	for (j = 0 ; j < 4 ; ++j) {
		m_lrMean[j] = m_lrSum[j] / m_ldwCount[j];
		if (m_ldwCount[j] != 1)
			m_lrStdDev[j] = pow ( ((m_lrSum2[j] * m_ldwCount[j]) - (m_lrSum[j] * m_lrSum[j])) / (m_ldwCount[j] * (m_ldwCount[j] - 1)), 0.5);
		else
			m_lrStdDev[j] = 0.0;
		for (c = 0 ; c < 256 ; ++c)
			m_llrDistrib[j][c] /= rtbyte (m_dwCntLen);
	}
	m_lrCntGravity[0] = rtbyte (dwSumX) / rtbyte (m_dwCntLen);
	m_lrCntGravity[1] = rtbyte (dwSumY) / rtbyte (m_dwCntLen);
	m_lrGryGravity[0] = rtbyte (dwSumGreyX) / rtbyte (dwSumGrey);
	m_lrGryGravity[1] = rtbyte (dwSumGreyY) / rtbyte (dwSumGrey);

	// Creation of the Mask
	m_wDimX = m_lwBottom[0] - m_lwTop[0] + 1;
	m_wDimY = m_lwBottom[1] - m_lwTop[1] + 1;
	m_dwMskLen = m_wDimX * m_wDimY;
	if (!(m_pbMask = (ubyte*)aimMemoryCommit (m_dwMskLen, "CPatch::Set", "m_pbMask")) )
		throw (CaImAPIException(0));
	for (dwCntPtr = 0 ; dwCntPtr < m_dwCntLen ; ++dwCntPtr)
		m_pbMask[COORD_TO_MSKOFFSET (SRCOFFSET_TO_COORDX (m_pdwContent[dwCntPtr]) - m_lwTop[0],
		                             SRCOFFSET_TO_COORDY ( m_pdwContent[dwCntPtr] ) - m_lwTop[1] )] = 1;
	m_dwConLen = 0;
	for (wX = 0 ; wX < m_wDimX ; ++wX)
		for (wY = 0 ; wY < m_wDimY ; ++wY) {
			if (m_pbMask[COORD_TO_MSKOFFSET (wX, wY)] != 1)
				continue;
			if (wX == 0 || wY == 0 || wX == m_wDimX - 1 || wY == m_wDimY - 1) {
				m_pbMask[COORD_TO_MSKOFFSET (wX, wY)] = 2;
				++m_dwConLen;
			}
			else if (m_pbMask[COORD_TO_MSKOFFSET (wX - 1, wY)] == 0 ||
			         m_pbMask[COORD_TO_MSKOFFSET (wX + 1, wY)] == 0 ||
			         m_pbMask[COORD_TO_MSKOFFSET (wX, wY - 1)] == 0 ||
			         m_pbMask[COORD_TO_MSKOFFSET (wX, wY + 1)] == 0 ) {
				m_pbMask[COORD_TO_MSKOFFSET (wX, wY)] = 2;
				++m_dwConLen;
			}
		}

	if (!( m_pdwContour = (uvar32_64*)aimMemoryCommit (m_dwConLen * 4, "CPatch::Set", "m_pdwContour")))
		throw (CaImAPIException(0));
	for (dwMskPtr = dwConPtr = 0 ; dwMskPtr < m_dwMskLen ; ++dwMskPtr)
		if (m_pbMask[dwMskPtr] == 2)
			m_pdwContour[dwConPtr++] = COORD_TO_SRCOFFSET (MSKOFFSET_TO_COORDX (dwMskPtr) + m_lwTop[0],
			                                               MSKOFFSET_TO_COORDY ( dwMskPtr ) + m_lwTop[1] );

	// Calculating CntGravity, Perimeter, Area
	m_rPerimX = m_rPerimY = m_rPerimXY = 0;
	for (dwMskPtr = 0 ; dwMskPtr < m_dwMskLen ; ++dwMskPtr)
		if (m_pbMask[dwMskPtr] == 2)
			CalculatePerimeter (MSKOFFSET_TO_COORDX (dwMskPtr), MSKOFFSET_TO_COORDY (dwMskPtr));
	m_rArea = m_dwCntLen * lrFactors[0] * lrFactors[1];
	m_rPerim = m_rPerimX * lrFactors[0] + m_rPerimY * lrFactors[1] + m_rPerimXY * lrFactors[2];

	// Rotating
	m_llrFerets[0][0] = m_lwApex[0];
	m_llrFerets[0][1] = m_lwApex[1];
	m_lrDiameters[0] = (m_lwBottom[0] - m_lwTop[0] + 1.0)*lrFactors[0];					// !!!
	m_rDiamMean = m_lrDiameters[0];
	rDiamSum2 = m_lrDiameters[0] * m_lrDiameters[0];
	rDimMin = m_lrDiameters[0];
	rDimMax = m_lrDiameters[0];
	m_lrAngles[0] = 0.0;
	m_bDiamMaxNo = m_bDiamMinNo = 0;
	for (rot = 1 ; rot < 64 ; ++rot) {
		lrTop[0] = lrTop[1] = rFeretY = 0x7FFFFFFF;
		lrBottom[0] = lrBottom[1] = -0x7FFFFFFF;
		for (dwConPtr = 0 ; dwConPtr < m_dwConLen ; ++dwConPtr) {
			rXX = SRCOFFSET_TO_COORDX (m_pdwContour[dwConPtr]) - m_lrCntGravity[0];
			rYY = SRCOFFSET_TO_COORDY (m_pdwContour[dwConPtr]) - m_lrCntGravity[1];
			rX = rXX * cosl (rRotAngle * rot) - rYY * sinl (rRotAngle * rot);
			rY = rXX * sinl (rRotAngle * rot) + rYY * cosl (rRotAngle * rot);
			if (rX < lrTop[0]) lrTop[0] = rX;
			if (rY < lrTop[1]) lrTop[1] = rY;
			if (rX > lrBottom[0]) lrBottom[0] = rX;
			if (rY > lrBottom[1]) lrBottom[1] = rY;
			if (rY < rFeretY) {
				rFeretY = rY;
				m_llrFerets[rot][0] = SRCOFFSET_TO_COORDX (m_pdwContour[dwConPtr]);
				m_llrFerets[rot][1] = SRCOFFSET_TO_COORDY (m_pdwContour[dwConPtr]);
				if (m_llrFerets[rot][0] - m_lrCntGravity[0] < 0) m_llrFerets[rot][0] -= .5;
				if (m_llrFerets[rot][0] - m_lrCntGravity[0] > 0) m_llrFerets[rot][0] += .5;
				if (m_llrFerets[rot][1] - m_lrCntGravity[1] < 0) m_llrFerets[rot][1] -= .5;
				if (m_llrFerets[rot][1] - m_lrCntGravity[1] > 0) m_llrFerets[rot][1] += .5;
			}
		}
		if (rot >= 32)
			continue;
		bAlpha = (rot <= 16) ? rot : (32 - rot);
		rAngle = rRotAngle * bAlpha;
		m_lrDiameters[rot] = lrBottom[0] - lrTop[0] + sinl (rAngle) + cosl (rAngle);
		m_lrDiameters[rot] *= pow (lrFactors[1]*sinl(rAngle) * lrFactors[1]*sinl(rAngle) + lrFactors[0]*cosl(rAngle) * lrFactors[0]*cosl(rAngle), 0.5);
		m_lrAngles[rot] = rot * rRotAngle * 180.0 / rPI;
		m_rDiamMean += m_lrDiameters[rot];
		rDiamSum2 += m_lrDiameters[rot] * m_lrDiameters[rot];
		if (rDimMin > m_lrDiameters[rot]) {
			rDimMin = m_lrDiameters[rot];
			m_bDiamMinNo = (BYTE)rot;
		}
		if (rDimMax < m_lrDiameters[rot]) {
			rDimMax = m_lrDiameters[rot];
			m_bDiamMaxNo  = (BYTE)rot;
		}
	}
	m_rDiamSigma = pow ((32.0*rDiamSum2 - m_rDiamMean*m_rDiamMean) / 992.0, 0.5);
	m_rDiamMean /= 32.0;
	m_rCscArea = m_rCscPerim = 0.0;
	for (i = 0 ; i < 64 ; ++i) {
		j = (i == 63) ? 0 : i + 1;
		vA(1) = (m_llrFerets[j][0] - m_llrFerets[i][0]) * lrFactors[0];
		vA(2) = (m_llrFerets[j][1] - m_llrFerets[i][1]) * lrFactors[1];
		vB(1) = (m_llrFerets[i][0] - m_lrCntGravity[0]) * lrFactors[0];
		vB(2) = (m_llrFerets[i][1] - m_lrCntGravity[1]) * lrFactors[1];
		vC(1) = (m_llrFerets[j][0] - m_lrCntGravity[0]) * lrFactors[0];
		vC(2) = (m_llrFerets[j][1] - m_lrCntGravity[1]) * lrFactors[1];
		rtbyte rp = ( vA.Module() + vB.Module() + vC.Module() ) / 2;
		m_rCscArea += pow ( rp*(rp-vA.Module())*(rp-vB.Module())*(rp-vC.Module()), 0.5 );
		m_rCscPerim += vA.Module ( );
	}

	dwSumX = 0;
	dwSumY = 0;
	for (dwConPtr = 0 ; dwConPtr < m_dwConLen ; ++dwConPtr) {
		dwSumX += SRCOFFSET_TO_COORDX (m_pdwContour[dwConPtr]);
		dwSumY += SRCOFFSET_TO_COORDY (m_pdwContour[dwConPtr]);
	}
	m_lrConGravity[0] = rtbyte (dwSumX) / rtbyte (m_dwConLen);
	m_lrConGravity[1] = rtbyte (dwSumY) / rtbyte (m_dwConLen);
	rX = (m_lrCntGravity[0] - m_lrConGravity[0]) * lrFactors[0];
	rY = (m_lrCntGravity[1] - m_lrConGravity[1]) * lrFactors[1];
	m_rCntConDist = pow (rX*rX + rY*rY, 0.5);
	m_rAngleContAxis = atan2 (rY, rX);
	rX = (m_lrCntGravity[0] - m_lrGryGravity[0]) * lrFactors[0];
	rY = (m_lrCntGravity[1] - m_lrGryGravity[1]) * lrFactors[1];
	m_rCntGryDist = pow (rX*rX + rY*rY, 0.5);
	m_rAngleGreyAxis = atan2 (rY, rX);

	m_dwFragments = 0;*/
}
Exemple #23
0
void CXEPxibb::CloseStream(const CJid& rJid, u16 localCid, u16 localSid)
{
	u16 remoteCid;
	u16 remoteSid;
	
	MutexOnChannelManager.Lock();

	try
	{
		// we are looking for the channelmanager associate to the Jid 		
		CChannelManager* pChannelManager = GetChannelManager(rJid);
				
		if(pChannelManager == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);
		
		// we are looking for the channel associate to the localCid
		CChannel* pChannel = pChannelManager->GetChannelByLocalCid(localCid);

		if(pChannel == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);

		remoteCid = pChannel->GetRemoteCid();

		// we are looking for the stream associate to the localSid
		CStream* pStream = pChannel->GetStreamByLocalSid(localSid);

		if(pStream == NULL)
		throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);

		remoteSid = pStream->GetRemoteSid();

		pXMPPCore->CommitHandler(pStream->GetStreamDataHandler());
		pChannel->RemoveStreamByLocalSid(localSid);
	}
	
	catch(exception& e)
	{
		MutexOnChannelManager.UnLock();
		#ifdef __DEBUG__
		cerr << e.what() << endl;
		#endif //__DEBUG__

		throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);
	}

	MutexOnChannelManager.UnLock();

	// we build the iq request
	string id;
	pXMPPCore->GenerateId(id);
	
	CStreamCloseStanza StreamCloseStanza(rJid, remoteCid, remoteSid, id);

	// we build the handler associate to the iq request
	CIQResultStanza IQResultStanza;
	CHandler IQResultHandler;

	CXMLFilter* pXMLFilter = new CXMLFilter("iq");
	pXMLFilter->SetAttribut("from", rJid.GetFull());
	pXMLFilter->SetAttribut("id", id);

	IQResultHandler.AddXMLFilter(pXMLFilter);
	
	pXMPPCore->RequestHandler(&IQResultHandler);

	// we send the iq request
	if(!pXMPPCore->Send(&StreamCloseStanza))
	throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);

	// we receive the iq result
	if(!pXMPPCore->Receive(&IQResultHandler, &IQResultStanza))
	throw CXEPxibbException(CXEPxibbException::XEPXEC_CLOSESTREAMERROR);

	pXMPPCore->CommitHandler(&IQResultHandler);
	pXMPPCore->RemoveId(id);
}
Exemple #24
0
int OnRequestChangeChannel( LPSOCKETCONTEXT lpSockContext, char *cpPacket )
{
    CCoder					coder;
    CChannel				*pChannel = &Server.ch[lpSockContext->iChannel];
    CRoom					*pRoom;
    char					cChannel,
                            cPacket[32],
                            *pOffset;
    int						newProcess,
                            iNext,
                            iSize;
    short					dummy;



    // ---- 유저 링크 제거 ----
    pChannel->KillUserLink( lpSockContext->index );

    // ---- 유저 퇴장을 통보 ----
    coder.SetBuf( cPacket );
    coder.PutChar( lpSockContext->idLen );
    coder.PutText( lpSockContext->cID, lpSockContext->idLen );
    iSize = coder.SetHeader( NOTIFY_USERDELETE );

    PostTcpSend( pChannel->iUserBegin, cPacket, iSize );
    iNext = pChannel->iUsedRoomBegin;
    while( iNext != NOTLINKED )
    {
        pRoom = &Server.rm[iNext];
        PostTcpSend( pRoom->iUserBegin, cPacket, iSize );
        iNext = Server.rn[iNext].next;
    }


    coder.SetBuf( cpPacket );
    coder.GetChar( &cChannel ); // 이동하려는 채널 번호
    coder.SetBuf( cPacket );

#ifdef _LOGLEVEL3_
    DConsole.Output( "OnRequestChangeChannel(%d) : %d\n", lpSockContext->index, cChannel );
#endif

    lpSockContext->iChannel = cChannel;
    newProcess = cChannel / Server.iMaxChannelInProcess;

    if( lpSockContext->iProcess == newProcess )
    {
        // ---- 같은 쓰레드 내에서는 직접 호출 ----
        OnRequestChangeChannelInt( lpSockContext, cpPacket );
    }
    else
    {
        lpSockContext->iProcess = newProcess;

        // ---- 중요한 작업 ----
        // ---- cpRTBegin 을 되감아서 다른 쓰레드가 그것을 처리할 수 있도록 한다 ----
        lpSockContext->cpRTBegin = cpPacket;

        dummy = REQUEST_CHANGECHANNEL_INT;
        pOffset = cpPacket + sizeof( short );

        if( pOffset >= lpSockContext->cRecvTcpRingBuf + RINGBUFSIZE )
        {
            pOffset -= RINGBUFSIZE;
            CopyMemory( pOffset, &dummy, sizeof( short ) );
        }
        else
        {
            CopyMemory( pOffset, &dummy, sizeof( short ) );
            dummy = lpSockContext->cRecvTcpRingBuf + RINGBUFSIZE - pOffset;
            if( dummy < sizeof( short) )
            {
                *lpSockContext->cRecvTcpRingBuf = *(lpSockContext->cRecvTcpRingBuf + RINGBUFSIZE);
            }
        }

        Server.ps[newProcess].GameBufEnqueue( lpSockContext );
    }

    return 1;
}
Exemple #25
0
CHandShakeBehaviour::CHandShakeBehaviour(CChannel& channel) : CBaseBehaviour(channel), m_method(), m_outgoing(channel.Outgoing())
{
	StartLogicalAccept();
}
Exemple #26
0
CBaseBehaviour::CBaseBehaviour(CChannel& channel) :
	m_id(channel.GetId()), m_server(channel.GetServer()), m_logger(channel.GetLogger()),
	m_params(channel.GetParameters()), m_state(channel.GetState()), m_transport(channel.GetTransport())
{
}
BOOL CChannels::EndChange(void)
{
	int				i;
	SChannel*		psAddedChannel;
	SChannel*		psRemovedChannel;
	CChannel*		psChannel;
	int				iSize;
	int				iOffset;
	BOOL			bAnyAdded;
	int				iOldBitStride;
	int				iAddedBitStride;
	int				iOldByteStride;
	BOOL			bResult;

	//I don't think this handles the case where the channels have been re-ordered...
	//Which as there *IS* no way of re-ordering them shouldn't be a problem.

	bResult = TRUE;
	if (IsChanging())
	{
		if (mpvUserData != mpsChangingDesc->pvUserData)
		{
			//Switch between using mabData and mpvUserData.
			if ((mpvUserData == NULL) && (mpsChangingDesc->pvUserData != NULL))
			{
				FreeData();
			}
			else if ((mpvUserData != NULL) && (mpsChangingDesc->pvUserData == NULL))
			{
				AllocateData();
				//should copy from mpvUserData
			}
			mpvUserData = (char*)mpsChangingDesc->pvUserData;
		}

		if (!IsUserAllocated())
		{
			//We're using mabData and have already allocated it.
			if ((miBitStride != 0) && (miSize != 0))
			{
				//Remove
				for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++)
				{
					psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i);
					psChannel = GetChannel(psRemovedChannel->iChannel);
					if (psChannel->Is8BitAligned())
					{
						iOffset = psChannel->miByteOffset;
						iSize = psChannel->miByteSize;
						mabData.BatchRemoveElements(iOffset, iSize, miSize, miByteStride);
					}
					else
					{
						//Deal with bitty removal.
					}
					masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE);
					Recalculate();
				}
			}

			//Add
			bAnyAdded = FALSE;
			for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++)
			{
				psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i);

				psChannel = masChannelOffsets.Add();
				psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse);
				bAnyAdded = TRUE;
			}

			if (bAnyAdded)
			{
				iOldBitStride = miBitStride;
				iOldByteStride = miByteStride;
				Recalculate();
				iAddedBitStride = miBitStride - iOldBitStride;
				if ((iAddedBitStride != 0) && (miSize != 0))
				{
					if (Is8BitAligned(iOldBitStride, iAddedBitStride))
					{
						iOffset = iOldByteStride;
						iSize = iAddedBitStride / 8;
						mabData.BatchInsertElements(iOffset, iSize, miSize, iOldByteStride);
					}
					else
					{
						//Deal with bitty addition.
					}
				}
			}

			//Change size due to size change.
			if (mpsChangingDesc->iSize != miSize)
			{
				miSize = mpsChangingDesc->iSize;
				iSize = CalculateByteSize(miBitStride, miSize);
				mabData.GrowToNumElements(iSize);
			}
		}
		else  //Using user allocated memory.
		{
			//This assumes the mpvUserData is *already* in the form being specified.
			for (i = 0; i < mpsChangingDesc->asRemovedChannels.NumElements(); i++)
			{
				psRemovedChannel = mpsChangingDesc->asRemovedChannels.Get(i);
				psChannel = GetChannel(psRemovedChannel->iChannel);
				masChannelOffsets.RemoveAt(masChannelOffsets.GetIndex(psChannel), TRUE);
			}

			for (i = 0; i < mpsChangingDesc->asAddedChannels.NumElements(); i++)
			{
				psAddedChannel = mpsChangingDesc->asAddedChannels.Get(i);

				psChannel = masChannelOffsets.Add();
				psChannel->Init(psAddedChannel->iChannel, psAddedChannel->eType, psAddedChannel->bReverse);
			}
			miSize = mpsChangingDesc->iSize;
			Recalculate();
		}

		mpsChangingDesc->Kill();
		free(mpsChangingDesc);
		mpsChangingDesc = NULL;
	}

	if (IsUserAllocated())
	{
		mpvDataCache = mpvUserData;
	}
	else
	{
		mpvDataCache = mabData.GetData();
	}
	return bResult;
}
Exemple #28
0
void CMixereView::SaveUndoState(CUndoState& State)
{
	if (State.GetCode() < START_UCODE) {	// if base class undo code
		CFormListView::SaveUndoState(State);	// defer to base class
		return;
	}
	if (State.GetCode() > END_UCODE) {		// if snapshot undo code
		m_Snapshot->SaveUndoState(State);		// defer to snapshot class
		return;
	}
	int	Chans = GetItemCount();
	UValCurPos(State) = m_CurPos;	// do first so handlers can override
	switch (State.GetCode()) {
	case UCODE_TRANSPORT:
		{
			TRANSPORT_UNDO_STATE	*uap;
			if (State.IsEmpty()) {	// if first time
				AllocUndoArray(uap, State, max(m_Selections, 1));
				SetUndoChanIdxs(uap);	// set each element's channel index
			} else
				GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				uap->m_Transport = Chan->GetTransport();
				uap->m_Pos = Chan->GetPosition();
			}
		}
		break;
	case UCODE_GO:
		{
			GO_UNDO_STATE	*uap;
			if (State.IsEmpty()) {	// if first time
				AllocUndoArray(uap, State, max(m_Selections, 1));
				SetUndoChanIdxs(uap);	// set each element's channel index
			} else
				GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				uap->m_Transport = Chan->GetTransport();
				uap->m_Pos = Chan->GetPosition();
				for (int j = 0; j < CChanInfo::AUTOS; j++) {
					uap->m_Auto[j].m_Transport = Chan->GetAuto(j)->GetTransport();
					uap->m_Auto[j].m_Pos = Chan->GetAuto(j)->GetNormPos();
				}
			}
		}
		break;
	case UCODE_LOOP:
		{
			bool	*uap;
			AllocUndoArray(uap, State, Chans);
			for (int i = 0; i < Chans; i++)
				uap[i] = GetChan(i)->GetLoop();
		}
		break;
	case UCODE_MUTE:
		{
			bool	*uap;
			AllocUndoArray(uap, State, Chans);
			for (int i = 0; i < Chans; i++)
				uap[i] = GetChan(i)->GetMute();
		}
		break;
	case UCODE_SOLO:
	case UCODE_END_SOLO:
		{
			bool	*uap;
			AllocUndoArray(uap, State, Chans);
			for (int i = 0; i < Chans; i++)
				uap[i] = GetChan(i)->GetSolo();
		}
		break;
	case UCODE_KEEP_SOLO:
		{
			BYTE	*uap;
			AllocUndoArray(uap, State, Chans);
			for (int i = 0; i < Chans; i++)
				uap[i] = GetChan(i)->GetMute() + (GetChan(i)->GetSolo() << 1);
		}
		break;
	case UCODE_LOAD_AUDIO:
	case UCODE_INSERT_AUDIO:
		if (!UValFlags(State)) {
			// override current position with pre-insert position
			UValCurPos(State) = m_PrevPos;
			CChanInfo	*uap;
			AllocUndoArray(uap, State, 1);
			GetChan(m_CurPos)->GetInfo(uap);
			UValFlags(State) = UFLAG_DEL;	// first restore will delete
		} else
			UValFlags(State) ^= UFLAG_DIR;	// reverse direction
		break;
	case UCODE_SHOW_VOLUME:
	case UCODE_SHOW_SNAPSHOT:
	case UCODE_SHOW_MS_FADE:
	case UCODE_SHOW_TEMPO:
		if (!UValBarNum(State))	// if first time (zero bar number)
			// assume m_UndoIdx contains notifier's dialog bar index
			UValBarNum(State) = m_UndoIdx + 1;	// zero is reserved for first time
		UValShowBar(State) = IsDlgBarVisible(UValBarNum(State) - 1);
		break;
	case UCODE_SET_DEFAULTS:
		{
			CChanInfo	*uap;
			AllocUndoArray(uap, State, 1);
			*uap = m_ChanDefaults;
		}
		break;
	case UCODE_EDIT_AUTO:
		{
			CEditAutoUndoState	*uap;
			if (State.IsEmpty()) {	// if first time
				AllocUndoArray(uap, State, max(m_Selections, 1));
				SetUndoChanIdxs(uap);	// set each element's channel index
				// assume m_UndoIdx contains notifier's auto slider index
				UValAutoIdx(State) = m_UndoIdx;
			} else
				GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				CAutoSliderCtrl	*Auto = Chan->GetAuto(UValAutoIdx(State));
				Auto->GetInfo(*uap);
				uap->m_ChanTransport = Chan->GetTransport();
				uap->m_ChanLoop = Chan->GetLoop();
				uap->m_ChanPos = Chan->GetPosition();
			}
		}
		break;
	default:
		NODEFAULTCASE;		
	}
}
Exemple #29
0
void CMixereView::RestoreUndoState(const CUndoState& State)
{
	if (State.GetCode() < START_UCODE) {	// if base class undo code
		CFormListView::RestoreUndoState(State);	// defer to base class
		return;
	}
	if (State.GetCode() > END_UCODE) {		// if snapshot undo code
		m_Snapshot->RestoreUndoState(State);	// defer to snapshot class
		return;
	}
	CWaitCursor	wc;
	switch (State.GetCode()) {
	case UCODE_TRANSPORT:
		{
			TRANSPORT_UNDO_STATE	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				Chan->SetTransportAndPos(uap->m_Transport, uap->m_Pos);
			}
		}
		break;
	case UCODE_GO:
		{
			GO_UNDO_STATE	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				for (int j = 0; j < CChanInfo::AUTOS; j++) {
					Chan->GetAuto(j)->SetTransport(uap->m_Auto[j].m_Transport);
					Chan->GetAuto(j)->SetNormPos(uap->m_Auto[j].m_Pos);
				}
				Chan->SetTransportAndPos(uap->m_Transport, uap->m_Pos);
			}
		}
		break;
	case UCODE_LOOP:
		{
			bool	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++)
				GetChan(i)->SetLoop(uap[i]);
		}
		break;
	case UCODE_MUTE:
		{
			bool	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++)
				GetChan(i)->SetMute(uap[i]);
		}
		break;
	case UCODE_SOLO:
	case UCODE_END_SOLO:
		{
			bool	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++)
				GetChan(i)->SetSolo(uap[i]);
		}
		break;
	case UCODE_KEEP_SOLO:
		{
			BYTE	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++) {
				GetChan(i)->SetMute((uap[i] & 0x1) != 0);
				GetChan(i)->SetSolo((uap[i] & 0x2) != 0);
			}
		}
		break;
	case UCODE_LOAD_AUDIO:
		{
			CChanInfo	*uap;
			GetUndoArray(uap, State);
			if ((UValFlags(State) & UFLAG_DIR) == UFLAG_INS) {
				GetChan(uap->m_Index)->OpenItem(uap);
				GetChan(uap->m_Index)->SetInfo(uap);
			} else
				GetChan(uap->m_Index)->Reset();
		}
		break;
	case UCODE_INSERT_AUDIO:
		RestoreUndoItems(State);
		break;
	case UCODE_SHOW_VOLUME:
	case UCODE_SHOW_SNAPSHOT:
	case UCODE_SHOW_MS_FADE:
	case UCODE_SHOW_TEMPO:
		ShowDlgBar(UValBarNum(State) - 1, UValShowBar(State) != 0);
		break;
	case UCODE_SET_DEFAULTS:
		{
			CChanInfo	*uap;
			GetUndoArray(uap, State);
			m_ChanDefaults = *uap;
		}
		break;
	case UCODE_EDIT_AUTO:
		{
			CEditAutoUndoState	*uap;
			GetUndoArray(uap, State);
			for (int i = 0; i < UValItems(State); i++, uap++) {
				CChannel	*Chan = GetChan(uap->m_ChanIdx);
				CAutoSliderCtrl	*Auto = Chan->GetAuto(UValAutoIdx(State));
				Auto->SetInfoNotify(*uap);	// calls OnNewPos and OnSelection
				Chan->SetLoop(uap->m_ChanLoop != 0);
				// if channel transport changed, restore it and audio position
				if (uap->m_ChanTransport != Chan->GetTransport())
					Chan->SetTransportAndPos(uap->m_ChanTransport, uap->m_ChanPos);
			}
		}
		break;
	default:
		NODEFAULTCASE;		
	}
	SetCurPos(UValCurPos(State));
}
Exemple #30
0
int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop)
{
    if (!m_enabled)
    {
        return -1;
    }
    if (m_sounds.find(sound) == m_sounds.end())
    {
        GetLogger()->Debug("Sound %d was not loaded!\n", sound);
        return -1;
    }

    int channel;
    bool alreadyLoaded = false;
    if (!SearchFreeBuffer(sound, channel, alreadyLoaded))
    {
        return -1;
    }

    if (!alreadyLoaded)
    {
        if (!m_channels[channel]->SetBuffer(m_sounds[sound].get()))
        {
            m_channels[channel]->SetBuffer(nullptr);
            return -1;
        }
    }

    CChannel* chn = m_channels[channel].get();

    chn->SetPosition(pos);
    chn->SetVolumeAtrib(1.0f);

    // setting initial values
    chn->SetStartAmplitude(amplitude);
    chn->SetStartFrequency(frequency);
    chn->SetChangeFrequency(1.0f);
    chn->ResetOper();
    chn->SetFrequency(frequency);
    chn->SetVolume(powf(amplitude * chn->GetVolumeAtrib(), 0.2f) * m_audioVolume);
    chn->SetLoop(loop);
    chn->Mute(false);

    if (!chn->Play())
    {
        m_channelsLimit = m_channels.size() - 1;
        GetLogger()->Debug("Changing channel limit to %u.\n", m_channelsLimit);
        m_channels.erase(channel);

        return -1;
    }

    return channel | ((chn->GetId() & 0xffff) << 16);
}