/*Currently we are having another API clCorClassDelete for same purpose. However,
  it takes class handle as input. If we plan to remove it. This will be useful.*/
ClRcT
dmClassDelete(ClCorClassTypeT id)
{
    ClRcT ret = CL_OK;
    CORClass_h tmp = 0;
    
    CL_FUNC_ENTER();

    if((!dmGlobal))
      {
        CL_FUNC_EXIT();  
        return(CL_COR_SET_RC(CL_COR_ERR_NULL_PTR));
      }
    
    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassDelete (Class:%04x)", id));
    
    /* check if class already present 
     */
    HASH_GET(dmGlobal->classTable, id, tmp);
    if(tmp) 
      {
        ret = dmClassByHandleDelete(tmp);
      } 
    else 
      {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "ClassDelete (Class:%04x) [Unknown class]", 
                              id));
        
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_NOT_PRESENT);
      }
    
    CL_FUNC_EXIT();
    return (ret);
}
コード例 #2
0
ファイル: connections.c プロジェクト: daiyoko/Arbitrator
/**
 * @param source_ip: Client's IP address in presentation format.
 * @param port: Server's port connection.
 * @return pointer to connection
 *
 * Looks up existing connections between the arbitrator->server.
 * This is done based off of connections between the client->arbitrator.
 *
 *  [client]            [arbitrator]            [server]
 *            ----->
 *            1st(based)                ----->
 *                                      2nd(derive)
 */
struct Connection *
connection_lookup(hashtable_t *connection_table, char *source_ip,
                  short port)
{
    connection_t *connection;

    if (connection = HASH_GET(connection_table, source_ip)) {
        DEBUG("FOUND %s -> %s:%d\n",
               source_ip, inet_ntoa(connection->node->ip),
               connection->port);
        return connection;
    }
    else {
        struct sockaddr_in servaddr;
        node_t *node;

        connection = malloc(sizeof(connection_t));

        node = current_algorithm.function(source_ip);
        connection->node = node;
        connection->port = port;
        pthread_mutex_init(&connection->in_progress, NULL);

        DEBUG("CREATE %s -> %s:%d\n", source_ip,
               inet_ntoa(connection->node->ip),
               connection->port);

        HASH_ADD(connection_table, source_ip, connection);
        return connection;
    }
}
/** 
 *  Get Class Type.
 *
 *  Returns Class Type information for the specified class id.
 *
 *  @param this   Data Manager Handle
 *  @param id     Class Identifier
 *
 *  @returns 
 *    CORClass_h   (non-null) class type handle
 *      null(0)    on failure.
 * 
 */
