コード例 #1
0
ファイル: ASTree.c プロジェクト: chantalgo/NSBL_gcDev
struct Node* ast_new_node(int token, int nch, struct Node** child, long long line){
    struct Node* node = (struct Node *) malloc ( sizeof (struct Node) );  // free in ast_free_tree
/*	if(token==BELONG && 0){   // not used 
		char* temp = strCatAlloc("", 3, child[1]->lexval.sval, "_", child[0]->lexval.sval);
		//child[1]->code = child[1]->lexval.sval;
		child[1]->lexval.sval = temp;
        
	}*/

    node->token = token;
    node->type = UNKNOWN_T;             // default
    node->typeCon = NULL;
    node->nch = nch;                    // assign children
    node->child = child;        
    node->symbol = NULL;                // default NULL
    node->line = line;                  // line # in source (for corresponding token)
    node->code = NULL;                  
    node->codetmp = NULL;
    node->scope[0] = sStackLevel;
    node->scope[1] = sStackTopId;
    node->tmp[0] = 0;
#ifdef _AST_DEBUG_EXTRA
    debugInfo("ast_new_node :: create \n");
    debugInfo("==DEBUG INFO==\n");
    ast_output_tree(node, stdout,0);
#endif
    return node;
}
コード例 #2
0
void CommonString::setString( const unsigned char * charstr )
{
    debugInfo (   __FILE__, __LINE__); 


    //set me to be a NULL  ?
    if( charstr == NULL)
    {
        this->clear();
        return;
    }

    //use my char pointer to set to myself ??
    if( this->stringData ==  charstr ) 
    {
        return ;
    }

    debugInfo (   __FILE__, __LINE__); 

    //set me to a empty string "" 
    if( charstr[0]==0 )
    {  
        if(string_debug_cg)
        {
            printf(" hit ! \n");
        }
        this->clear();
        return;
    }

    //If this already has string , erase it.
    if ( stringData != NULL )
    {  
        this->clear();
    }
    debugInfo (   __FILE__, __LINE__);   

    //copy 
    this->size = getStringSize( charstr ) ;
    if( string_debug_cg)
    {
        printf("size = %u \n", this->size ) ;
    } 

    stringData = new unsigned char [ this->size+1 ];    
    //Not enough memory
    if( stringData  == NULL )
    {   

        this->size = 0 ;
        return;
    }    
    strcpy( (char *)this->stringData,  ( char *) charstr ) ;    
    return ;

}
コード例 #3
0
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
  bool Server::isThisNameRegistered(const QString& name) {
    for (auto user: m_online_users) {
      if (user.name == name) {
	debugInfo(name + " found a match, already registered.");
	return true;
      }
    }
    debugInfo(name + " did not found a match, going to register.");
    return false;
  }
コード例 #4
0
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
  int Server::getIndexOfUEIp(const QString& ip) {
    for (unsigned i = 0; i < m_online_users.size(); ++i) {
      if (m_online_users.at(i).ip == ip) {
	debugInfo(ip + " found a match at index: " + QString::number(i));
	return i;
      }
    }
    debugInfo(ip + " was not found on list. Returning -1.");
    return -1;
  }
コード例 #5
0
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
  bool Server::isThisIpRegistered(const QString& ip) {
    for (auto user: m_online_users) {
      if (user.ip == ip) {
	debugInfo(ip + " found a match, already registered.");
	return true;
      }
    }
    debugInfo(ip + " did not found a match, going to register.");
    return false;
  }
コード例 #6
0
ファイル: indigo_io.cpp プロジェクト: equilion/indigo
void IndigoOutput::toString (Array<char> &str)
{
   if (_own_buf)
      str.copy(_buf);
   else
      throw IndigoError("can not convert %s to string", debugInfo());
}
コード例 #7
0
ファイル: abstractplannode.cpp プロジェクト: EasonYi/voltdb
string AbstractPlanNode::debug(const string& spacer) const
{
    ostringstream buffer;
    buffer << spacer << "* " << debug() << "\n";
    string info_spacer = spacer + "  |";
    buffer << debugInfo(info_spacer);
    //
    // Inline PlanNodes
    //
    if (!m_inlineNodes.empty()) {
        buffer << info_spacer << "Inline Plannodes: "
               << m_inlineNodes.size() << "\n";
        string internal_spacer = info_spacer + "  ";
        map<PlanNodeType, AbstractPlanNode*>::const_iterator it;
        for (it = m_inlineNodes.begin(); it != m_inlineNodes.end(); it++) {
            buffer << info_spacer << "Inline "
                   << planNodeToString(it->second->getPlanNodeType())
                   << ":\n";
            buffer << it->second->debugInfo(internal_spacer);
        }
    }
    //
    // Traverse the tree
    //
    string child_spacer = spacer + "  ";
    for (int ctr = 0, cnt = static_cast<int>(m_children.size()); ctr < cnt; ctr++) {
        buffer << child_spacer << m_children[ctr]->getPlanNodeType() << "\n";
        buffer << m_children[ctr]->debug(child_spacer);
    }
    return (buffer.str());
}
コード例 #8
0
CommonString::CommonString( ) 
{
    debugInfo (   __FILE__, __LINE__); 
    stringData = NULL;    
    size = 0; 

}
コード例 #9
0
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
 QString Server::filterMessage(QString& dest, QString &from, QString data) {
   //currently, a data structure has the following format
   //    ue_message(message);ue_dest(dest);ue_from(sender);
   //This function extracts both dest and message
   int i1 = data.indexOf("ue_message") + QString("ue_message").size() + 1;
   int i2 = data.indexOf("ue_dest") - 2;
   int i3 = data.indexOf("ue_dest") + QString("ue_dest").size() + 1;
   int i4 = data.indexOf("ue_from") - 2;
   int i5 = data.indexOf("ue_from") + QString("ue_from").size() + 1;
   int i6 = data.lastIndexOf(";") - 1;
   dest = data.mid(i3, i4 - i3) ;
   from = data.mid(i5, i6 - i5);
   debugInfo("Parsed dest:" + dest);
   debugInfo("Parsed dender:" + from);
   debugInfo("Parsed message:" + data.mid(i1, i2 - i1));
   return data.mid(i1, i2 - i1);
 }
コード例 #10
0
/**
 * Internal function used to clear persistent data (counters and SD) if requested by user at reset.
 *
 * @return <tt>true</tt> if all persistent data have been cleared
 */
boolean
clearAllPersistentDataOnRequest()
{
  delay(1000);

  if (digitalRead(USER_SWITCH_PIN) == LOW)
  {
    debugInfo("@Clear\r\n");
    // reset all counters
    counters.reset();

    if (sdFileLogger.clear())
    {
      debugInfo("@SD Cleared\r\n");
    }
    return true;
  }
  return false;
}
コード例 #11
0
string AbstractPlanNode::debug(const string& spacer) const
{
    std::ostringstream buffer;
    buffer << spacer << "* " << debug() << "\n";
    std::string info_spacer = spacer + "  |";
    buffer << debugInfo(info_spacer);
    //
    // Inline PlanNodes
    //
    if (!m_inlineNodes.empty()) {
        buffer << info_spacer << "Inline Plannodes: "
               << m_inlineNodes.size() << "\n";
        string internal_spacer = info_spacer + "  ";
        map<PlanNodeType, AbstractPlanNode*>::const_iterator it;
        for (it = m_inlineNodes.begin(); it != m_inlineNodes.end(); it++) {
            buffer << info_spacer << "Inline "
                   << planNodeToString(it->second->getPlanNodeType())
                   << ":\n";
            buffer << it->second->debugInfo(internal_spacer);
        }
    }
    //
    // Output table
    //
    Table* outputTable = getOutputTable();
    buffer << info_spacer << "Output table:\n";
    if (outputTable != NULL) {
        buffer << outputTable->debug(spacer + "  ");
    }
    else {
        buffer << "  " << info_spacer << "<NULL>\n";
    }
    //
    // Input tables
    //
    for (int i = 0; i < getInputTableCount(); ++i) {
        Table* inputTable = getInputTable(i);
        buffer << info_spacer << "Input table " << i << ":\n";
        if (inputTable != NULL) {
            buffer << inputTable->debug(spacer + "  ");
        }
        else {
            buffer << "  " << info_spacer << "<NULL>\n";
        }
    }
    //
    // Traverse the tree
    //
    string child_spacer = spacer + "  ";
    for (int ctr = 0, cnt = static_cast<int>(m_children.size()); ctr < cnt; ctr++) {
        buffer << child_spacer << m_children[ctr]->getPlanNodeType() << "\n";
        buffer << m_children[ctr]->debug(child_spacer);
    }
    return (buffer.str());
}
コード例 #12
0
ファイル: ConvertVar.cpp プロジェクト: PuerkitoBio/locic
		// Attach the variable to the SemanticAnalysis node tree.
		void attachVar(Context& context, const String& name, const AST::Node<AST::TypeVar>& astTypeVarNode, SEM::Var* const var, const Debug::VarInfo::Kind varKind) {
			assert(var->isBasic());
			
			const auto insertResult = insertVar(context.scopeStack().back(), name, var);
			if (!insertResult.second) {
				const auto existingVar = insertResult.first->second;
				throw ErrorException(makeString("Variable name '%s' at position %s duplicates existing variable of the same name at position %s.",
					name.c_str(), astTypeVarNode.location().toString().c_str(),
					existingVar->debugInfo()->declLocation.toString().c_str()));
			}
			
			var->setDebugInfo(makeVarInfo(varKind, astTypeVarNode));
		}
