Example #1
0
/*
* Reposition the window so as to center on the dot.
*/
bool
reposition ()
{
    long l_val;

    l_val = DOT_POS (curwp) - (curwp->w_ntrows * R_BYTES (curwp) / 2L);
    move_ptr (curwp, l_val, FALSE, TRUE, FALSE);
    curwp->w_flag |= WFHARD;
    return (TRUE);
}
Example #2
0
void MasterSession::on_connect( )
{
    uptr<MessageRegister> msg = make_uptr( MessageRegister );
    msg->set_id( MRT::UUID::create( ) );
    msg->set_block_num( BlockTable::instance( )->block_num( ) );
    msg->set_data_addr ( "" );
    msg->set_data_port ( 0 );
    msg->set_disk_space( 1000 );
    this->send_message( move_ptr( msg ) );
}
Example #3
0
bool BlockDistributer::put_file( size_t file_size ,
                                 sptr<ClientSession> client ,
                                 uptr<MessageRequestPut> msg )
{
    LOG_DEBUG( "file size num %lld " , file_size );

    auto size_left = file_size;

    size_t block_num        = ( size_t ) ceil( ( double ) file_size / ( double ) ( BLOCK_SIZE ) );
    size_t max_block_num    = 0;
    size_t offset           = 0;

    NodeManager::instance( )->sort( [ ] ( sptr<NodeSession> n1 , sptr<NodeSession> n2 )
    {
        return n1->block_num( ) > n2->block_num( );
    } );

    if ( NodeManager::instance( )->count( ) == 0 )
    {
        LOG_DEBUG( "node count is 0 exit" , block_num );
        client->close( );
        return false;
    }

    for ( size_t i = 0; i < block_num; i++ )
    {
        if ( size_left == 0 ) break;

        auto c_size = size_left > BLOCK_SIZE ? BLOCK_SIZE : size_left;

        auto n = NodeManager::instance( )->get_node( i % NodeManager::instance( )->count( ) );

        if ( n == nullptr )
        {
            LOG_DEBUG( "No node found exit..." , n->id( ) );
            return false;
        }


        uptr<MessageRequestPutToken> req = make_uptr( MessageRequestPutToken );
        req->set_request_id( msg->request_id( ) );
        req->set_block_id( i );
        req->set_size( c_size );
        req->set_client_id( client->id( ) );
        req->set_file_name( msg->path( ) );
        req->set_offset( offset );
        n->send_message( move_ptr( req ) );

        size_left -= c_size;
        offset += c_size;
    }

    client->token_num( block_num );
    return true;
}
bool DirectorMeta::AddFile( sptr<FileMeta> file )
{
    auto dir = this->FindDirector( file->FilePath() );
 
    if ( dir == nullptr )
    {
        dir = this->MakeDirector( file->FilePath() );
    }

    dir->file_list_.push_back( move_ptr( file ) );
    return true;
}
void DuplicateConnector::OnSessionClose( Session * session )
{
    auto s = DuplicateSessionPool::Instance()->Pop( scast<DuplicateSession*>( session ) );

    if ( session->LastError().Code() != 0 &&
         session->LastError().Code() != -4095 )
    {
        Logger::Error( "duplicate error <%>%" , session->LastError().Code() ,
                       session->LastError().Message() );
    }

    if ( session->LastError().Code() == -4078 )
    {
        Logger::Log( "retring duplicate % from %" ,
                     this->message_->path() ,
                     this->message_->address() );
        auto connector = make_uptr( DuplicateConnector , move_ptr( this->message_ ) );
        MRT::Maraton::Instance()->Regist( move_ptr( connector ) );
    }
     
    SAFE_DELETE( session );
}
Example #6
0
void MasterSession::alive( )
{
    worker_ = MRT::SyncWorker::create( 1000 , [this] ( MRT::SyncWorker* worker )
    {
        uptr<MessageAlive> alive = make_uptr( MessageAlive );
        alive->set_block_num( BlockTable::instance( )->block_num( ) );
        alive->set_disk_space( 0 );
        alive->set_session_id( this->session_id( ) );
        alive->set_token_num( TokenPool::instance( )->token_num( ) );
        alive->set_local_time( Timer::tick( ) );
        this->send_message( move_ptr( alive ) );
        return false;
    } , nullptr , nullptr );
}
Example #7
0
bool FileMeta::AddBlock( sptr<BlockMeta> block )
{
    for ( auto & b : this->block_list_ )
    {
        if ( b->PartId() == block->PartId() )
        {
            return false;
        }
    }

    this->size_ += block->BlockSize();
    this->block_list_.push_back( move_ptr( block ) );

    return true;
}
Example #8
0
sptr<DirectoryMeta> DirectoryMeta::get_dir( std::string name )
{
    size_t hash = hash_code( name );

    if ( this->name_hash_ == hash &&
         this->name_ == name )
    {
        return shared_from_this();
    }
    
    for ( auto d : this->children_ )
    {
        if ( d->name_hash_ == hash &&
             d->name_ == name )
        {
            return move_ptr( sptr<DirectoryMeta>( d ) );
        }
    }

    return nullptr;
}
Example #9
0
void MasterSession::sync_all_block( )
{ 
    auto block_num = BlockTable::instance( )->block_num( );

    for ( size_t i = 0; i < block_num; i++ )
    {
        auto block = BlockTable::instance( )->find_block( i );

        if ( false == block->is_used ) continue;

        uptr<MessageSyncBlock> msg = make_uptr( MessageSyncBlock );

        msg->set_id( block->block_id );
        msg->set_index( block->index );
        msg->set_path( block->path );
        msg->set_size( block->size );
        msg->set_status( 0 );

        this->send_message( move_ptr( msg ) );
    }

    LOG_DEBUG( "Sync % files in total" , block_num );

}
Example #10
0
Battle::Battle(Petinfo &petInfo, PE_TEAM_SELECTION &teamA, PE_TEAM_SELECTION &teamB, int verbosity) {
   PE_ERROR error;
   PE_MOVE moveA, moveB;
   PE_DURATION cooldownA, cooldownB;
   PE_AN expectedNumAVA, expectedNumAVB;
   vector<PE_AV> abilityValuesA, abilityValuesB;
   int abilityA, abilityB;
   PE_FAMILY abilityFamilyA, abilityFamilyB;
   State state(PE_SIDES, PE_TEAM_SIZE);

   m_verbosity = verbosity;
   m_move[PE_SIDEA].resize(PE_TEAM_SIZE);
   m_move[PE_SIDEB].resize(PE_TEAM_SIZE);
#if PE_VERBOSE > PE_VERBOSE_OFF
   m_petName.resize(PE_SIDES);
   m_abilityName.resize(PE_SIDES);
   m_petName[PE_SIDEA].resize(PE_TEAM_SIZE);
   m_petName[PE_SIDEB].resize(PE_TEAM_SIZE);
   m_abilityName[PE_SIDEA].resize(PE_TEAM_SIZE);
   m_abilityName[PE_SIDEB].resize(PE_TEAM_SIZE);
#endif
   for (int pet = PE_PET1; pet < PE_TEAM_SIZE; pet++) {
      state.setFamily(petInfo.getFamily(teamA.pet[pet].petNumber), PE_SIDEA, (PE_PET_NUMBER)pet);
      state.setFamily(petInfo.getFamily(teamB.pet[pet].petNumber), PE_SIDEB, (PE_PET_NUMBER)pet);
      state.setGenus(petInfo.getGenus(teamA.pet[pet].petNumber), PE_SIDEA, (PE_PET_NUMBER)pet);
      state.setGenus(petInfo.getGenus(teamB.pet[pet].petNumber), PE_SIDEB, (PE_PET_NUMBER)pet);
      state.setStats(petInfo.getStats(teamA.pet[pet].petNumber, teamA.pet[pet].breedNumber), PE_SIDEA, (PE_PET_NUMBER)pet);
      state.setStats(petInfo.getStats(teamB.pet[pet].petNumber, teamB.pet[pet].breedNumber), PE_SIDEB, (PE_PET_NUMBER)pet);
#if PE_VERBOSE > PE_VERBOSE_OFF
   m_petName[PE_SIDEA][pet] = petInfo.getPetName(teamA.pet[pet].petNumber);
   m_petName[PE_SIDEB][pet] = petInfo.getPetName(teamB.pet[pet].petNumber);
   m_abilityName[PE_SIDEA][pet].resize(PE_ABILITIES);
   m_abilityName[PE_SIDEB][pet].resize(PE_ABILITIES);
#endif
      for (int move = PE_SLOT1; move < PE_ABILITIES; move++) {
         abilityA = move*PE_SELECTIONS + teamA.pet[pet].abilitySelection[move];
         petInfo.getAbilityValues(teamA.pet[pet].petNumber, teamA.pet[pet].breedNumber, (PE_ABILITY)abilityA, abilityValuesA);
         string abilityStringA(petInfo.getAbilityName(teamA.pet[pet].petNumber, (PE_ABILITY)abilityA, abilityFamilyA));
#if PE_VERBOSE > PE_VERBOSE_REQ
		 printf("%d %d %d %s\n", pet, move, abilityFamilyA, abilityStringA.c_str());
#endif
		 error = petInfo.getMove(abilityStringA, state.allPower(PE_SIDEA, pet), abilityFamilyA, moveA, expectedNumAVA, cooldownA);
		 if (error == PE_NEED_INFO) {
			 abilityValuesA.push_back(expectedNumAVA);
			 expectedNumAVA = 1;
			 error = PE_OK;
		 }
         if (error != PE_OK) {
#if PE_VERBOSE > PE_VERBOSE_OFF
			 printf("Unknown ability %s for pet %s\n", abilityStringA.c_str(), m_petName[PE_SIDEA][pet].c_str());
#endif
            exit(9);
         }
         else if (expectedNumAVA != abilityValuesA.size()) {
#if PE_VERBOSE > PE_VERBOSE_OFF
            printf("Wrong number of abilitiy numbers on ability %s for pet %s\n", abilityStringA, m_petName[PE_SIDEA][pet].c_str());
#endif
            exit(9);
         }
         else {
            m_move[PE_SIDEA][pet].push_back(move_ptr(new Move(PE_SIDEA, abilityFamilyA, moveA, abilityValuesA, cooldownA, pet)));
#if PE_VERBOSE > PE_VERBOSE_REQ
            printf("  %d -- ", moveA);
            for (uint32_t avn = 0; avn < abilityValuesA.size(); avn++) {
               printf("%d ", abilityValuesA[avn]);
            }
            printf("\n");
#endif
         }
         abilityB = move*PE_SELECTIONS + teamB.pet[pet].abilitySelection[move];
         petInfo.getAbilityValues(teamB.pet[pet].petNumber, teamB.pet[pet].breedNumber, (PE_ABILITY)abilityB, abilityValuesB);
         string abilityStringB(petInfo.getAbilityName(teamB.pet[pet].petNumber, (PE_ABILITY)abilityB, abilityFamilyB));
#if PE_VERBOSE > PE_VERBOSE_REQ
		 printf("%d %d %d %s\n", pet, move, abilityFamilyB, abilityStringB.c_str());
#endif
		 error = petInfo.getMove(abilityStringB, state.allPower(PE_SIDEB, pet), abilityFamilyB, moveB, expectedNumAVB, cooldownB);
		 if (error == PE_NEED_INFO) {
			 abilityValuesB.push_back(expectedNumAVB);
			 expectedNumAVB = 1;
			 error = PE_OK;
		 }
		 if (error != PE_OK) {
#if PE_VERBOSE > PE_VERBOSE_OFF
            printf("Unknown ability %s for pet %s\n", abilityStringB, m_petName[PE_SIDEB][pet].c_str());
#endif
            exit(9);
         }
         else if (expectedNumAVB != abilityValuesB.size()) {
#if PE_VERBOSE > PE_VERBOSE_OFF
            printf("Wrong number of abilitiy numbers on ability %s for pet %s\n", abilityStringB, m_petName[PE_SIDEB][pet].c_str());
#endif
            exit(9);
         }
         else {
            m_move[PE_SIDEB][pet].push_back(move_ptr(new Move(PE_SIDEB, abilityFamilyB, moveB, abilityValuesB, cooldownB, pet)));
#if PE_VERBOSE > PE_VERBOSE_REQ
            printf("  %d -- ", moveB);
			for (uint32_t avn = 0; avn < abilityValuesB.size(); avn++) {
               printf("%d ", abilityValuesB[avn]);
            }
            printf("\n");
#endif
         }
#if PE_VERBOSE > PE_VERBOSE_OFF
   m_abilityName[PE_SIDEA][pet][move] = abilityStringA;
   m_abilityName[PE_SIDEB][pet][move] = abilityStringB;
#endif
      }
   }
   m_game = game_ptr(new Game());
   m_state = state;
#if PE_VERBOSE > PE_VERBOSE_OFF
   state.setVerbosity(m_verbosity);
#endif

   m_status = PE_OK;
}
void ClusterSession::try_pop_message( )
{
    while ( true )
    {
        switch ( this->state_ )
        {
            case MessageParseState::Header:
                {
                    auto tmp = this->buffer_.pop( 2 );
                    if ( tmp == nullptr ) return;


                    auto kf = ( *tmp )[0];
                    auto ks = ( *tmp )[1];

                    if ( kf == 'Y' && ks == 'H' )
                    {
                        this->state_ = MessageParseState::Length;
                    }
                    else
                    {
                        this->close( );
                        return;
                    }
                }
                break;
            case MessageParseState::Length:
                {
                    auto tmp = this->buffer_.pop( 4 );

                    if ( tmp == nullptr ) return;

                    short* pshort           = ( short* ) ( tmp->data( ) );
                    this->oringal_size_     = *pshort;
                    ++pshort;
                    this->compressed_size_  = *pshort;

                    if ( this->compressed_size_ < MAX_CIRCLE_BUFFER_SIZE &&
                         this->oringal_size_ < MAX_CIRCLE_BUFFER_SIZE )
                    {
                        this->state_ = MessageParseState::Body;
                    }
                    else
                    {
                        this->state_ = MessageParseState::Header;
                        this->close( );
                        return;
                    }
                }
                break;
            case MessageParseState::Body:
                {
                    auto tmp = this->buffer_.pop( this->compressed_size_ );

                    if ( tmp == nullptr ) return;

                    try
                    {
                        auto msg = make_uptr( Message , std::string( tmp->data( ) , tmp->size( ) ) );
                        msg->owner( this );
                        this->on_message( move_ptr( msg ) );
                    }
                    catch ( ... )
                    {

                    }

                    this->state_ = MessageParseState::Header;
                }
                break;
            default:
                break;
        }
    }
}
DuplicateConnector::DuplicateConnector( uptr<MessageDuplicateBlock> msg )
    : Connector( msg->address() , msg->port() )
{
    this->message_ = move_ptr( msg );
}
Session * DuplicateConnector::CreateSession()
{
    return new DuplicateSession( move_ptr( this->message_ ) );
}
Example #14
0
 TInterface* release () throw ()
 {
     auto ptr = move_ptr (m__ptr);
 }
Example #15
0
 cptr (cptr && ptr) throw ()
     :   m__ptr (move_ptr (ptr.m__ptr))
 {
 }
Example #16
0
 coutptr (coutptr && outptr) throw ()
 {
     m__cptr = move_ptr (outptr.m__cptr);
     m__ptr = move_ptr (outptr.m__ptr);
 }