CORClass_h 
dmClassGet(ClCorClassTypeT id
           )
{
    CORClass_h tmp = 0;

    CL_FUNC_ENTER();
    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassGet (Class:%04x)", id));

    if(dmGlobal)
      {
        HASH_GET(dmGlobal->classTable, id, tmp);
      }

    CL_FUNC_EXIT();
    return (tmp);
}
コード例 #4
0
ファイル: arp_exist.c プロジェクト: ychtiger/capiflash
// if successful returns length of value
int ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp)
{
  scb_t            *scbp     = &(_arkp->poolthreads[tid]);
  rcb_t            *rcbp     = &(_arkp->rcbs[tcbp->rtag]);
  ark_io_list_t    *bl_array = NULL;
  int32_t           rc       = 0;
  int32_t           state    = ARK_CMD_DONE;

  // Now that we have the hash entry, get the block
  // that holds the control information for the entry.
  tcbp->hblk = HASH_LBA(HASH_GET(_arkp->ht, rcbp->pos));

  // If there is no control block for this hash
  // entry, then the key is not present in the hash.
  // Set the error
  if ( tcbp->hblk == 0 )
  {
    KV_TRC_FFDC(pAT, "rc = ENOENT key %p, klen %"PRIu64"",
                 rcbp->key, rcbp->klen);
    rcbp->res   = -1;
    rcbp->rc = ENOENT;
    state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  // Set up the in-buffer to read in the hash bucket
  // that contains the key
  tcbp->blen = bl_len(_arkp->bl, tcbp->hblk);
  rc = bt_growif(&(tcbp->inb), &(tcbp->inb_orig), &(tcbp->inblen), 
                  (tcbp->blen * _arkp->bsize));
  if (rc != 0)
  {
    rcbp->res = -1;
    rcbp->rc = rc;
    state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  // Create a chain of blocks to be passed to be read
  bl_array = bl_chain(_arkp->bl, tcbp->hblk, tcbp->blen);
  if (bl_array == NULL)
  {
    rcbp->rc = ENOMEM;
    rcbp->res = -1;
    state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  scbp->poolstats.io_cnt += tcbp->blen;

  rc = ea_async_io_mod(_arkp, ARK_EA_READ, (void *)tcbp->inb, bl_array, 
                   tcbp->blen, 0, tcbp->ttag, ARK_EXIST_FINISH);
  if (rc < 0)
  {
    rcbp->rc = -rc;
    rcbp->res = -1;
    state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }
  else if (rc == 0)
  {
    state = ARK_IO_HARVEST;
  }
  else
  {
    state = ark_exist_finish(_arkp, tid, tcbp);
  }

ark_exist_start_err:

  return state;
}
/** 
 * Delete a class from class handle.
 *
 * API to dmClassByHandleDelete <Deailed desc>. 
 *
 *  @param this       object handle
 *  @param 
 * 
 *  @returns 
 *    ClRcT  CL_OK on success <br>
 *     CL_COR_SET_RC(CL_COR_ERR_NULL_PTR) on null parameter.
 *
 *  @todo      
 *
 */
ClRcT
dmClassByHandleDelete(CORClass_h classHandle
                      )
{
    ClRcT ret = CL_OK;
    CORClass_h tmp = 0;

    CL_FUNC_ENTER();

    if((!classHandle) || (!dmGlobal))
      {
        CL_FUNC_EXIT();  
        return(CL_COR_SET_RC(CL_COR_ERR_NULL_PTR));
      }
    
    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassDelete (Class:%04x)", 
                          classHandle->classId));


    /* check if instances are there and also base classes
     * by default cannot be deleted, they may be in other
     * inherited classes.
     */
    if (COR_CLASS_IS_BASE(*classHandle))
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "ClassDelete (Class:%04x) [Class is base]", classHandle->classId));
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_IS_BASE);
    }
    else if(classHandle->objCount == 0 && 
           (classHandle->moClassInstances == 0))
      {
        
        /* get the handle to the parent class */
        HASH_GET(dmGlobal->classTable,classHandle->superClassId, tmp);
        if(tmp)
        {
            tmp->noOfChildren--;
            if(tmp->noOfChildren == 0)
                COR_CLASS_RESETAS_BASE(*tmp);
        }
        /* now we can remove from hash table & free it 
         */
        HASH_REMOVE(dmGlobal->classTable, classHandle->classId);
        /* free the attribute list hashtable and the elements in
         * the vector 
         */
        HASH_FREE(classHandle->attrList);
        COR_LLIST_FREE(classHandle->objFreeList);

        corVectorRemoveAll(&classHandle->attrs);
        /* nothing to remove in the objects vector */
        clHeapFree(classHandle);
      } 
    else 
      {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "ClassDelete (Class:%04x) [Instances present]", 
                              classHandle->classId));
        
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_INSTANCES_PRESENT);
      }
    
    CL_FUNC_EXIT();
    return (ret);
}
/** 
 *  Class Type create API.
 *
 *  Creates a new class type with the given information like class id,
 *  number of attributes, max and minimum instances for the class.
 *  NOTE: What happens in case of different versions?? need to figure
 *  out.
 *
 *  @param id            class id
 *  @param nAttrs        Number of attributes in class.
 *
 *  @returns 
 *    CORClass_h   (non-null) valid class handle
 *      null(0)    on failure.
 * 
 */
