void KernelHandle::printNeighbor()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
     
     std::pair<shm_neighbors_type*, std::size_t> neighbors = segment.find<shm_neighbors_type>("shm_neighbors_"); 
     if(neighbors.first==0)
     {
         return;
     }
     
     shm_neighbors_type *n_pointer=neighbors.first;
     shm_neighbors_type::iterator n_it;
     
     for (n_it=n_pointer->begin(); n_it!=n_pointer->end(); n_it++)
     {
         std::cout<<n_it->first<<": ";
         
         std::cout<<n_it->second.getDistance()<<","<<n_it->second.getAzimuth()<<","<<n_it->second.getElevation()<<","<<\
             n_it->second.getX()<<","<<n_it->second.getY()<<","<<n_it->second.getZ();
         std::cout<<std::endl;
     }
 }
Esempio n. 2
0
    void on_init()
    {
        // Shared memory front-end that is able to construct objects
        // associated with a c-string. Erase previous shared memory with the name
        // to be used and create the memory segment at the specified address and initialize resources
        shared_memory_object::remove(FOO_SBS_SHM_SEGMENT);
        managed_shared_memory segment(
            create_only, 
            FOO_SBS_SHM_SEGMENT,  // segment name
            65536);               // segment size in bytes

        // Initialize the shared memory STL-compatible allocator
        ShMemAllocator alloc_inst (segment.get_segment_manager());

        // Construct a shared memory map.
        // Note that the first parameter is the comparison function,
        // and the second one the allocator.
        // This the same signature as std::map's constructor taking an allocator
        ShMemMap *shm_map = 
            segment.construct<ShMemMap>(FOO_SBS_SHM_MAP)           // object name
                                       (std::less<std::string>(),  // first ctor parameter
                                        alloc_inst);               // second ctor parameter

        if (cfg_enable.get_value() != 0)
        {
            g_start_server();
            g_register_callback_sbs();
        }
    }
   std::set<unsigned int> KernelHandle::getSwarmMembers(unsigned int swarm_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       //std::string mutex_name="named_kernel_mtx"+robot_id_string;
       //boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::set<unsigned int> result;
       result.clear();
   
       std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
       if(neighbor_swarm.first==0)
       {
           return result;
       }
 
       shm_neighbor_swarm_type *ns_pointer=neighbor_swarm.first;
       shm_neighbor_swarm_type::iterator ns_it;
       
       for(ns_it=ns_pointer->begin(); ns_it!=ns_pointer->end(); ns_it++)
       {
           shm_int_vector tmp=ns_it->second.getSwarmIDVector();
           
           if (std::find(tmp.begin(), tmp.end(), swarm_id) != tmp.end())
               result.insert(ns_it->first);
       }
       
       return result;
   }
   std::vector<unsigned int> KernelHandle::getSwarmList()
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       //std::string mutex_name="named_kernel_mtx"+robot_id_string;
       //boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::vector<unsigned int> result;
       result.clear();
       
       std::pair<shm_swarms_type*, std::size_t> swarms = segment.find<shm_swarms_type>("shm_swarms_"); 
       if(swarms.first==0)
       {
           return result;
       }
 
       shm_swarms_type *s_pointer=swarms.first;
       shm_swarms_type::iterator s_it;
       
       for(s_it=s_pointer->begin();s_it!=s_pointer->end();s_it++)
       {
           if(s_it->second)
               result.push_back(s_it->first);
       }
   
       return result;
   }
 void KernelHandle::printNeighborSwarm()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
     
     std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
     if(neighbor_swarm.first==0)
     {
         return;
     }
     
     shm_neighbor_swarm_type *nst_pointer=neighbor_swarm.first;
     shm_neighbor_swarm_type::iterator nst_it;
     
     for (nst_it=nst_pointer->begin(); nst_it!=nst_pointer->end(); nst_it++)
     {
         std::cout<<"neighbor swarm "<<nst_it->first<<": ";
         
         shm_int_vector temp=nst_it->second.getSwarmIDVector();
         for(int i=0;i<temp.size();i++)
         {
             std::cout<<temp[i]<<",";
         }
         std::cout<<"age: "<<nst_it->second.getAge();
         std::cout<<std::endl;
     }
 }
   std::map<unsigned int, NeighborLocation> KernelHandle::getNeighbors()
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       std::map<unsigned int, NeighborLocation> result;
   
       std::pair<shm_neighbors_type*, std::size_t> neighbors = segment.find<shm_neighbors_type>("shm_neighbors_"); 
       if(neighbors.first==0)
       {
           result.clear();
           return result;
       }
 
       shm_neighbors_type *n_pointer=neighbors.first;
       shm_neighbors_type::iterator n_it;
       
       for(n_it=n_pointer->begin(); n_it!=n_pointer->end(); n_it++)
       {
           NeighborLocation neighbor_location=n_it->second;
           result.insert(std::pair<unsigned int, NeighborLocation>(n_it->first,neighbor_location));
       }
   
       return result;
   }
   unsigned int KernelHandle::getVirtualStigmergySize(unsigned int id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       //std::string mutex_name="named_kernel_mtx"+robot_id_string;
       //boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           return 0;
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           unsigned int size=vst_it->second.size();
           return vst_it->second.size();
       }
       
       return 0;
   }
 void KernelHandle::printVirtualStigmergy()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
     
     std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
     if(virtual_stigmergy.first==0)
     {
         return;
     }
     
     shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
     shm_virtual_stigmergy_type::iterator vst_it;
     shm_virtual_stigmergy_tuple_type *svstt_pointer;
     shm_virtual_stigmergy_tuple_type::iterator svstt_it;
     
     for (vst_it=vst_pointer->begin(); vst_it!=vst_pointer->end(); vst_it++)
     {
         std::cout<<"["<<vst_it->first<<":"<<std::endl;
         svstt_pointer=&(vst_it->second);
         for (svstt_it=svstt_pointer->begin(); svstt_it!=svstt_pointer->end(); svstt_it++)
         {
             std::cout<<"("<<svstt_it->first<<","<< \
                 svstt_it->second.getVirtualStigmergyValue()<<","<<svstt_it->second.getVirtualStigmergyTimestamp()<<","<<\
                 svstt_it->second.getRobotID()<<")"<<std::endl;
         }
         std::cout<<"]"<<std::endl;
         std::cout<<std::endl;
     }
 }
   bool KernelHandle::getSwarm(unsigned int swarm_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       //std::string mutex_name="named_kernel_mtx"+robot_id_string;
       //boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_swarms_type*, std::size_t> swarms = segment.find<shm_swarms_type>("shm_swarms_"); 
       if(swarms.first==0)
       {
           return false;
       }
 
       shm_swarms_type *s_pointer=swarms.first;
       shm_swarms_type::iterator s_it;
       s_it=s_pointer->find(swarm_id);
   
       if(s_it!=s_pointer->end())
       {
           return s_it->second;
       }
       else
       {
           return false;
       }
   
       return false;
   }
   void KernelHandle::insertOrUpdateVirtualStigmergy(unsigned int id, std::string key_std, std::string value_std, time_t time_now, unsigned int robot_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       micros_swarm_framework::shm_string  key(key_std.data(), alloc_inst);
       micros_swarm_framework::shm_string  value(value_std.data(), alloc_inst);
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           return;
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key);
       
           if(svstt_it!=vst_it->second.end())
           {
               ShmVirtualStigmergyTuple new_tuple(value, time_now, robot_id, alloc_inst);
               
               named_kernel_mtx.lock();
               svstt_it->second = new_tuple;
               named_kernel_mtx.unlock();
           }
           else
           {
               ShmVirtualStigmergyTuple new_tuple(value, time_now, robot_id, alloc_inst);
               ShmVirtualStigmergyTupleType new_tuple_type(key,new_tuple);
               
               named_kernel_mtx.lock();
               vst_it->second.insert(new_tuple_type);
               named_kernel_mtx.unlock();
           }
       }
       else
       {       
           std::cout<<"ID "<<id<<" VirtualStigmergy is not exist."<<std::endl;
           return;
       }
   }
   void KernelHandle::insertOrRefreshNeighborSwarm(unsigned int robot_id, std::vector<unsigned int> swarm_list)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
       if(neighbor_swarm.first==0)
       {
           return;
       }
 
       shm_neighbor_swarm_type *ns_pointer=neighbor_swarm.first;
       shm_neighbor_swarm_type::iterator ns_it;
       ns_it=ns_pointer->find(robot_id);
   
       if(ns_it!=ns_pointer->end())
       {
           named_kernel_mtx.lock();
           ns_it->second.clearSwarmIDVector();
           
           for(int i=0;i<swarm_list.size();i++)
           {
               ns_it->second.addSwarmID(swarm_list[i]);
           }
           ns_it->second.setAge(0);  //age置为0
           
           named_kernel_mtx.unlock();
       }
       else
       {
           NeighborSwarm new_neighbor_swarm(alloc_inst, 0);
           
           for(int i=0;i<swarm_list.size();i++)
           {
               new_neighbor_swarm.addSwarmID(swarm_list[i]);
           }
           
           NeighborSwarmType new_type(robot_id, new_neighbor_swarm);
           
           named_kernel_mtx.lock();
           ns_pointer->insert(new_type);
           named_kernel_mtx.unlock();
           return;
       }
   }