コード例 #13
0
/**
 * LEDs initialization
 */
void
initSD()
{
  pinMode(SD_CARD_CHIP_SELECT_PIN, OUTPUT);

  debugInfo("@SD_");

  if (!SD.begin(SD_CARD_CHIP_SELECT_PIN))
  {
    debugInfo("KO\r\n");
  }
  else
  {
    debugInfo("OK\r\n");
  }

  if (!clearAllPersistentDataOnRequest())
  {
    debugInfo("@Restart\r\n");
    resetCounter.increment(1);
  }
}
コード例 #14
0
void CommonString::append( const unsigned char * charstr )
{

    if ( charstr == 0 )
    return ;
    

    //NULL and empty string "" is different
    
    size_t part2Size ;
    part2Size = strlen( (const   char *)charstr );
    if (   part2Size <= 0)
    {
        return ;
    }    


    //Both str1 and str2 have something, none of them are "" ""

    debugInfo (   __FILE__, __LINE__); 

   
    unsigned char * temp_p;
    unsigned long size;
    size = this->getSize() + part2Size + 1;
    
    temp_p = new unsigned char [ size ];   
   
    debugInfo (   __FILE__, __LINE__); 
    strcpy ( ( char *)temp_p, (const  char *)this->getChar_p_readonly()  );
    strcat( (char *)temp_p  ,  (const char *)charstr );
    
    this->setString( temp_p);
    delete temp_p;
    
    return    ;


}    
コード例 #15
0
ファイル: SymbolTable.c プロジェクト: norman0612/NSBL_gcDev
// destroy Symbol Table entry
void s_destroy_entry ( gpointer dummy1, gpointer entry, gpointer dummy2 ) {
#ifdef _DEBUG
    debugInfo("Destroy Entry: ");
    s_show_entry(NULL, entry, DEBUGIO);
#endif
    SymbolTableEntry* e = ( SymbolTableEntry* ) entry ; 
    if (e->typeCon != NULL) {
        g_array_free( e->typeCon, 1 );
#ifdef _DEBUG
        debugInfoExt(" >> destroy typeCon... \n");
#endif
    }

    free( e );
}
コード例 #16
0
ファイル: SymbolTable.c プロジェクト: norman0612/NSBL_gcDev
GList* s_table_all_variables_in_scope (SymbolTable* table, ScopeId sid, int type) {
    GList* gl = NULL;
    GList* vals = g_hash_table_get_values( table );
    int i, l = g_list_length( vals );
    for ( i=0; i<l; ++i ) {
        SymbolTableEntry * e = (SymbolTableEntry *) g_list_nth_data( vals, i );
        if ( e->scope[1] == sid && e->type == type ) { 
#ifdef _DEBUG
            debugInfo("s_table_all_variables_in_scope: sid = %d, type = %d, %s\n", sid, type, e->bind);
#endif
            gl = g_list_append( gl, (gpointer) e );
        }
    }
    g_list_free(vals);
    return gl;
}
コード例 #17
0
ファイル: ModuleI2C.cpp プロジェクト: ChriD/iRadio
    int ModuleI2C::init()
    {
        bool ret = Module::init();

        if(ret)
        {
            // wiring PI Setup always returns 0. it does fatal faults...
            wiringPiSetup();
            i2cFileHandle = wiringPiI2CSetup(i2cAddress);
            if(i2cFileHandle == -1)
                return failed("I2C file handle for address " + std::to_string(i2cAddress) + " could not be created");
        }

        debugInfo("I2C Library init done for device on address: " + std::to_string(i2cAddress));

        return ret;
    }
コード例 #18
0
ファイル: ASTree.c プロジェクト: chantalgo/NSBL_gcDev
void ast_free_tree(struct Node* node) {
    if ( node == NULL ) return;
#ifdef _AST_DEBUG_MEMORY
    debugInfo("TO FREE node:");
    ast_output_node(node, DEBUGIO, "\n");
#endif
    /* free sval */
    if ( node->token == STRING_LITERAL || node->token == IDENTIFIER ) {
#ifdef _AST_DEBUG_MEMORY
        debugInfo("FREE sval: %s\n",node->lexval.sval); 
#endif
        free(node->lexval.sval);        // malloc by LexAly.l
        node->lexval.sval = NULL;
    }
    /* free code */
    if ( node->code != NULL ) {
#ifdef _AST_DEBUG_MEMORY
        debugInfo("FREE code: %s\n", node->code);
#endif
        free(node->code); node->code = NULL;
    }
    if ( node->codetmp != NULL ) {
#ifdef _AST_DEBUG_MEMORY
        debugInfo("FREE codetmp: %s\n", node->codetmp);
#endif
        free(node->codetmp); node->codetmp = NULL;
    }
    /* if child exsits, free child first */
    if ( node->nch > 0 && node->child != NULL ) {
        // free children
        int i;for(i=0; i<node->nch; ++i) { 
            ast_free_tree( node->child[i] ); 
            node->child[i] = NULL;
        }
        // free child ptr array
#ifdef _AST_DEBUG_MEMORY
        debugInfo("FREE child ptrs in ");
        ast_output_node(node, DEBUGIO, "\n");
#endif
        free(node->child); node->child = NULL;
    }
    else if (node->nch > 0 || node->child != NULL) {
        fprintf(stderr, "ERROR:: ast_free_tree :: nch does NOT match child! code bug detected!!\n ");
    }
    /* free myself */
#ifdef _AST_DEBUG_MEMORY
    debugInfo("FREE this node : %d", node->token);
    ast_output_node(node, DEBUGIO, "\n");
    fflush(DEBUGIO);
#endif
    free(node); node = NULL;
    return;
}
コード例 #19
0
// Broadcast character's position
void GameEngine::SendCharacterPosition(int _indexCharacter)
{
	MovingObject *character = m_characters[_indexCharacter];
	if (character == NULL || character->IsDead())
		return;

	InfoForDisplay info = character->GetInfoForDisplay();
	Event posInfo(&info);
	m_eventEngine->dispatch(CHAR_POS_UPDATED, &posInfo);
#ifdef DEBUG_MODE
	if (_indexCharacter == m_indexMario)
	{
		*m_debugInfo = character->GetDebugInfo();
		Event debugInfo(m_debugInfo);
		m_eventEngine->dispatch(DEBUG_INFO_UPDATED, &debugInfo);
	}
#endif
}
コード例 #20
0
std::string
AbstractExpression::debug(const std::string &spacer) const
{
    std::ostringstream buffer;
    buffer << spacer << "+ " << debug() << "\n";

    std::string info_spacer = spacer + "   ";
    buffer << debugInfo(info_spacer);

    // process children
    if (m_left != NULL || m_right != NULL) {
        buffer << info_spacer << "left:  " <<
          (m_left != NULL  ? "\n" + m_left->debug(info_spacer)  : "<NULL>\n");
        buffer << info_spacer << "right: " <<
          (m_right != NULL ? "\n" + m_right->debug(info_spacer) : "<NULL>\n");
    }
    return (buffer.str());
}
コード例 #21
0
void CommonString::print( void )
{
    debugInfo (   __FILE__, __LINE__); 

    if( this->getChar_p()!= NULL )
    {    	
        if( this->getSize() <=0)
            printf("<empty string \"\"> " );
        else 
            printf("%s", this->getChar_p() );

    }else
    {
        printf("<NULL>" );

    }


}
コード例 #22
0
/**
 * Internal function used to initialize serial debug.
 */
