Example #1
0
int axio_show_mim_summary(FILE * fp, char * mesg, afni_xml_t * ax, int verb)
{
   afni_xml_t * xm, * xt;
   FILE       * ofp = fp ? fp : stderr;
   int          kid, matkid, mind;

   if( ! ax ) {
      fprintf(stderr,"** AX_SMS: missing struct pointer\n");
      return 1;
   }
   if( mesg ) fputs(mesg, ofp);

   xm = axio_find_map_name(ax, "Matrix", 2);

   if( !xm || strcmp(xm->name, "Matrix") ) {
      fprintf(ofp, "** missing Matrix element under %s\n", ax->name);
      return 1;
   }

   if( verb > 1 ) fprintf(ofp, "-- have %d Matrix children\n", xm->nchild);

   for( matkid = 0; matkid < xm->nchild; matkid++ ) {
      xt = xm->xchild[matkid];
      if( strcmp(xt->name, "MatrixIndicesMap") ) continue;
      
      if( verb > 1 ) fprintf(ofp, "-- have %d MIMap children\n", xt->nchild);

      for( kid=0; kid<xt->nchild; kid++ ) {
         mind = get_map_index(xt->xchild[kid]);
         if( kid >= 0 ) MIM_disp_funcs[mind](ofp, xt->xchild[kid], verb);
      }
   }

   return 0;
}
Example #2
0
  int CPacket_wait_manager::addWaitNode(int area, const data_entry*, const data_entry* value, int bucket_number,
      const vector<uint64_t>& des_server_ids, base_packet* request, uint32_t max_packet_id, int &version)
  {
    //check map_size first
    int index = get_map_index(max_packet_id);
    {
      //CRwLock m_lock(m_mutex,RLOCK);
      CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), false);
      if(m_PkgWaitMap[index].size() > TAIR_MAX_DUP_MAP_SIZE) return TAIR_RETURN_DUPLICATE_BUSY;
    }

    //CRwLock m_lock(m_mutex,WLOCK);
    CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), true);
    CDuplicatPkgMapIter itr = m_PkgWaitMap[index].find(max_packet_id);
    if (itr == m_PkgWaitMap[index].end())
    {
      //not found in map .inert it and inster to a queue.
      CPacket_wait_Nodes *pdelaysign = new CPacket_wait_Nodes(bucket_number, request, des_server_ids, version, value);
      changeBucketCount(bucket_number, 1);
      m_PkgWaitMap[index][max_packet_id] = pdelaysign;
      return TAIR_RETURN_SUCCESS;
    }
    else
    {
      //should never happen,but if crash and restared, nay mixed.
      log_error("packet sequnce id is dup");
      return TAIR_RETURN_DUPLICATE_IDMIXED;
    }
  }
Example #3
0
  int CPacket_wait_manager::doResponse(int bucket_number, uint64_t des_server_id, uint32_t max_packet_id,
      struct CPacket_wait_Nodes **ppNode)
  {
    //CRwLock m_lock(m_mutex,WLOCK);
    int index = get_map_index(max_packet_id);
    CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), true);

    CDuplicatPkgMapIter itr = m_PkgWaitMap[index].find(max_packet_id);
    if (itr != m_PkgWaitMap[index].end())
    {
      int ret=itr->second->do_response(bucket_number,des_server_id);
      if (0 == ret)
      {
        changeBucketCount(bucket_number, -1);
        *ppNode= itr->second;
        m_PkgWaitMap[index].erase(itr);
      }
      else
      {
        *ppNode= NULL;
      }

      return ret;
    }
    else
    {
      //already timeout.
      log_warn("resonse packet %u, but not found", max_packet_id);
	    *ppNode= NULL;
      return TAIR_RETURN_DUPLICATE_DELAY;
    }
  }
Example #4
0
 int CPacket_wait_manager::doTimeout( uint32_t max_packet_id)
 {
   //CRwLock m_lock(m_mutex,WLOCK);
   int index = get_map_index(max_packet_id);
   {
     CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), false);
     CDuplicatPkgMapIter itr = m_PkgWaitMap[index].find(max_packet_id);
     if (itr == m_PkgWaitMap[index].end()) return 0;
   }
   //now we should clear it.
   clear_waitnode(max_packet_id);
   return TAIR_RETURN_DUPLICATE_ACK_TIMEOUT;
 }
Example #5
0
  int CPacket_wait_manager::clear_waitnode( uint32_t max_packet_id)
  {
    int index=get_map_index(max_packet_id);
    CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), true);

    CDuplicatPkgMapIter itr = m_PkgWaitMap[index].find(max_packet_id);
    if (itr != m_PkgWaitMap[index].end())
    {
      CPacket_wait_Nodes* pNode = itr->second;
      changeBucketCount(pNode->bucket_number, -1);
      m_PkgWaitMap[index].erase(itr);
      delete pNode; pNode = NULL;
      return 0;
    }
    else
    {
	    log_error("clear_waitnode node but not found,packet=%d",max_packet_id);
    }
    return 0;
  }