Esempio n. 12
0
SharedMemory::SharedMemory(const std::string &suffix, bool server):
  server_(server),
  memory_name_(std::string(SHARED_MEMORY_BASE_NAME) + suffix)
{
  if (server_) {
    // remove the shared memory
    boost::interprocess::shared_memory_object::remove(memory_name_.c_str());
    mem_segment_ = new boost::interprocess::managed_shared_memory(boost::interprocess::create_only,memory_name_.c_str(),MEMORY_SIZE);
    VoidAllocator alloc_inst(mem_segment_->get_segment_manager());
    blocks_ = mem_segment_->construct<SharedMemMap>(MEM_MAP_NAME)(std::less<SharedString>(),alloc_inst);
  }
  else {
    mem_segment_ = new boost::interprocess::managed_shared_memory(boost::interprocess::open_only,memory_name_.c_str());
    blocks_ = mem_segment_->find<SharedMemMap>(MEM_MAP_NAME).first;
  }
}
 Location KernelHandle::getRobotLocation()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
 
     std::pair<Location*, std::size_t> kernel_robot_location = segment.find<Location>("shm_robot_location_"); 
     if(kernel_robot_location.first==0)
     {
         Location l(-1,-1,-1);
         return l;
     }
     
     return *(kernel_robot_location.first);
 }
 unsigned int KernelHandle::getRobotID()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
 
     std::pair<unsigned int*, std::size_t> kernel_robot_id = segment.find<unsigned int>("shm_robot_id_"); 
     if(kernel_robot_id.first==0)
     {
         //return 0;
         return INT_MAX;
     }
     
     return *(kernel_robot_id.first);
 }
 void KernelHandle::setRobotLocation(Location robot_location)
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     std::string mutex_name="named_kernel_mtx"+robot_id_string;
     boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
 
     std::pair<Location*, std::size_t> kernel_robot_location = segment.find<Location>("shm_robot_location_"); 
     if(kernel_robot_location.first==0)
     {
         return;
     }
     
     named_kernel_mtx.lock();
     *(kernel_robot_location.first)=robot_location;
     named_kernel_mtx.unlock();
 }
   void KernelHandle::deleteVirtualStigmergyValue(unsigned int id, std::string key_std)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       micros_swarm_framework::shm_string  key(key_std.data(), alloc_inst);
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           return;
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key);
       
           if(svstt_it!=vst_it->second.end())
           {
               named_kernel_mtx.lock();
               vst_it->second.erase(key);
               named_kernel_mtx.unlock();
           }
           else
           {
               return;
           }
       }
       else
       {
           return;
       }
   }
   VstigTuple KernelHandle::getVirtualStigmergyTuple(unsigned int id, std::string key_std)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
       
       micros_swarm_framework::shm_string  key(key_std.data(), alloc_inst);
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           shm_virtual_stigmergy_tuple_type::iterator svstt_it=vst_it->second.find(key);
       
           if(svstt_it!=vst_it->second.end())
           {
               shm_string value_shm=svstt_it->second.getVirtualStigmergyValue();
               std::string value(value_shm.data(), value_shm.size());
               time_t time_now=svstt_it->second.getVirtualStigmergyTimestamp();
               unsigned int robot_id=svstt_it->second.getRobotID();
               VstigTuple new_tuple(value, time_now, robot_id);
               
               return new_tuple;
           }
       }
       
       std::string value="";
       time_t time_now=0;
       unsigned int robot_id=0;
       VstigTuple tuple(value, time_now, robot_id);
           
       return tuple;
   }
   void KernelHandle::deleteNeighborSwarm(unsigned int robot_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());  
   
       std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
       if(neighbor_swarm.first==0)
       {
           return;
       }
 
       shm_neighbor_swarm_type *ns_pointer=neighbor_swarm.first;
   
       named_kernel_mtx.lock();
       ns_pointer->erase(robot_id);
       named_kernel_mtx.unlock();
   }