void
initDebugSerial()
{
  SERIAL_DEBUG.begin(SERIAL_DEBUG_BAUDRATE);
  debugInfo("@Reset\r\n");
}
コード例 #23
0
//设置在屏幕上的坐标(像素)
VOID CCreatureBoard::SetPosition(FLOAT nX, FLOAT nY)
{
	float fAlpha = 1.0f;
	if(m_nDistance > CUICreatureBoardSystem::GetMe()->GetMaxDispearDistance())
	{
		m_pWindow->hide();
		return;
	}

	if(m_nDistance > CUICreatureBoardSystem::GetMe()->GetMaxDistance())
	{
		fAlpha -= (m_nDistance - CUICreatureBoardSystem::GetMe()->GetMaxDistance() )/
					( CUICreatureBoardSystem::GetMe()->GetMaxDispearDistance() - CUICreatureBoardSystem::GetMe()->GetMaxDistance());
	}

	CEGUI::Point fPos(nX, nY);
	float fOffset = 0;
	float fY = fPos.d_y;
	CEGUI::Size size;	

	// 判断是否要显示
	if( m_bShowHpLevel )
	{
		if( m_pHPlevelWindow && m_pHPWindow )
		{
			// 计算位置
			fOffset -= m_pHPlevelWindow->getAbsoluteHeight();
			fPos.d_y += fOffset;
			fPos.d_x -= m_pHPlevelWindow->getAbsoluteWidth() / 2.0f;
			m_pHPlevelWindow->setPosition(CEGUI::Absolute, fPos);

			// 血条
			m_pHPWindow->setPosition(CEGUI::Absolute, fPos);

			// 设置进度
			((CEGUI::ProgressBar*)m_pHPWindow)->setProgress( m_fProgross );

			//laim1648 m_pHPWindow->show();
		}
	}
	
	// 恢复x偏移
	fPos.d_x = nX;
	fPos.d_y = nY;

	// 计算名字的位置
	fPos.d_y += fOffset;

	( ( CEGUI::IFalagardSelfFitWindow* )( CEGUI::FalagardSelfFitWindow* )m_pNameWindow )->setCenter(fPos);
	fOffset -= m_pNameWindow->getAbsoluteHeight();
	
	// 名字
	if( m_pNameWindow->isVisible() && !( m_pNameWindow->getText().empty() ) )
	{
		m_pWindow->show();
		debugInfo();
	}
	else
	{
		// 摆摊状态时,其他玩家名字不显示时,信息板还要显示	20100527 BLL
		if ( m_bShowStallSign == FALSE ) 
		{
			m_pWindow->hide();
		}
		else
			m_pWindow->show();
	}

	// 20100504 AddCodeBegin
	// 级别显示在玩家名字后面
	if( m_bShowHpLevel )
	{
		CEGUI::Point fLevelPos = m_pNameWindow->getAbsolutePosition();
		CEGUI::Size  nameSize  = m_pNameWindow->getAbsoluteSize();

		fLevelPos.d_x = fLevelPos.d_x + nameSize.d_width;

		( ( CEGUI::IFalagardSelfFitWindow* )( CEGUI::FalagardSelfFitWindow* )m_pLevelTextWindow )->setCenter(fLevelPos);

		m_pLevelTextWindow->setPosition( CEGUI::Absolute, fLevelPos );
		m_pLevelIcoWindow->setPosition(  CEGUI::Absolute, fLevelPos );

		if( !m_bShowLevelIco )
		{
			m_pLevelTextWindow->show();
		}
		else
		{
			size = m_pNameWindow->getAbsoluteSize();
			size.d_width = size.d_height;
			m_pLevelIcoWindow->setSize( CEGUI::Absolute, size );
			m_pLevelIcoWindow->show();
		}
	}
	// 20100504 AddCodeEnd

	
	// 国家称号
	if( m_bCountryTitle && !( m_pCountryTitleWindow->getText().empty() ) )
	{
		fPos.d_y = fY + fOffset;
		((CEGUI::IFalagardSelfFitWindow*)(CEGUI::FalagardSelfFitWindow*)m_pCountryTitleWindow)->setCenter( fPos );
		fOffset -= m_pCountryTitleWindow->getAbsoluteHeight();

		m_pCountryTitleWindow->show();
	}

	// 帮会称号
	if( m_bGuildTitle && !( m_pGuildTitleWindow->getText().empty() ) )
	{
		fPos.d_y = fY + fOffset;
		((CEGUI::IFalagardSelfFitWindow*)(CEGUI::FalagardSelfFitWindow*)m_pGuildTitleWindow)->setCenter( fPos );	
		fOffset -= m_pGuildTitleWindow->getAbsoluteHeight();

		m_pGuildTitleWindow->show();
	}

	// 称号
	if( m_bTitle && !(m_pTitleWindow->getText().empty()) )
	{
		fPos.d_y = fY + fOffset;
		((CEGUI::IFalagardSelfFitWindow*)(CEGUI::FalagardSelfFitWindow*)m_pTitleWindow)->setCenter(fPos);	
		fOffset -= m_pTitleWindow->getAbsoluteHeight();

		m_pTitleWindow->show();
	}

	// 摆摊
	if( m_pSaleWindow->isVisible() )
	{
		fPos.d_y = fY + fOffset;
		m_pSaleWindow->setProperty( "HookPosition", CEGUI::PropertyHelper::pointToString( fPos ) );
		((CEGUI::PushButton*)m_pSaleWindow)->resizeWithText();
		fOffset -= m_pSaleWindow->getAbsoluteHeight();
	}

	// 头顶泡泡
	if( m_pPaoPao->isVisible() )
	{
		fPos.d_y = fY + fOffset;
		((CEGUI::IFalagardSelfFitWindow*)(CEGUI::FalagardSelfFitWindow*)m_pPaoPao)->setCenter(fPos);
		fOffset  -= m_pPaoPao->getAbsoluteHeight();
	}

	// PK标志 
	// 20100513 ModifyCodeBegin
	if( m_pPKWindow->isVisible() ) 
	{
		CEGUI::Size pkSize;

		fOffset -= m_pPKWindow->getAbsoluteHeight();
		fPos.d_y = fY + fOffset;
		fPos.d_x = nX - m_pPKWindow->getAbsoluteWidth() / 2;

		//pkSize.d_width  = ((CEGUI::StaticImage*)m_pPKWindow)->getImage()->getWidth();
		//pkSize.d_height = ((CEGUI::StaticImage*)m_pPKWindow)->getImage()->getHeight();

		pkSize = CEGUI::AnimateManager::getSingleton().getAnimate( (CEGUI::utf8*)"questsign_accept" )->getSize();

		m_pPKWindow->setSize( CEGUI::Absolute, pkSize );
		m_pPKWindow->setPosition( CEGUI::Absolute, fPos );
	}
	// 20100513 ModifyCodeEnd


	// 国家标志
	size = m_pNameWindow->getAbsoluteSize();
	fPos = m_pNameWindow->getAbsolutePosition();

	fPos.d_x -= size.d_height;
	m_pCountryFlag->setPosition(CEGUI::Absolute, fPos);

	size.d_width = size.d_height;
	m_pCountryFlag->setSize(CEGUI::Absolute, size);


	// 队长标志
	size = m_pNameWindow->getAbsoluteSize();
	fPos = m_pNameWindow->getAbsolutePosition();

	// 20100504 ModifyCodeBegin 级别改为在名字后面显示后,修改队长标记位置
	CEGUI::Size  levelTextSize = m_pLevelTextWindow->getAbsoluteSize();

	fPos.d_x += size.d_width;
	fPos.d_x += levelTextSize.d_width;
	// 20100504 ModifyCodeEnd

	m_pLeadFlag->setPosition(CEGUI::Absolute, fPos);
	size.d_width = size.d_height;
	m_pLeadFlag->setSize(CEGUI::Absolute, size);


	// 帮派权限图标标的位置
	size = m_pTitleWindow->getAbsoluteSize();
	fPos = m_pTitleWindow->getAbsolutePosition();

	fPos.d_x -= size.d_height;
	m_pBangpaiFlag->setPosition( CEGUI::Absolute, fPos );

	size.d_width = size.d_height;
	m_pBangpaiFlag->setSize( CEGUI::Absolute, size );


	// 设置透明度
	m_pCountryFlag->setAlpha( fAlpha );
	m_pBangpaiFlag->setAlpha( fAlpha );
	m_pLeadFlag->setAlpha( fAlpha );
	m_pPKWindow->setAlpha( fAlpha );
	m_pSaleWindow->setAlpha( fAlpha );
	m_pNameWindow->setAlpha( fAlpha );
	m_pTitleWindow->setAlpha(fAlpha);
	m_pCountryTitleWindow->setAlpha(fAlpha);
	m_pGuildTitleWindow->setAlpha(fAlpha);


	switch( m_InfoState ) 
	{
	case STATE_NORMAL:
		break;
	case STATE_DIE:
		m_pNameWindow->setProperty( "TextColor", CEGUI::PropertyHelper::colourToString( CEGUI::colour( 0.5,0.5,0.5, fAlpha ) ) );
		break;
	default:
		break;
	}
}
コード例 #24
0
ファイル: DebugLoop.cpp プロジェクト: hostilefork/titlewait
// See if a previous image is still running of the process we're debugging
// Might want to keep the thread/process in a state of suspended animation
BOOL PreviousStillRunning(std::wstring & exeImageName, DWORD processId) 
{
	// Why all this rigamorole when there's:
	//
	//      DebugEv->u.CreateProcessInfo.lpImageName?
	//
	// Ok, here's why:
	//
	// "This member is strictly optional. Debuggers must be prepared to handle
	// the case where lpImageName is NULL or *lpImageName (in the address space
	// of the process being debugged) is NULL. Specifically, the system does
	// not provide an image name for a create process event, and will not
	// likely pass an image name for the first DLL event. The system also
	// does not provide this information in the case of debug events that
	// originate from a call to the DebugActiveProcess function.

	DWORD dwPIDCount;
	static smPROCESSINFO lpi[MAX_PI] = {0};

	// Get processes list
	debugInfo(L"Beginning process enumeration");
	dwPIDCount = EnumProcesses2Array(lpi);
	debugInfo(L"Ending process enumeration");

	smPROCESSINFO* outerExecutiveProcessInfo = NULL;
	// remember we run a "CMD" via system()
	smPROCESSINFO* cmdShellOuterProcessInfo = NULL;
	// remember we run a "CMD /C" via system() 
	smPROCESSINFO* cmdShellInnerProcessInfo = NULL;
	smPROCESSINFO* nestedExecutiveProcessInfo = NULL;
	smPROCESSINFO* mainDebuggeeProcessInfo = NULL;

	DWORD outerExecutiveProcessId = GetCurrentProcessId();
	DWORD cmdShellOuterProcessId = 0;
	DWORD cmdShellInnerProcessId = 0;
	DWORD nestedExecutiveProcessId = 0;
	DWORD mainDebuggeeProcessId = 0;
	{ 
		if (WaitForSingleObject(processListMutex, INFINITE) != WAIT_OBJECT_0)
			WindowsVerify(L"WaitForSingleObject", FALSE);
		if (numProcesses > 0)
			cmdShellOuterProcessId = processIds[0];
		if (numProcesses > 1)
			cmdShellInnerProcessId = processIds[1];
		if (numProcesses > 2)
			nestedExecutiveProcessId = processIds[2];
		if (numProcesses > 3)
			mainDebuggeeProcessId = processIds[3];
		WindowsVerify(L"ReleaseMutex", ReleaseMutex(processListMutex));
	}

	// little sanity check here...
	// How would we receive these debug events if the shell isn't running?!
	Verify(L"Nested executive command process couldn't be found.",
		cmdShellOuterProcessId != 0
	);

	if (mainDebuggeeProcessId == 0) {
		return FALSE; // not ready to do the process test yet.
	}
	
	if (processId != 0 and mainDebuggeeProcessId != processId) {
		return FALSE; // don't suspend threads in wrong process!
	}

	for (int index = 0; index < dwPIDCount; index++) {
		if (lpi[index].dwPID == outerExecutiveProcessId)
			outerExecutiveProcessInfo = &lpi[index];
		if (lpi[index].dwPID == cmdShellOuterProcessId)
			cmdShellOuterProcessInfo = &lpi[index];
		if (lpi[index].dwPID == cmdShellInnerProcessId)
			cmdShellInnerProcessInfo = &lpi[index];
		if (lpi[index].dwPID == nestedExecutiveProcessId)
			nestedExecutiveProcessInfo = &lpi[index];
		if (lpi[index].dwPID == mainDebuggeeProcessId)
			mainDebuggeeProcessInfo = &lpi[index];
	}
	
	debugInfo(L"GetNtProcessInfo(%s)", mainDebuggeeProcessInfo->szImgPath);

	for (int index = 0; index < dwPIDCount; index++) {

		if (lpi[index].dwPID == outerExecutiveProcessId)
				continue;
		if (lpi[index].dwPID == cmdShellOuterProcessId)
				continue;
		if (lpi[index].dwPID == cmdShellInnerProcessId)
				continue;
		if (lpi[index].dwPID == nestedExecutiveProcessId)
				continue;
		if (lpi[index].dwPID == mainDebuggeeProcessId)
				continue;

		// windows filenames are case insensitive
		debugInfo(L"Process Image: %s", lpi[index].szImgPath);
		if (!lstrcmpi(mainDebuggeeProcessInfo->szImgPath, lpi[index].szImgPath)) {
			exeImageName = std::wstring(mainDebuggeeProcessInfo->szImgPath);
			return TRUE;
		}
	}

	return FALSE;
}
コード例 #25
0
ファイル: DebugLoop.cpp プロジェクト: hostilefork/titlewait
// EnterDebugLoop was taken from:
// http://msdn.microsoft.com/en-us/library/ms681675(VS.85).aspx
//
// Note that we don't actually *want* to be a debugger, but CreateProcess has
// some bug or security dependency which is leading it to (in some situations)
// not show the window of the process it launches.  Somehow, calling a debug
// loop addresses this.  I've left the full code from the sample here in order
// to make it easier to set breakpoints to discover what's going wrong if
// there is a problem with the technique of working around CreateProcess's
// flaw with the debug API.
//
DWORD WINAPI DebugLoopMain(LPVOID lpParam) // returns a MainReturn
{
	DebugArgs & debugArgs = *static_cast<DebugArgs *>(lpParam);

	HMODULE ntDllModule = sm_LoadNTDLLFunctions();

	debugInfo(L"Got to DebugLoopMain thread code.");

	PROCESS_INFORMATION processInfo;
	processInfo.hProcess = NULL;
	processInfo.hThread = NULL;

	// Windows can modify the command line, so we have to make a copy
	std::vector<WCHAR> commandLineCopy (
		debugArgs.commandLine.begin(),
		debugArgs.commandLine.end()
	);
	commandLineCopy.push_back(L'\0');

	DWORD dwCreationFlags =
#ifdef USE_STARTUPINFO_FOR_WINDOW_POSITION
			// These options don't work :-(
			(config->runWindowPosition ? STARTF_USEPOSITION : 0) |
			(config->runWindowSize ? STARTF_USESIZE : 0) |
#endif
			(config->shutdownEvent ? 0 : DEBUG_PROCESS) |
			STARTF_USESHOWWINDOW;

	// REVIEW: for security should lpApplicationName be the same as the 
	// name in the command line?
	WindowsVerify(
		L"CreateProcess",
		CreateProcess(
			0, // lpApplicationName
			&commandLineCopy[0], // lpCommandLine (no .data() in C++98)
			0, // lpProcessAttributes
			0, // lpThreadAttributes
			config->shutdownEvent == NULL ? TRUE : FALSE, // bInheritHandles
			dwCreationFlags,
			0, // lpEnvironment
			0, // lpCurrentDirectory
			debugArgs.startupInfo, // lpStartupInfo
			&processInfo // lpProcessInformation
		)
	);

	Verify(L"Thread or process was null.", 
		processInfo.hThread and processInfo.hProcess
	);

	debugInfo(L"CreateProcess(%s) - Id = %d\n", 
		debugArgs.commandLine.c_str(), processInfo.dwProcessId
	);

	debugInfo(L"Entering debugger loop...\n");

	HANDLE suspendedThread = NULL;
	BOOL previouslyWaited = FALSE;

	DEBUG_EVENT Ev;
	const LPDEBUG_EVENT DebugEv = &Ev;

	while (TRUE) {

		// Wait for a debugging event to occur. The second parameter indicates
		// that the function does not return until a debugging event occurs. 

		BOOL gotDebugEvent = FALSE;
		BOOL handledEvent = TRUE;

		DWORD tickBefore = GetTickCount();
		if (WaitForDebugEvent(
			DebugEv,
			suspendedThread ? 1000 : *debugArgs.msecLeft
		)) {
			gotDebugEvent = TRUE;
		} else {
			DWORD lastError = GetLastError();
			if (lastError == 0x79) {
				// The semaphore timeout period has expired, that is ok
			} else {
				ExitProgramOnWindowsError(L"WaitForDebugEvent", lastError);
			}
		}

		if (suspendedThread) {
			switch(WaitForSingleObject(debugArgs.retryEvent, 0)) {
			case WAIT_OBJECT_0: {
				WindowsVerify(L"ResetEvent", ResetEvent(debugArgs.retryEvent));
				// need to poll processes again...
				std::wstring exeImageName;
				if (PreviousStillRunning(exeImageName, 0)) {
					debugInfo(L"Retry failed, show message box again.");
					WindowsVerify(L"SetEvent", SetEvent(debugArgs.deferEvent));
				} else {
					debugInfo(L"Resuming thread handle 0x%x", suspendedThread);
					WindowsVerify(L"ResumeThread",
						ResumeThread(suspendedThread) != -1
					);
					WindowsVerify(L"CloseHandle", CloseHandle(suspendedThread));
					suspendedThread = NULL;
					previouslyWaited = TRUE;
				}
				break;
			}
			case WAIT_TIMEOUT:
				// nope, do nothing, try again in a second...
				break;
			default:
				WindowsVerify(L"WaitForSingleObject", FALSE);
			}
		}

		DWORD tickAfter = GetTickCount();
		if (*debugArgs.msecLeft != INFINITE) {
			bool timedOut = false;
			if (tickAfter < tickBefore) {
				// happens once every 28 days, the tick count rolls over...
				// account for the rollover only
				if (tickBefore > *debugArgs.msecLeft) {
					timedOut = true;
				} else {
					*debugArgs.msecLeft = *debugArgs.msecLeft - tickBefore;
				}
			} else {
				if (tickAfter - tickBefore > *debugArgs.msecLeft) {
					timedOut = true;
				} else {
					*debugArgs.msecLeft =
						*debugArgs.msecLeft - (tickAfter - tickBefore);
				}
			}
			if (timedOut) {
				// Need to take the screenshot here, because if we return from
				// the DebugLoop the windows will be closed and the state lost
				// by the time we return to the caller
				if (not config->timeoutSnapshot.empty()) {
					Verify(L"Screen Capture Failed", 
						TakeScreenshotToFile(config->timeoutSnapshot.c_str())
					);
				}
				return TitleWait::TimeoutReturn;
			}
		}

		// Process the debugging event code. 
		if (gotDebugEvent) {
			switch (DebugEv->dwDebugEventCode) { 

			case EXCEPTION_DEBUG_EVENT: {
				// Process the exception code. When handling 
				// exceptions, remember to set the continuation 
				// status parameter (dwContinueStatus). This value 
				// is used by the ContinueDebugEvent function. 
	 
				switch(DebugEv->u.Exception.ExceptionRecord.ExceptionCode) { 

				case EXCEPTION_ACCESS_VIOLATION: {
					// First chance: Pass this on to the system. 
					// Last chance: Display an appropriate error.

					debugInfo(L"EXCEPTION_ACCESS_VIOLATION");

					if (not config->crashSnapshot.empty()) {
						Verify(L"Screen Capture Failed",
							TakeScreenshotToFile(config->crashSnapshot.c_str())
						);
					}
	 				debugInfo(L"Child Process Crashed - Quitting");
					return TitleWait::CrashedReturn;
				}
	 
				case EXCEPTION_BREAKPOINT: {
					// First chance: Display the current 
					// instruction and register values.
					debugInfo(L"EXCEPTION_BREAKPOINT");
	
					// No process functions during CREATE_PROCESS_DEBUG_EVENT
					// have to wait for a later time
					if (!config->defer or previouslyWaited or suspendedThread)
						break;

					if (PreviousStillRunning(
						debugArgs.exeImageName, DebugEv->dwProcessId
					)) {
						WindowsVerify(L"SetEvent", SetEvent(debugArgs.deferEvent));

						// don't block, keep processing debug events...
						// but suspend the thread!
						debugInfo(
							L"About to suspend thread handle 0x%x", 
							DebugEv->dwThreadId
						);
						suspendedThread = OpenThread(
							THREAD_SUSPEND_RESUME, FALSE, DebugEv->dwThreadId
						);
						WindowsVerify(L"OpenThread", suspendedThread != NULL);
						WindowsVerify(L"Suspend Thread",
							SuspendThread(suspendedThread) != -1
						);
						}
					}
					break;
	 
				case EXCEPTION_DATATYPE_MISALIGNMENT: 
					// First chance: Pass this on to the system. 
					// Last chance: Display an appropriate error.
					debugInfo(L"EXCEPTION_DATATYPE_MISALIGNMENT");
					break;
	 
				case EXCEPTION_SINGLE_STEP: 
					// First chance: Update the display of the 
					// current instruction and register values.
					debugInfo(L"EXCEPTION_SINGLE_STEP");
					break;
	 
				case DBG_CONTROL_C: 
					// First chance: Pass this on to the system. 
					// Last chance: Display an appropriate error. 
					debugInfo(L"DBG_CONTROL_C");
					break;
	 
				default:
					debugInfo(
						L"EXCEPTION_(0x%x) (unrecognized, passing through)",
						DebugEv->u.Exception.ExceptionRecord.ExceptionCode
					);
					// We have debugger behaviors for everything we
					// understand, but not random exceptions...pass on up
					// the chain and say we don't handle it.
					handledEvent = false;
					break;
				}
				break;
			}
	 
			case CREATE_THREAD_DEBUG_EVENT: {
				// As needed, examine or change the thread's registers 
				// with the GetThreadContext and SetThreadContext functions; 
				// and suspend and resume thread execution with the 
				// SuspendThread and ResumeThread functions. 

				debugInfo(
					L"CREATE_THREAD_DEBUG_EVENT - H: 0x%x - P: 0x%x",
					DebugEv->u.CreateThread.hThread,
					DebugEv->dwProcessId
				);
				break;
			}

			case CREATE_PROCESS_DEBUG_EVENT: {
				// As needed, examine or change the registers of the
				// process's initial thread with the GetThreadContext and
				// SetThreadContext functions; read from and write to the
				// process's virtual memory with the ReadProcessMemory and
				// WriteProcessMemory functions; and suspend and resume
				// thread execution with the SuspendThread and ResumeThread
				// functions. 

				SetLastError(0);
				DWORD processId = GetProcessId(
					DebugEv->u.CreateProcessInfo.hProcess
				);
				DWORD lastError = GetLastError();
				if (lastError != ERROR_SUCCESS) {
					ExitProgramOnWindowsError(L"GetProcessId", lastError);
				}

				debugInfo(
					L"CREATE_PROCESS_DEBUG_EVENT - P: 0x%x - T: 0x%x",
					processId,
					DebugEv->dwThreadId
				);

				DWORD processMonThreadId;
				HANDLE processMonThread = CreateThread( 
					NULL, // default security attributes
					0, // use default stack size  
					ProcessMonitorMain, // thread function name
					// argument to thread function
					DebugEv->u.CreateProcessInfo.hProcess, 
					CREATE_SUSPENDED, // create the thread as suspended
					&processMonThreadId);   // returns thread identifier 
				if (processMonThread == NULL) {
					WindowsVerify(L"CreateThread", FALSE);
				}

				// lock process list mutex and append tracking data for thread
				if (WaitForSingleObject(processListMutex, INFINITE) != WAIT_OBJECT_0) {
					WindowsVerify(L"WaitForSingleObject", FALSE);
				}

				processIds[numProcesses] = processId;
				processMonThreads[numProcesses] = processMonThread;
				numProcesses++;

				WindowsVerify(L"ReleaseMutex", ReleaseMutex(processListMutex));

				WindowsVerify(L"ResumeThread",
					ResumeThread(processMonThread) != -1
				);

				// "Be sure to close the handle to the process image
				// file with CloseHandle."  Ok, sure.
				WindowsVerify(L"CloseHandle",
					CloseHandle(DebugEv->u.CreateProcessInfo.hFile)
				);
				break;
			}
	 
			case EXIT_THREAD_DEBUG_EVENT:
				debugInfo(L"EXIT_THREAD_DEBUG_EVENT");
				break;
	 
			case EXIT_PROCESS_DEBUG_EVENT: {
				// Display the process's exit code.  We should only get this if
		 		// the main spawn has returned.  This should not happen, ever,
		 		// but if we catch the first spawn we can perhaps watch on it
		 		// and pipe its result back.
				debugInfo(
					L"EXIT_PROCESS_DEBUG_EVENT - ExitCode: 0x%x",
					DebugEv->u.ExitProcess.dwExitCode
				);
			
#ifdef QUIT_WHEN_MAIN_PROCESS_EXITS
				// we used to exit here, but now we wait for the LAST
				// process exiting signal.  We could in theory return
				// ClosedReturn if we want the behavior of quitting
				// just because the main process we spawned quit...but that
				// is not a good default when people are using things like
				// iexplore which launches a child.... so 
				// make that a non-default option?
				if (WaitForSingleObject(lastProcessExitedEvent, INFINITE) 
					!= WAIT_OBJECT_0
				) {
					WindowsVerify(L"WaitForSingleObject", FALSE);
				}

				if (processInfo.hThread) {
					WindowsVerify(L"CloseHandle",
						CloseHandle(processInfo.hThread)
					);
				}

				if (processInfo.hProcess) {
					WindowsVerify(L"CloseHandle",
						CloseHandle(processInfo.hProcess)
					);
				}

				sm_FreeNTDLLFunctions(ntDllModule);

				return ClosedReturn;
#endif
				break;
			}

			case LOAD_DLL_DEBUG_EVENT:
				// Read the debugging information included in the newly 
				// loaded DLL. Be sure to close the handle to the loaded DLL 
				// with CloseHandle.
				WindowsVerify(L"CloseHandle", 
					CloseHandle(DebugEv->u.LoadDll.hFile)
				);
#ifdef DEBUG_DLL_EVENTS
				// A lot of these go by, disable by default
				debugInfo(L"LOAD_DLL_DEBUG_EVENT");
#endif
				break;

			case UNLOAD_DLL_DEBUG_EVENT:
#ifdef DEBUG_DLL_EVENTS
			// A lot of these go by, disable by default
				debugInfo(L"UNLOAD_DLL_DEBUG_EVENT");
#endif
				break;
	 
			case OUTPUT_DEBUG_STRING_EVENT:
				// Client wants us to display the output debug string.
				// Pass through to WinDbg or display ourselves?
				// For now, say we don't handle it. 
				handledEvent = false;
				debugInfo(
					L"OUTPUT_DEBUG_STRING_EVENT - ExceptionCode 0x%x",
					DebugEv->u.Exception.ExceptionRecord.ExceptionCode
				);
				break;

			case RIP_EVENT:
				debugInfo(L"RIP_EVENT");
				break;
			} 

		// Resume executing the thread that reported the debugging event. 
		WindowsVerify(
			L"ContinueDebugEvent",
			ContinueDebugEvent(
				DebugEv->dwProcessId, 
				DebugEv->dwThreadId, 
				handledEvent ? DBG_CONTINUE : DBG_EXCEPTION_NOT_HANDLED
			)
		);
		}		
 	} // end while(TRUE) loop

	if (processInfo.hThread) {
		WindowsVerify(L"CloseHandle", CloseHandle(processInfo.hThread));
	}

	if (processInfo.hProcess) {
		WindowsVerify(L"CloseHandle", CloseHandle(processInfo.hProcess));
	}

	sm_FreeNTDLLFunctions(ntDllModule);

	// unreachable point
	return TitleWait::InternalErrorReturn;
}
コード例 #26
0
void AltSpeedController::updateAltitude(cvg_double curAlt, cvg_double maxAltSpeedCommand) {
	if (!enabled) return;

/*	cvg_double elapsed = dTimer.getElapsedSeconds();
	dTimer.restart(started);

	// Filter altitude
	for (cvg_int i = 0; i < ALTSC_D_FILTER_LENGTH - 1; i++)
		dHistory[i] = dHistory[i + 1];
	dHistory[ALTSC_D_FILTER_LENGTH - 1] = curAlt;

	cvg_double fAlt = 0.0;
	cvg_double weight = 2.0 / (ALTSC_D_FILTER_LENGTH + 1);
	for (cvg_int i = 0; i < ALTSC_D_FILTER_LENGTH; i++) {
		fAlt += weight * dHistory[ALTSC_D_FILTER_LENGTH - i - 1];
#if ALTSC_D_FILTER_LENGTH > 1
		weight -= (2.0 / (ALTSC_D_FILTER_LENGTH * (ALTSC_D_FILTER_LENGTH + 1)));
#endif
	}
*/
	cvg_double fAlt = curAlt;

/*	if (fAlt == lastAlt) {
		repeatCount++;
		if (repeatCount >= 10) repeatCount = 0;
	} else {
		repeatCount = 0;
	}
*/
	repeatCount++;
	if (repeatCount >= SUBSAMPLING_DIVIDER) repeatCount = 0;

	cvg_double altSpeed, altSpeedF;
	if (repeatCount == 0) {
		if (!started) {
			started = true;
			lastAlt = fAlt;
		}
		cvg_double elapsed = dTimer.getElapsedSeconds();
		dTimer.restart();
		altSpeed = (fAlt - lastAlt) / elapsed;

		// Altitude speed saturation to avoid altitude sensor peaks
		cvg_double speedLimit = fabs(maxAltSpeedCommand * ALT_SPEED_MEASURE_SATURATION_FACTOR);
		if (altSpeed > speedLimit)
			altSpeed = speedLimit;
		else if (altSpeed < -speedLimit)
			altSpeed = -speedLimit;

		lastAlt = fAlt;
//		altSpeedF = outputFilter.filter(altSpeed);
//		lastSpeedF = altSpeedF;
		lastSpeed = altSpeed;
	} else {
//		altSpeedF = lastSpeedF;
		altSpeed = lastSpeed;
	}

	altSpeedF = outputFilter.filter(altSpeed);

#ifdef SHOW_DEBUG
	debugInfo(cvgString("A_measure:") + curAlt + " A_filt:" + fAlt + " AS_calc:" + altSpeed + " AS_filt:" + altSpeedF);
#endif
	pid.setFeedback(altSpeedF);
}
コード例 #27
0
ファイル: Debug.c プロジェクト: haluuson/C_Source
void debug(int INmode)
	{
	ClearScreen();
	SDL_Flip(screen);
	selectGame(1);
	gameResetVars();

	if (INmode==2) //ClearFullRows()
		{
		for (int i=0; i<AREA_HEIGHT+2; i++)
			{
			for (int j=0; j<AREA_WIDTH; j++)
				{
				area[j][i] = (rand()%15)-EMPTY_AREA;
				if (area[j][i]>EMPTY_AREA)
					area[j][i]=area[j][i]%3+1;
				}
			}
		drawBoard();
		SDL_Delay(5000);
		clearFullRows();
		SDL_Delay(250);
		drawBoard();
		SDL_Delay(5000);
		}

	else if (INmode==3) //drawTetromino()
		{
		int tets,angl;
		for (tets=0; tets<7; tets++)
			{
			for (angl=0; angl<4; angl++)
				{
				ClearScreen();
				drawTetromino(tets,(angl+2)%4,0,0,REAL_TET);
				SDL_Flip(screen);
				SDL_Delay(600);
				}
			}
		}

	else if (INmode==4) //peiceSetinto()
		{
		pieceCreate(COMING);
		tetUD=10;
		
		drawTetromino(currentPiece,currentRotate,tetLR,tetUD,REAL_TET);
		SDL_Delay(3000);
		
		drawBoard();
		SDL_Delay(3000);
		
		pieceSetInto(currentPiece);
		drawBoard();
		SDL_Delay(3000);
		
		debugInfo(0);
		}
	
	else if (INmode==5) //peiceCreate()
		{
		for (int i=0; i<10; i++)
			{
			pieceCreate(COMING);
			ClearScreen();
			printf("c%d n%d n%d n%d\n",currentPiece,nextPiece[0],nextPiece[1],nextPiece[2]);
			SDL_Delay(100);
			}
		}
	
	else if (INmode==6) //gravity
		{
		pieceCreate(COMING);
		while(tetUD<AREA_HEIGHT) //off by 2?
			{
			ClearScreen();
			//drawBoard(true);
			drawTetromino(currentPiece,currentRotate,tetLR,tetUD,REAL_TET);
			printf("y=%d",tetUD);
			SDL_Delay(1000);
			tetUD++;
			}
		}
	}