ClRcT
dmClassCreate(ClCorClassTypeT id,
              ClCorClassTypeT inhId)
{
    CORClass_h tmp = 0;
    CORClass_h tmp1 = 0;
    ClRcT ret = CL_OK;

    CL_FUNC_ENTER();

    if(!dmGlobal)
    {
        CL_FUNC_EXIT();  
        return(CL_COR_SET_RC(CL_COR_ERR_NULL_PTR));
    }
    
    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassCreate (Class:%04x, Inh:%04x)", id, inhId));
    
    /* check if id & inhId is already present 
     */
    HASH_GET(dmGlobal->classTable, id, tmp);
    if(inhId > 0) 
    {
        HASH_GET(dmGlobal->classTable, inhId, tmp1);
    }
    
    if(tmp) 
    {
        CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassCreate (Class:%04x, Inh:%04x) [Class present]", id, inhId));
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_PRESENT);
    } 
    else if(tmp1 == 0 && inhId > 0) 
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "ClassCreate (Class:%04x, Inh:%04x) [Superclass unknown]", id, inhId));
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_NOT_PRESENT);
    } 
    else 
    {
        /* Create the new class
         */
        tmp = (CORClass_h) clHeapAllocate(sizeof(CORClass_t));
        if(tmp != 0) 
        {
            /* init stuff here */
            tmp->classId = id;
            tmp->superClassId = inhId; 
            tmp->size = -1;
            tmp->version.releaseCode = CL_RELEASE_VERSION;
            tmp->version.majorVersion = CL_MAJOR_VERSION;
            tmp->version.minorVersion = CL_MINOR_VERSION;
            tmp->flags = 0;
            tmp->moClassInstances = 0;

            if (CL_OK != (ret = HASH_CREATE(&tmp->attrList)))
            { 
                  clHeapFree(tmp);
                  CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "Failed to create hash table for Attributes [rc 0x%x]", ret));
                  CL_FUNC_EXIT();  
                  return (ret);
            }
        
            if (CL_OK != (ret = COR_LLIST_CREATE(&tmp->objFreeList)))
            {
                clHeapFree(tmp);
                CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "Failed to create hash table for free objects [rc 0x%x]", ret));
                CL_FUNC_EXIT();
                return (ret);
            }

            tmp->nAttrs = 0;
            tmp->noOfChildren = 0;
            tmp->recordId = 1;
            tmp->objCount = 0;
            tmp->objBlockSz = COR_OBJ_DEF_BLOCK_SIZE;

            /* init the vector, check the return value
             * and remove class/hashtable
             */
            if (CL_OK != (ret = corVectorInit(&tmp->attrs, 
                          sizeof(CORAttr_t),
                          COR_CLASS_DEF_BLOCK_SIZE)))
            {
                HASH_FREE(tmp->attrList);
                COR_LLIST_FREE(tmp->objFreeList);
                clHeapFree(tmp);
    	        CL_FUNC_EXIT();  
     	        return (ret);
	        }

            /* add the newly created class to the class table */
            if (CL_OK != (ret = HASH_PUT(dmGlobal->classTable, id, tmp)))
	        {
              corVectorRemoveAll(&tmp->attrs);
              HASH_FREE(tmp->attrList);
              COR_LLIST_FREE(tmp->objFreeList);
              clHeapFree(tmp);
       	      CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "Failed to add class in Data Manager [rc 0x%x]", ret));
    	      CL_FUNC_EXIT();  
     	      return (ret);
	        }
            /* declare the inh class as base class */
            if(inhId > 0) 
            {
                tmp1->noOfChildren++;
                COR_CLASS_SETAS_BASE(*tmp1);
            }
        } 
        else 
        {
	        clLogWrite(CL_LOG_HANDLE_APP, CL_LOG_DEBUG, NULL,
				CL_LOG_MESSAGE_0_MEMORY_ALLOCATION_FAILED);
                CL_DEBUG_PRINT(CL_DEBUG_CRITICAL, (CL_COR_ERR_STR_MEM_ALLOC_FAIL)); 
            ret = CL_COR_SET_RC(CL_COR_ERR_NO_MEM);
        }
    }

    CL_FUNC_EXIT();  
    return (ret);
}
コード例 #7
0
ファイル: arp_exist.c プロジェクト: bedrisendir/capiflash
// if successful returns length of value
void ark_exist_start(_ARK *_arkp, int tid, tcb_t *tcbp)
{
  scb_t         *scbp     = &(_arkp->poolthreads[tid]);
  rcb_t         *rcbp     = &(_arkp->rcbs[tcbp->rtag]);
  tcb_t         *iotcbp   = &(_arkp->tcbs[rcbp->ttag]);
  iocb_t        *iocbp    = &(_arkp->iocbs[rcbp->ttag]);
  ark_io_list_t *bl_array = NULL;
  int32_t        rc       = 0;

  // Now that we have the hash entry, get the block
  // that holds the control information for the entry.
  tcbp->hblk = HASH_LBA(HASH_GET(_arkp->ht, rcbp->pos));

  // If there is no control block for this hash
  // entry, then the key is not present in the hash.
  // Set the error
  if ( tcbp->hblk == 0 )
  {
    KV_TRC_FFDC(pAT, "rc = ENOENT key %p, klen %"PRIu64" ttag:%d",
                 rcbp->key, rcbp->klen, tcbp->ttag);
    rcbp->res   = -1;
    rcbp->rc = ENOENT;
    tcbp->state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  // Set up the in-buffer to read in the hash bucket
  // that contains the key
  tcbp->blen = bl_len(_arkp->bl, tcbp->hblk);
  rc = bt_growif(&(tcbp->inb), &(tcbp->inb_orig), &(tcbp->inblen), 
                  (tcbp->blen * _arkp->bsize));
  if (rc != 0)
  {
    KV_TRC_FFDC(pAT, "bt_growif failed tcbp:%p ttag:%d", tcbp, tcbp->ttag);
    rcbp->res = -1;
    rcbp->rc = rc;
    tcbp->state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  // Create a chain of blocks to be passed to be read
  bl_array = bl_chain(_arkp->bl, tcbp->hblk, tcbp->blen);
  if (bl_array == NULL)
  {
    KV_TRC_FFDC(pAT, "bl_chain failed tcbp:%p ttag:%d", tcbp, tcbp->ttag);
    rcbp->rc = ENOMEM;
    rcbp->res = -1;
    tcbp->state = ARK_CMD_DONE;
    goto ark_exist_start_err;
  }

  scbp->poolstats.io_cnt += tcbp->blen;

  KV_TRC_IO(pAT, "read hash entry ttag:%d", tcbp->ttag);
  ea_async_io_init(_arkp, ARK_EA_READ, (void *)tcbp->inb, bl_array,
                   tcbp->blen, 0, tcbp->ttag, ARK_EXIST_FINISH);
  if (ea_async_io_schedule(_arkp, tid, iotcbp, iocbp) &&
      ea_async_io_harvest (_arkp, tid, iotcbp, iocbp, rcbp))
  {
      ark_exist_finish(_arkp, tid, tcbp);
  }

ark_exist_start_err:

  return;
}