Esempio n. 19
0
void fetch(void)
{
    md_inst_t inst;
    inst_t *pI = NULL;

    if( g_piperegister[IF_ID_REGISTER] != NULL )
        return; // pipeline is stalled

    // allocate an instruction record, fill in basic information
    pI            = alloc_inst();
    pI->taken     = 0;
    pI->stalled   = 0;
    pI->pc        = g_fetch_pc;
    pI->status    = ALLOCATED;
    pI->op        = 0;
    pI->donecycle = 0xFFFFFFFF; // i.e., largest unsigned integer
    pI->uid       = g_uid++;

    /* get the instruction bits from the instruction memory */
    MD_FETCH_INST(inst, mem, g_fetch_pc);
    pI->inst = inst;

    if( g_fetch_redirected ) {
       // set PC to target of branch/jump
       g_fetch_pc = g_target_pc;

       // Opps... it looks like we fetched the wrong instruction. So, turn it into a "bubble" by 
       // deleting the instruction and leaving the IF/ID register "empty".  Note that, in 
       // hardware we would mux a nop (all zeros) into the IF/ID instruction register field.
       free_inst(pI);
       g_fetch_redirected = 0;
    } else {
       // set PC to point to next sequential instruction
       g_fetch_pc += sizeof(md_inst_t);

       // place the instruction in the IF/ID register
       pI->status = FETCHED; 
       g_piperegister[IF_ID_REGISTER] = pI; 
    }
}
   void KernelHandle::leaveNeighborSwarm(unsigned int robot_id, unsigned int swarm_id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
       if(neighbor_swarm.first==0)
       {
           return;
       }
 
       shm_neighbor_swarm_type *ns_pointer=neighbor_swarm.first;
       shm_neighbor_swarm_type::iterator ns_it;
       ns_it=ns_pointer->find(robot_id);
   
       if(ns_it!=ns_pointer->end())
       {
           if(ns_it->second.swarmIDExist(swarm_id))
           {
               named_kernel_mtx.lock();
               ns_it->second.removeSwarmID(swarm_id);
               ns_it->second.setAge(0);
               named_kernel_mtx.unlock();
           }
           else
           {
               std::cout<<"robot"<<robot_id<<"is not in swarm"<<swarm_id<<"."<<std::endl;
           }
       }
       else  //不存在
       {
           std::cout<<"robot_id "<<robot_id<<" neighbor_swarm tuple is not exist."<<std::endl;
           return;
       }
   
   }
   void KernelHandle::insertOrUpdateNeighbor(unsigned int robot_id, float distance, float azimuth, float elevation, float x, float y, float z)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_neighbors_type*, std::size_t> neighbors = segment.find<shm_neighbors_type>("shm_neighbors_"); 
       if(neighbors.first==0)
       {
           return;
       }
 
       shm_neighbors_type *n_pointer=neighbors.first;
       shm_neighbors_type::iterator n_it;
       n_it=n_pointer->find(robot_id);
   
       if(n_it!=n_pointer->end())
       {
           NeighborLocation new_neighbor_location(distance, azimuth, elevation, x, y, z);
           
           named_kernel_mtx.lock();
           n_it->second = new_neighbor_location;
           named_kernel_mtx.unlock();   
       }
       else
       {
           NeighborLocation new_neighbor_location(distance, azimuth, elevation, x, y, z);
           NeighborLocationType new_type(robot_id, new_neighbor_location);    
           
           named_kernel_mtx.lock();
           n_pointer->insert(new_type);
           named_kernel_mtx.unlock();
       }
   }
   void KernelHandle::createVirtualStigmergy(unsigned int id)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       
       std::string id_string=boost::lexical_cast<std::string>(id);
       std::string virtual_stigmergy_name="shm_virtual_stigmergy_tuple_"+id_string;
       const char *p=virtual_stigmergy_name.data();
       
       VoidAllocator alloc_inst (segment.get_segment_manager());  
   
       std::pair<shm_virtual_stigmergy_type*, std::size_t> virtual_stigmergy = segment.find<shm_virtual_stigmergy_type>("shm_virtual_stigmergy_"); 
       if(virtual_stigmergy.first==0)
       {
           return;
       }
 
       shm_virtual_stigmergy_type *vst_pointer=virtual_stigmergy.first;
       shm_virtual_stigmergy_type::iterator vst_it;
       vst_it=vst_pointer->find(id);
   
       if(vst_it!=vst_pointer->end())
       {
           return;
       }
       else
       {
           shm_virtual_stigmergy_tuple_type *tmp=segment.construct<shm_virtual_stigmergy_tuple_type>(p)(std::less<shm_string>(), alloc_inst);
           VirtualStigmergyType vst(id, *tmp);
           
           named_kernel_mtx.lock();
           vst_pointer->insert(vst);
           named_kernel_mtx.unlock();
       }
   }
 void KernelHandle::printSwarm()
 {
     std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
     std::string shm_object_name="KernelData"+robot_id_string;
     boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
     VoidAllocator alloc_inst (segment.get_segment_manager());
     
     std::pair<shm_swarms_type*, std::size_t> swarms = segment.find<shm_swarms_type>("shm_swarms_"); 
     if(swarms.first==0)
     {
         return;
     }
     
     shm_swarms_type *s_pointer=swarms.first;
     shm_swarms_type::iterator s_it;
     
     for (s_it=s_pointer->begin(); s_it!=s_pointer->end(); s_it++)
     {
         std::cout<<s_it->first<<": ";
         
         std::cout<<s_it->second;
         std::cout<<std::endl;
     }
 }