コード例 #28
0
ファイル: Function.cpp プロジェクト: PuerkitoBio/locic
		void Function::setDebugPosition(const Debug::SourcePosition& position) {
			const auto debugLoc = llvm::DebugLoc::get(position.lineNumber(), position.column(), debugInfo());
			getBuilder().SetCurrentDebugLocation(debugLoc);
		}
コード例 #29
0
ファイル: Shader.cpp プロジェクト: collects/angle
void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const
{
    std::string debugInfo(mShader->getDebugInfo());
    getSourceImpl(debugInfo, bufSize, length, buffer);
}
コード例 #30
-1
ファイル: server.cpp プロジェクト: eiger824/TCP_Messenger
  void Server::acceptUser() {
    //to be called every time a new connection is received
    QTcpSocket *socket = m_tcp_server->nextPendingConnection();
    debugInfo("New incoming connection, from IP " +
	      socket->peerAddress().toString() +
	      " and port: " + QString::number(socket->peerPort()));
    //check if ip is registered
    if (!isThisIpRegistered(socket->peerAddress().toString())) {
      //then parse user
      UE new_ue;
      new_ue.name = "";
      new_ue.ip = socket->peerAddress().toString();
      //will change when ue_name() is sent
      new_ue.rx_port = 0;
      m_online_users.append(new_ue);
      debugInfo("New empty UE registered!");
    } else {
      debugInfo("user is transmitting either its name or data");
      socket->waitForReadyRead(1000);
      //parse data
      QDataStream in(socket);
      in.setVersion(QDataStream::Qt_4_0);
      debugInfo("m_block_size: " + QString::number(m_block_size));
      if (m_block_size == 0) {
	if (socket->bytesAvailable() < (int)sizeof(quint16))
	  return;
      
	in >> m_block_size;
      }
      debugInfo("bytes available in socket: " + QString::number(socket->bytesAvailable()));
    
      if (socket->bytesAvailable() < m_block_size)
	return;
    
      QString message;
      in >> message;
    
      debugInfo(">Message: [" + message + "]");

      ProtocolStreamType_UE type;
      QStringList params = m_protocol->parseStream_UE(type, message);

      switch (type) {
      case UE_REGISTER:
	{
	  QString temp_name = params.at(0);
	  quint16 temp_port = (quint16) params.at(1).toInt();
	  DLOG (INFO) << "Parsed port: " << temp_port;
	  if (temp_name.isEmpty()) {
	    m_block_size=0;
	    return;
	  }
	  UE temp;
	  int index;
	  if (!isThisNameRegistered(temp_name)) {
	    //case for same ip, different name
	    debugInfo("New user " + temp_name + " connected from same IP. Registering user.");
	    temp.name = temp_name;
	    temp.ip = socket->peerAddress().toString();
	    //parse ue_rx_port
	    temp.rx_port = temp_port;
	    index = getIndexOfUEIp(socket->peerAddress().toString());
	    if (m_online_users.at(index).name.isEmpty()) {
	      //first time, when username is still empty
	      if (index != -1) {
		temp = m_online_users.at(index);
		temp.name = temp_name;
		temp.rx_port = temp_port;
		m_online_users.replace(index,temp);
	      }
	    } else {
	      //same ip but different username, then append new UE
	      m_online_users.append(temp);
	    }
	  } else {
	    LOG (ERROR) << "User already exists on server. Notifying user...";
	    //inform user of currently online users
	    QByteArray block;
	    QDataStream out(&block, QIODevice::WriteOnly);
	    out.setVersion(QDataStream::Qt_4_0);
	    out << (quint16)0;
	    out << QString("ue_error(Existing user on server. Choose other username);");
	    out.device()->seek(0);
	    out << (quint16)(block.size() - sizeof(quint16));
	    DLOG (INFO) <<"Sending error message to UE ...\n";
	    m_log_label->setText(m_log_label->toPlainText()
			      + "\nError: attempted connection with same "
			      "username from same IP. Sending error to client...");
	    socket->write(block);
	    //reset m_block_size
	    m_block_size = 0;
	    return;
	  }
	  DLOG (INFO) << "New user is online: " << temp;
	  debugInfo("Nr. online users: " + QString::number(m_online_users.size()));
	  if (m_log_label->toPlainText() != "") {
	    m_log_label->setText(m_log_label->toPlainText() + "\n[" + temp.name + "]@" +
			      temp.ip + ":" +
			      QString::number(temp.rx_port) + " is now online.");
	  } else {
	    m_log_label->setText(m_log_label->toPlainText() + "[" + temp.name + "]@" +
			      temp.ip + ":" +
			      QString::number(temp.rx_port) + " is now online.");
	  }
	  //parse online users
	  QString users;
	  for (auto user: m_online_users) {
	    users += user.name + "\n";
	  }
	  users.chop(1);
	  m_online_users_label->setText(users);
	  qobject_cast<QLabel*>(m_main_layout->itemAt(2)->widget())->setText("Currently online users("
									  + QString::number(m_online_users.size()) + "):");
	  //inform user of currently online users
	  QByteArray block;
	  QDataStream out(&block, QIODevice::WriteOnly);
	  out.setVersion(QDataStream::Qt_4_0);
	  out << (quint16)0;
	  QStringList params;
	  for (auto user: m_online_users) {
	    params << user.name;
	  }
	  out << m_protocol->constructStream_Server(params,
						    ProtocolStreamType_Server::SERVER_ALL);
	  out.device()->seek(0);
	  out << (quint16)(block.size() - sizeof(quint16));
	  DLOG (INFO) <<"Sending information about currently online users...\n";
	  /*At this point, this block will be sent to all current users, not only to the
	    user that is currently connected*/
	  for (auto connection: m_online_users) {
	    QTcpSocket *temp_socket = new QTcpSocket(this);
	    temp_socket->connectToHost(QHostAddress(connection.ip), connection.rx_port);
	    if (!temp_socket->waitForConnected(3000)) {
	      LOG (ERROR) << "ERROR: Connection attempt @"
			  << connection.ip.toStdString() << ":"
			  << connection.rx_port << " timed out. Omitting current...";
	    } else {
	      debugInfo("Connection to client @" + connection.ip + ":"
			+ QString::number(connection.rx_port) + " was established. Now sending...");
	      temp_socket->write(block);
	      if (!temp_socket->waitForBytesWritten()) {
		LOG (ERROR) << "ERROR: Connection attempt @"
			    << connection.ip.toStdString() << ":"
			    << connection.rx_port << " timed out. Omitting current...";
	      } else {
		debugInfo("Transmission to client @" + connection.ip + ":"
			  + QString::number(connection.rx_port) + " was successful!");
	      }
	    }
	    temp_socket->disconnectFromHost();
	    if (temp_socket->state() == QAbstractSocket::UnconnectedState ||
		temp_socket->waitForDisconnected(1000)) {
	      debugInfo("Socket disconnected.");
	    }
	  }

	  break;

	  
	}
      case UE_ACK:
	{
	  m_log_label->setText(m_log_label->toPlainText() + "\n" + message);
	  debugInfo("Going to forward user ack to destination");
	  QByteArray block;
	  QDataStream out(&block, QIODevice::WriteOnly);
	  out.setVersion(QDataStream::Qt_4_0);
	  out << (quint16)0;
	  out << m_protocol->constructStream_Server(QStringList(message),
						    ProtocolStreamType_Server::SERVER_FWD_TO_SENDER);
	  out.device()->seek(0);
	  out << (quint16)(block.size() - sizeof(quint16));

	  //and lookup destination details for given user
	  QString dest = params.at(0);
	  QString from = params.at(1);
	  unsigned int message_id = (unsigned int) params.at(2).toInt();

	  //Create temporary socket
	  QTcpSocket* dest_socket = new QTcpSocket(this);
	  QString dest_ip;
	  quint16 dest_port;
	  int index = getIndexOfUEName(dest);
	  if (index != -1) {
	    dest_ip = m_online_users.at(index).ip;
	    dest_port = m_online_users.at(index).rx_port;
	    debugInfo("Going to forward ack to " + dest_ip + ":" + QString::number(dest_port));
	  } else {
	    LOG (ERROR) << "ERROR: name was not found on server. Returning...";
	    m_block_size=0;
	    return;
	  }
	  dest_socket->connectToHost(QHostAddress(dest_ip), dest_port);

	  if (!dest_socket->waitForConnected(2000)) {
	    debugInfo("ERROR: request timed out");
	  } else {
	    debugInfo("Established connection with client. Forwarding user ack...");
	    dest_socket->write(block);
	    if (!dest_socket->waitForBytesWritten(5000)) {
	      debugInfo("ERROR: transmission timed out");
	    } else {
	      debugInfo("Success! ACK was forwarded to destination");
	    }
	    dest_socket->disconnectFromHost();
	  }
	  break;
	}
      case UE_ERROR:
	{
	  debugInfo("Some error encountered by user. Returning ...");
	  m_block_size=0;
	  return;
	}
      case UE_MESSAGE:
	{
	  m_log_label->setText(m_log_label->toPlainText() + "\n" + message);
	  //and send it back to the user
	  debugInfo("Going to resend message to dest client: [" + message + "]");
	  
	  QString content = params.at(0);
	  QString dest = params.at(1);
	  QString from = params.at(2);
	  unsigned int message_id = (unsigned int) params.at(3).toInt();
	  
	  DLOG (INFO) << "Message: " << content.toStdString() << ", from " << from.toStdString()
		      << " and to " << dest.toStdString()
		      << ", with message ID: " << message_id;
	  QByteArray block;
	  QDataStream out(&block, QIODevice::WriteOnly);
	  out.setVersion(QDataStream::Qt_4_0);
	  out << (quint16)0;
	  out << m_protocol->constructStream_Server(QStringList(message),
						    ProtocolStreamType_Server::SERVER_FWD_TO_SENDER);
	  out.device()->seek(0);
	  out << (quint16)(block.size() - sizeof(quint16));
	  if (dest == from) {
	    debugInfo("WARNING: Message intended for self UE. Sending back to user...");
	    socket->write(block);
	    if (!socket->waitForBytesWritten(2000)) {
	      LOG (ERROR) << "ERROR: transmission timeout";
	    } else {
	      debugInfo("Success!");
	    }
	  } else {
	    QTcpSocket *dest_socket = new QTcpSocket(this);
	    QString dest_ip;
	    quint16 dest_port;
	    int index = getIndexOfUEName(dest);
	    if (index != -1) {
	      dest_ip = m_online_users.at(index).ip;
	      dest_port = m_online_users.at(index).rx_port;
	      debugInfo("Going to forward message to " + dest_ip + ":" + QString::number(dest_port));
	    } else {
	      LOG (ERROR) << "ERROR: name was not found on server. Returning...";
	      m_block_size=0;
	      return;
	    }
	    dest_socket->connectToHost(QHostAddress(dest_ip), dest_port);
	    if (!dest_socket->waitForConnected(2000)) {
	      debugInfo("ERROR: request timed out");
	    } else {
	      debugInfo("Established connection with client. Sending...");
	      dest_socket->write(block);
	      if (!dest_socket->waitForBytesWritten(5000)) {
		debugInfo("ERROR: transmission timed out");
	      } else {
		debugInfo("Success! Message was forwarded to destination");
	      }
	      dest_socket->disconnectFromHost();
	      //and send an ack to the user to inform that message was received
	      QByteArray ack_data;
	      QDataStream ack(&ack_data, QIODevice::WriteOnly);
	      ack.setVersion(QDataStream::Qt_4_0);
	      ack << (quint16)0;
	      QStringList params;
	      params << from << QString::number(message_id);
	      ack << m_protocol->constructStream_Server(params,
							ProtocolStreamType_Server::SERVER_ACK);
	      ack.device()->seek(0);
	      debugInfo("Sending ack to user: "******"ERROR: transmission timeout!";
	      } else {
		debugInfo("Success!");
	      }
	    }
	  }
	  break;
	}
      case UE_UNREGISTER:
	{
	  unregisterUser();
	  break;
	}
      case UE_TYPING:
	{
	  debugInfo("User is typing...");
	  m_log_label->setText(m_log_label->toPlainText() + "\n" + message);
	  //no need to parse parameters, going to forward to user
	  
	  QString dest = params.at(0);
	  QString from = params.at(1);

	  debugInfo(dest + "," + from);
	  
	  QByteArray typing_data;
	  QDataStream typing_stream(&typing_data, QIODevice::WriteOnly);
	  typing_stream.setVersion(QDataStream::Qt_4_0);
	  typing_stream << (quint16)0;
	  QStringList typing_params;
	  typing_params << params.at(0) << params.at(1) << params.at(2);
	  typing_stream << m_protocol->constructStream_Server(typing_params,
							      ProtocolStreamType_Server::SERVER_FWD_TYPING);
	  typing_stream.device()->seek(0);

	  DLOG (INFO) << "Sending: " << m_protocol->constructStream_Server(typing_params,
							    ProtocolStreamType_Server::SERVER_FWD_TYPING).toStdString();
	  
	  QTcpSocket *dest_socket = new QTcpSocket(this);
	  QString dest_ip;
	  quint16 dest_port;
	  int index = getIndexOfUEName(dest);
	  if (index != -1) {
	    dest_ip = m_online_users.at(index).ip;
	    dest_port = m_online_users.at(index).rx_port;
	    debugInfo("Going to forward typing info to " +
		      dest_ip + ":" + QString::number(dest_port));
	  } else {
	    LOG (ERROR) << "ERROR: name was not found on server. Returning...";
	    m_block_size=0;
	    return;
	  }
	  dest_socket->connectToHost(QHostAddress(dest_ip), dest_port);
	  if (!dest_socket->waitForConnected(2000)) {
	    debugInfo("ERROR: request timed out");
	  } else {
	    debugInfo("Established connection with client. Sending...");
	    dest_socket->write(typing_data);
	    if (!dest_socket->waitForBytesWritten(5000)) {
	      debugInfo("ERROR: transmission timed out");
	    } else {
	      debugInfo("Success! Typing information was forwarded to destination");
	    }
	    dest_socket->disconnectFromHost();
	  }

	  break;
	}
      default:
	LOG (WARNING) << "Unrecognized stream type";
	break;
      }
    
    }
    //reset m_block_size
    m_block_size=0;
  }