Changeset 2952

Show
Ignore:
Timestamp:
04/27/06 13:21:37 (3 years ago)
Author:
madcat
Message:

More fixes for shared dirs removal/addition issues. Working correctly now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hncgcomm/cgcomm.cpp

    r2942 r2952  
    664664                        onRemoved(i->second); 
    665665                        m_list.erase(i); 
     666                } 
     667                return; 
     668        } else if (oc == OC_CHANGEID) { 
     669                uint32_t oldId = Utils::getVal<uint32_t>(packet); 
     670                uint32_t newId = Utils::getVal<uint32_t>(packet); 
     671                Iter i = m_list.find(oldId); 
     672                if (i != m_list.end()) { 
     673                        SharedFilePtr obj = i->second; 
     674                        m_list.erase(i); 
     675                        obj->m_id = newId; 
     676                        m_list[newId] = obj; 
    666677                } 
    667678                return; 
  • hydranode/hncore/cgcomm/opcodes.h

    r2942 r2952  
    6767        OC_CADDED   = 0x1d,  //!< Child was added to an object 
    6868        OC_CREMOVED = 0x1e,  //!< Child was removed from an object 
    69         OC_DESTROY  = 0x1f   //!< Object was destroyed 
    70  
     69        OC_DESTROY  = 0x1f,  //!< Object was destroyed 
     70        OC_CHANGEID = 0x20   //!< Object ID was changed 
    7171}; 
    7272 
  • hydranode/hncore/cgcomm/sub_shared.cpp

    r2938 r2952  
    222222                (*it)->setZombie(); 
    223223        } else if (it != m_cache.get<2>().end()) { 
     224                if (event == SF_METADATA_ADDED) { 
     225                        changeId(it); 
     226                        it = m_cache.get<2>().find(file); 
     227                        CHECK_THROW(it != m_cache.get<2>().end()); 
     228                } 
    224229                (*it)->update(file); 
    225230        } 
     
    230235        ); 
    231236} MSVC_ONLY(;) 
     237 
     238void Shared::changeId(FIter c) { 
     239        if ((*c)->getId() == getFId((*c)->m_file)) { 
     240                return; 
     241        } 
     242        uint32_t oldId = (*c)->getId(); 
     243        uint32_t newId = getFId((*c)->m_file); 
     244        CacheEntry *cc = *c; 
     245 
     246        // preconditions 
     247        CHECK_THROW(m_cache.get<1>().find(newId) == m_cache.get<1>().end()); 
     248 
     249        m_cache.get<2>().modify( 
     250                c, boost::lambda::bind(&CacheEntry::m_id, __1) = newId 
     251        ); 
     252 
     253        // postconditions 
     254        CHECK_THROW(cc->getId() == newId); 
     255        CHECK_THROW(m_cache.get<1>().find(newId) != m_cache.get<1>().end()); 
     256 
     257        std::ostringstream tmp; 
     258        Utils::putVal<uint8_t>(tmp, OC_CHANGEID); 
     259        Utils::putVal<uint32_t>(tmp, oldId); 
     260        Utils::putVal<uint32_t>(tmp, newId); 
     261        sendPacket(tmp.str()); 
     262} 
    232263 
    233264void Shared::onMonitorTimer() try { 
  • hydranode/hncore/cgcomm/sub_shared.h

    r2938 r2952  
    6464        }; 
    6565private: 
    66         void monitor(std::istream &i); 
    67         void addShared(std::istream &i); 
    68         void remShared(std::istream &i); 
    69         void sendList(); 
    70         void rebuildCache(); 
    71         void onEvent(SharedFile *file, int event); 
    72         void onMonitorTimer(); 
    73  
    7466        typedef boost::multi_index_container< 
    7567                CacheEntry*, 
     
    9486        typedef Cache::nth_index<1>::type::iterator IDIter; 
    9587        typedef Cache::nth_index<2>::type::iterator FIter; 
     88 
     89        void monitor(std::istream &i); 
     90        void addShared(std::istream &i); 
     91        void remShared(std::istream &i); 
     92        void sendList(); 
     93        void rebuildCache(); 
     94        void onEvent(SharedFile *file, int event); 
     95        void onMonitorTimer(); 
     96        void changeId(FIter i); 
     97 
    9698        Cache m_cache; 
    97  
    9899        uint32_t m_updateTimer; 
    99100};