Example #6
0
  int CPacket_wait_manager::doResponse(int bucket_number, uint64_t des_server_id, uint32_t max_packet_id,
      struct CPacket_wait_Nodes **ppNode)
  {
    //CRwLock m_lock(m_mutex,WLOCK);
    int index = get_map_index(max_packet_id);
    CScopedRwLock __scoped_lock(m_slots_locks->getlock(index), true);

    CDuplicatPkgMapIter itr = m_PkgWaitMap[index].find(max_packet_id);
    if (itr != m_PkgWaitMap[index].end())
    {
      int ret=itr->second->do_response(bucket_number,des_server_id);
      if (0 == ret)
      {
        changeBucketCount(bucket_number, -1);
        *ppNode= itr->second;
        m_PkgWaitMap[index].erase(itr);
      }
      else
      {
        *ppNode= NULL;
      }

      // at this point, we duplicate successfully and need record this key/value (rsync_manager->add_record(xx))
      // for remote sync, unfortunately, current duplicate_manager doest't maintain neccessary
      // context of request, so we can do noting but ignoring now.
      // Howerver, storage manager who just uses its own binlog can rest easy now, because rsyc_manager->add_record(xx)
      // is meaningless for it actually.
      // TODO: reconstruct duplicate_manager thoroughly.
      return ret;
    }
    else
    {
      //already timeout.
      log_warn("resonse packet %u, but not found", max_packet_id);
	    *ppNode= NULL;
      return TAIR_RETURN_DUPLICATE_DELAY;
    }
  }
Example #7
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    return list_lookup(map->lists[get_map_index(map, key)], key);
}
Example #8
0
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    int index = get_map_index(map, key);
    Node *first = prepend(key, value, map->lists[index]);
    map->lists[index] = first;
}
Example #9
0
/* This function takes the character string in ch->pnote and
 *  creates rooms laid out in the appropriate configuration.
 */
void map_to_rooms( CHAR_DATA * ch, MAP_INDEX_DATA * m_index )
{
   struct map_stuff map[49][78]; /* size of edit buffer */
   const char *newmap;
   int row, col, i, n, x, y, tvnum, proto_vnum = 0, leftmost, rightmost;
   int newx, newy;
   const char *l;
   char c;
   ROOM_INDEX_DATA *newrm;
   MAP_INDEX_DATA *map_index = NULL, *tmp;
   EXIT_DATA *xit;   /* these are for exits */
   bool getroomnext = FALSE;

   if( !ch->pnote )
   {
      bug( "%s: ch->pnote==NULL!", __FUNCTION__ );
      return;
   }

   /*
    * Make sure format is right 
    */
   newmap = check_map( ch->pnote->text );
   STRFREE( ch->pnote->text );
   ch->pnote->text = STRALLOC( newmap );

   n = 0;
   row = col = 0;
   leftmost = rightmost = 0;

   /*
    * Check to make sure map_index exists.  
    * If not, then make a new one.
    */
   if( !m_index )
   {
      /*
       * Make a new vnum 
       */
      for( i = ch->pcdata->area->low_r_vnum; i <= ch->pcdata->area->hi_r_vnum; i++ )
      {
         if( ( tmp = get_map_index( i ) ) == NULL )
         {
            map_index = make_new_map_index( i );
            break;
         }
      }
   }
   else
      map_index = m_index;

   /*
    *  
    */
   if( !map_index )
   {
      send_to_char( "Couldn't find or make a map_index for you!\r\n", ch );
      bug( "%s", "map_to_rooms: Couldn't find or make a map_index\r\n" );
      /*
       * do something. return failed or somesuch 
       */
      return;
   }

   for( x = 0; x < 49; x++ )
   {
      for( y = 0; y < 78; y++ )
      {
         map[x][y].vnum = 0;
         map[x][y].proto_vnum = 0;
         map[x][y].exits = 0;
         map[x][y].index = 0;
      }
   }

   l = ch->pnote->text;
   do
   {
      c = l[0];
      switch ( c )
      {
         case '\n':
            break;
         case '\r':
            col = 0;
            row++;
            break;
      }
      if( c != ' ' && c != '-' && c != '|' && c != '=' && c != '\\' && c != '/' && c != '^'
          && c != ':' && c != '[' && c != ']' && c != '^' && !getroomnext )
      {
         l++;
         continue;
      }
      if( getroomnext )
      {
         n++;
         /*
          * Actual room info 
          */
         map[row][col].vnum = add_new_room_to_map( ch, c );
         map_index->map_of_vnums[row][col] = map[row][col].vnum;
         map[row][col].proto_vnum = proto_vnum;
         getroomnext = FALSE;
      }
      else
      {
         map_index->map_of_vnums[row][col] = 0;
         map[row][col].vnum = 0;
         map[row][col].exits = 0;
      }
      map[row][col].code = c;
      /*
       * Handle rooms 
       */
      if( c == '[' )
         getroomnext = TRUE;
      col++;
      l++;
   }
   while( c != '\0' );

   for( y = 0; y < ( row + 1 ); y++ )
   {  /* rows */
      for( x = 0; x < 78; x++ )
      {  /* cols (78, i think) */

         if( map[y][x].vnum == 0 )
            continue;

         newrm = get_room_index( map[y][x].vnum );
         /*
          * Continue if no newrm 
          */
         if( !newrm )
            continue;

         /*
          * Check up 
          */
         if( y > 1 )
         {
            newx = x;
            newy = y;
            newy--;
            while( newy >= 0 && ( map[newy][x].code == '^' ) )
               newy--;

            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_UP );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check down 
          */
         if( y < 48 )
         {
            newx = x;
            newy = y;
            newy++;
            while( newy <= 48 && ( map[newy][x].code == '^' ) )
               newy++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_DOWN );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check north 
          */
         if( y > 1 )
         {
            newx = x;
            newy = y;
            newy--;
            while( newy >= 0 && ( map[newy][x].code == '|' || map[newy][x].code == ':' || map[newy][x].code == '=' ) )
               newy--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTH );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[newy + 1][x].code == ':' || map[newy + 1][x].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check south 
          */
         if( y < 48 )
         {
            newx = x;
            newy = y;
            newy++;
            while( newy <= 48 && ( map[newy][x].code == '|' || map[newy][x].code == ':' || map[newy][x].code == '=' ) )
               newy++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTH );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[newy - 1][x].code == ':' || map[newy - 1][x].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check east 
          */
         if( x < 79 )
         {
            newx = x;
            newy = y;
            newx++;
            while( newx <= 79 && ( map[y][newx].code == '-' || map[y][newx].code == ':' || map[y][newx].code == '='
                                   || map[y][newx].code == '[' || map[y][newx].code == ']' ) )
               newx++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[y][newx].vnum )
               break;
            if( ( tvnum = map[y][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_EAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[y][newx - 2].code == ':' || map[y][newx - 2].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check west 
          */
         if( x > 1 )
         {
            newx = x;
            newy = y;
            newx--;
            while( newx >= 0 && ( map[y][newx].code == '-' || map[y][newx].code == ':' || map[y][newx].code == '='
                                  || map[y][newx].code == '[' || map[y][newx].code == ']' ) )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[y][newx].vnum )
               break;
            if( ( tvnum = map[y][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_WEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[y][newx + 2].code == ':' || map[y][newx + 2].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check southeast 
          */
         if( y < 48 && x < 79 )
         {
            newx = x;
            newy = y;
            newx += 2;
            newy++;
            while( newx <= 79 && newy <= 48 && ( map[newy][newx].code == '\\' || map[newy][newx].code == ':'
                                                 || map[newy][newx].code == '=' ) )
            {
               newx++;
               newy++;
            }
            if( map[newy][newx].code == '[' )
               newx++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTHEAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check northeast 
          */
         if( y > 1 && x < 79 )
         {
            newx = x;
            newy = y;
            newx += 2;
            newy--;
            while( newx >= 0 && newy <= 48 && ( map[newy][newx].code == '/' || map[newy][newx].code == ':'
                                                || map[newy][newx].code == '=' ) )
            {
               newx++;
               newy--;
            }
            if( map[newy][newx].code == '[' )
               newx++;

            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTHEAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check northwest 
          */
         if( y > 1 && x > 1 )
         {
            newx = x;
            newy = y;
            newx -= 2;
            newy--;
            while( newx >= 0 && newy >= 0 && ( map[newy][newx].code == '\\' || map[newy][newx].code == ':'
                                               || map[newy][newx].code == '=' ) )
            {
               newx--;
               newy--;
            }
            if( map[newy][newx].code == ']' )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTHWEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check southwest 
          */
         if( y < 48 && x > 1 )
         {
            newx = x;
            newy = y;
            newx -= 2;
            newy++;
            while( newx >= 0 && newy <= 48 && ( map[newy][newx].code == '/' || map[newy][newx].code == ':'
                                                || map[newy][newx].code == '=' ) )
            {
               newx--;
               newy++;
            }
            if( map[newy][newx].code == ']' )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTHWEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }
      }
   }
}