Ejemplo n.º 1
0
void kr_message_free(T_KRMessage *krmsg)
{
    if (krmsg) {
        if (krmsg->msgbuf) kr_free(krmsg->msgbuf);
        kr_free(krmsg); 
    }
}
Ejemplo n.º 2
0
T_KREventLoop *kr_event_loop_create(int setsize) {
    T_KREventLoop *eventLoop;
    int i;

    if ((eventLoop = kr_malloc(sizeof(*eventLoop))) == NULL) goto err;
    eventLoop->events = kr_malloc(sizeof(T_KRFileEvent)*setsize);
    eventLoop->fired = kr_malloc(sizeof(T_KRFiredEvent)*setsize);
    if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err;
    eventLoop->setsize = setsize;
    eventLoop->timeEventHead = NULL;
    eventLoop->timeEventNextId = 0;
    eventLoop->stop = 0;
    eventLoop->maxfd = -1;
    eventLoop->beforesleep = NULL;
    if (kr_event_api_create(eventLoop) == -1) goto err;
    /* Events with mask == KR_EVENT_NONE are not set. So let's initialize the
     * vector with it. */
    for (i = 0; i < setsize; i++)
        eventLoop->events[i].mask = KR_EVENT_NONE;
    return eventLoop;

err:
    if (eventLoop) {
        kr_free(eventLoop->events);
        kr_free(eventLoop->fired);
        kr_free(eventLoop);
    }
    return NULL;
}
static void kr_hdi_cache_value_free(T_KRHdiCacheValue *cache_value)
{
    if (cache_value->eValueType == KR_TYPE_STRING) {
        kr_free(cache_value->uValue.s);
    }
    kr_free(cache_value);
}
Ejemplo n.º 4
0
/* initialize rule detecting context */
T_KRContext *kr_context_init(T_KRContextEnv *ptEnv)
{
    T_KRContext *ptContext = kr_calloc(sizeof(T_KRContext));
    if (ptContext == NULL) {
        KR_LOG(KR_LOGERROR, "kr_calloc ptContext failed!");
        return NULL;
    }

    ptContext->ptEnv = ptEnv;

    /* reconnect database in thread */
    T_DbsEnv *ptDbsEnv = ((T_KRContextEnv *)ptEnv)->ptDbsEnv;
    ptContext->ptDbsEnv = dbsConnect(ptDbsEnv->dsn, ptDbsEnv->user, ptDbsEnv->pass);
    if (ptContext->ptDbsEnv == NULL) {
        KR_LOG(KR_LOGERROR, "dbsConnect [%s] [%s] [%s] failed!", \
                ptDbsEnv->dsn, ptDbsEnv->user, ptDbsEnv->pass);
        kr_free(ptContext);
        return NULL;
    }

    /* construct data */
    ptContext->ptData = kr_data_construct(ptEnv->ptParam, ptEnv->dataModule, 
            ptDbsEnv, ptEnv->ptHDICache, kr_data_get_type, kr_data_get_value);
    if (ptContext->ptData == NULL) {
        KR_LOG(KR_LOGERROR, "kr_data_construct failed!");
        dbsDisconnect(ptContext->ptDbsEnv);
        kr_free(ptContext);
        return NULL;
    }
    
    /* construct flow */
    
    return ptContext;
}
Ejemplo n.º 5
0
static void kr_rebuild_index_del(T_KRIndexTable *ptIndextable, T_KRRecord *ptRecord)
{
    void *key = kr_field_get_value(ptRecord, ptIndextable->iIndexFieldId);
    T_KRHashTable *pHashTable = ptIndextable->ptIndex->pHashTable;

    T_KRIndexSolt *ptIndexSlot = kr_hashtable_lookup(pHashTable, key);
    if (ptIndexSlot != NULL) {
        /*modify statistical fields of external*/
        if (kr_get_proctime(ptRecord) > ptIndexSlot->tExtMaxProcTime) {
            ptIndexSlot->tExtMaxProcTime = kr_get_proctime(ptRecord);
        }
        if (kr_get_transtime(ptRecord) > ptIndexSlot->tExtMaxTransTime) {
            ptIndexSlot->tExtMaxTransTime = kr_get_transtime(ptRecord);
        }
        /*remove record from list*/
        kr_list_remove(ptIndexSlot->pRecList, ptRecord);

        /*free this slot if there is no records*/
        if (kr_list_length(ptIndexSlot->pRecList) == 0 ) {
            kr_hashtable_remove(pHashTable, ptIndexSlot->pKeyValue);
            kr_list_destroy(ptIndexSlot->pRecList);
            kr_free(ptIndexSlot->pKeyValue);
            kr_free(ptIndexSlot);
        }
    }
}
Ejemplo n.º 6
0
void kr_calc_destruct(T_KRCalc *krcalc)
{
    if (krcalc != NULL) {
        kr_free(krcalc->calc_string);
        kr_calctree_free(krcalc->calc_tree);
        kr_free(krcalc); krcalc = NULL;
    }
}
Ejemplo n.º 7
0
/* destroy this krset */
void kr_hashset_destroy(T_KRHashSet *krset)
{
    if (krset != NULL) {
        kr_hashtable_destroy(krset->set);
        kr_free(krset->name);
        kr_free(krset); krset=NULL;
    }
}
Ejemplo n.º 8
0
void kr_table_drop(T_KRTable *ptTable)
{
    kr_list_remove(ptTable->ptDB->pTableList, ptTable);
    pthread_mutex_destroy(&ptTable->tLock);
    kr_list_destroy(ptTable->pIndexTableList);
    kr_free(ptTable->pRecordBuff);
    kr_free(ptTable->ptFieldDef);
    kr_free(ptTable);
}
Ejemplo n.º 9
0
void kr_context_fini(T_KRContext *ptContext)
{
    if (ptContext) {
        kr_dynamicmem_fini(ptContext->ptDym);
        if (ptContext->ptArg) kr_free(ptContext->ptArg);
        dbsDisconnect(ptContext->ptDbs);
        kr_free(ptContext);
    }
}
Ejemplo n.º 10
0
void kr_data_item_free(T_KRDataItem *ptDataItem)
{
    if (ptDataItem) {
        if (ptDataItem->pfDataItemFree != NULL) {
            ptDataItem->pfDataItemFree(ptDataItem->ptPrivate);
        }
        if (ptDataItem->eValueType == KR_TYPE_STRING) {
            kr_free(ptDataItem->uValue.s);
        }
        kr_free(ptDataItem);
    }
}
Ejemplo n.º 11
0
void kr_skiplist_free(T_KRSkipList *krsl) 
{
    T_KRSkipListNode *node = krsl->header->forward[0], *next;

    kr_free(krsl->header);
    while(node) {
        next = node->forward[0];
        kr_skiplist_free_node(node);
        node = next;
    }
    kr_free(krsl);
}
Ejemplo n.º 12
0
void kr_db_drop(T_KRDB *ptDB)
{
    kr_list_destroy(ptDB->pTableList);
    kr_list_destroy(ptDB->pIndexList);
    kr_list_destroy(ptDB->pIndexTableList);
    kr_free(ptDB);
}
Ejemplo n.º 13
0
void kr_index_drop(T_KRIndex *ptIndex)
{
    kr_list_remove(ptIndex->ptDB->pIndexList, ptIndex);
    kr_hashtable_destroy(ptIndex->pHashTable);
    kr_list_destroy(ptIndex->pIndexTableList);
    kr_free(ptIndex);
}
Ejemplo n.º 14
0
T_KRHDITable *kr_hdi_table_construct(T_KRShmHDI *shm_hdi, T_KRModule *datamodule)
{
    T_KRHDITable *krhditable = kr_calloc(sizeof(T_KRHDITable));
    if (krhditable == NULL) {
        KR_LOG(KR_LOGERROR, "kr_calloc krhditable failed!");
        return NULL;
    }
    krhditable->ptShmHDIs = shm_hdi;
    krhditable->lHDICnt = shm_hdi->lHDIDefCnt;
    krhditable->ptHDITable = \
      kr_hashtable_new_full(kr_long_hash, kr_long_equal, \
                            NULL, (KRDestroyNotify )kr_hdi_destruct);
    
    int i = 0;
    T_KRHDI *krhdi = NULL;
    for (i=0; i<shm_hdi->lHDIDefCnt; ++i) {
        krhdi = kr_hdi_construct(&shm_hdi->stShmHDIDef[i], datamodule);
        if (krhdi == NULL) {
            KR_LOG(KR_LOGERROR, "kr_hdi_construct [%d] failed!", i);
            kr_hashtable_destroy(krhditable->ptHDITable);
            kr_free(krhditable);
            return NULL;
        }
        kr_hashtable_insert(krhditable->ptHDITable, &krhdi->lHDIId, krhdi);
    }
    krhditable->tConstructTime = shm_hdi->tLastLoadTime;
    
    return krhditable;    
}
Ejemplo n.º 15
0
void armci_shmalloc_exchange_offsets(context_t *ctx_local) 
{
    void **ptr_arr;
    void *ptr;
    armci_size_t bytes = 128;
    int i;    
    
    ptr_arr    = (void**)malloc(armci_nproc*sizeof(void*));
    offset_arr = (long*) malloc(armci_nproc*sizeof(long));
    if(!ptr_arr || !offset_arr) armci_die("armci_shmalloc_get_offsets: malloc failed", 0);

    /* get memory with same size on all procs */
    ptr = kr_malloc(bytes, ctx_local);
    if(!ptr) armci_die("armci_shmalloc_get_offsets: kr_malloc failed",bytes);
    
    bzero((char*)ptr_arr,armci_nproc*sizeof(void*));
    ptr_arr[armci_me] = ptr;

    /* now combine individual addresses into a single array */
    armci_exchange_address(ptr_arr, armci_nproc);
    
    /* identify offets */
    for (i=0; i<armci_nproc; i++) 
    {
       offset_arr[i] = (long) ((char*)ptr - (char*)ptr_arr[i]);
    }
       
    /* release memory */
    kr_free(ptr, ctx_local);
}
Ejemplo n.º 16
0
int kr_coordi_handle_svroff(T_KREventLoop *el, int fd, T_KRMessage *krmsg)
{
    KR_LOG(KR_LOGDEBUG, "Server [%s] Offline [%d]!", krmsg->serverid, fd);
    
    /* Check this server whether exists */
    T_KRActualNode *node = \
        kr_conhash_lookup(krcoordi.servers, krmsg->serverid);
    if (node == NULL) {
        KR_LOG(KR_LOGDEBUG, "Server %s not exists!", krmsg->serverid);
        return 0;
    }
    
    /* remove from fdtable */
    kr_hashtable_remove(krcoordi.fdtable, &fd);
    
    /* remove from conhash */
    T_KRCoordiConnector *ptServer = (T_KRCoordiConnector *)node->priv;
    kr_conhash_remove(krcoordi.servers, ptServer->id);

    /* Free this server */
    kr_event_file_delete(el, fd, KR_EVENT_READABLE);
    close(fd);
    
    kr_free(ptServer);
    
    return 0;
}
Ejemplo n.º 17
0
int kr_coordi_handle_clioff(T_KREventLoop *el, int fd, T_KRMessage *krmsg)
{
    KR_LOG(KR_LOGDEBUG, "Client [%s] Offline [%d]!", krmsg->clientid, fd);

    /* Check this client whether exists */
    T_KRListNode *node = kr_list_search(krcoordi.clients, krmsg->clientid);
    if (node == NULL) {
        KR_LOG(KR_LOGDEBUG, "Client %s not exists!", krmsg->clientid);
        return 0;
    }
   
    /*remove from list*/
    T_KRCoordiConnector *ptClient = (T_KRCoordiConnector *)node->value;
    kr_list_remove(krcoordi.clients, ptClient->id);

    /* remove from fdtable */
    kr_hashtable_remove(krcoordi.fdtable, &fd);
    
    /* Free this client */
    kr_event_file_delete(el, fd, KR_EVENT_READABLE);
    close(fd);
    
    kr_free(ptClient);
    
    return 0;
}
Ejemplo n.º 18
0
void kr_drop_table(T_KRTable *krtable, T_KRDB *krdb)
{
    if (krtable->caMMapFile[0] == '\0') {
        kr_free(krtable->pRecordBuff);
    } else {
        kr_db_unmmap_table(krtable);
    }

    kr_list_remove(krdb->pTableList, krtable);
    kr_list_foreach(krtable->pIndexList, \
                    (KRForEachFunc )kr_drop_table_index, krtable);
    kr_list_destroy(krtable->pIndexList);

    kr_free(krtable->ptFieldDef);
    kr_free(krtable);
}
Ejemplo n.º 19
0
void kr_data_destruct(T_KRData *ptData)
{
    if (ptData) {
        kr_hashtable_destroy(ptData->ptItemTable);
        kr_free(ptData);
    }
}
Ejemplo n.º 20
0
/*fixed format*/
void *fixed_define_pre_func(T_KRParamInput *ptParamInput)
{
    T_KRIfaceFixedData *fixed_data = kr_calloc(sizeof(*fixed_data));

    /* Open Define File */
    fixed_data->datasrc_id = ptParamInput->lInputId;
    strcpy(fixed_data->datasrc_name, ptParamInput->caInputName);
    snprintf(fixed_data->filename, sizeof(fixed_data->filename), \
                "%s.h", ptParamInput->caInputName);
    fixed_data->fp = fopen(fixed_data->filename, "w");
    if (fixed_data->fp == NULL) {
        fprintf(stdout, "open output file: %s failed\n", fixed_data->filename);
        kr_free(fixed_data);
        return NULL;
    }
    /* Generate Define file head*/
    FILE *fp = fixed_data->fp;
    fprintf(fp, "#ifndef __KR_INTERFACE_%d_H__ \n", fixed_data->datasrc_id);
    fprintf(fp, "#define __KR_INTERFACE_%d_H__ \n", fixed_data->datasrc_id);
    fprintf(fp, "#include <stdint.h> \n");
    fprintf(fp, "\n\n");
    fprintf(fp, "typedef struct _kr_interface_%d_t \n", fixed_data->datasrc_id);
    fprintf(fp, "{\n");

    return fixed_data;
}
Ejemplo n.º 21
0
/*make a new hashset from multi_string*/
T_KRHashSet *kr_hashset_make(E_KRType key_type, char *multi_string)
{
    T_KRHashSet *krhashset = kr_hashset_create(multi_string, key_type);
    if (krhashset == NULL) {
        return NULL;
    }
    char *str = kr_strdup(multi_string);
    char *save_str = NULL;
    char *p = strtok_r(str, ",", &save_str);
    U_KRValue val;
    while(p)
    {
        switch(krhashset->type) 
        {
            case KR_TYPE_INT:
                val.i=atoi(p);
                kr_hashset_add(krhashset, &val.i);
                break;
            case KR_TYPE_DOUBLE:
                val.d=atof(p);
                kr_hashset_add(krhashset, &val.d);
                break;
            case KR_TYPE_STRING:
                p = p+1;
                p[strlen(p)-1] = '\0';
                val.s=p;
                kr_hashset_add(krhashset, val.s);
                break;
        }
        p=strtok_r(NULL, ",", &save_str);
    }
    kr_free(str);

    return krhashset;
}
Ejemplo n.º 22
0
T_KRHDITable *kr_hdi_table_construct(T_KRParamHDI *ptParamHDI, T_KRModule *ptModule)
{
    T_KRHDITable *ptHdiTable = kr_calloc(sizeof(T_KRHDITable));
    if (ptHdiTable == NULL) {
        KR_LOG(KR_LOGERROR, "kr_calloc ptHdiTable failed!");
        return NULL;
    }
    ptHdiTable->ptParamHDI = ptParamHDI;
    ptHdiTable->lHDICnt = ptParamHDI->lHDIDefCnt;
    ptHdiTable->ptHDITable = \
      kr_hashtable_new_full(kr_long_hash, kr_long_equal, \
                            NULL, (KRDestroyNotify )kr_hdi_destruct);
    
    int i = 0;
    T_KRHDI *ptHDI = NULL;
    for (i=0; i<ptParamHDI->lHDIDefCnt; ++i) {
        ptHDI = kr_hdi_construct(&ptParamHDI->stParamHDIDef[i], ptModule);
        if (ptHDI == NULL) {
            KR_LOG(KR_LOGERROR, "kr_hdi_construct [%d] failed!", i);
            kr_hashtable_destroy(ptHdiTable->ptHDITable);
            kr_free(ptHdiTable);
            return NULL;
        }
        kr_hashtable_insert(ptHdiTable->ptHDITable, &ptHDI->lHDIId, ptHDI);
    }
    ptHdiTable->tConstructTime = ptParamHDI->tLastLoadTime;
    
    return ptHdiTable;    
}
Ejemplo n.º 23
0
void kr_context_fini(T_KRContext *ptContext)
{
    if (ptContext) {
        kr_data_destruct(ptContext->ptData);
        dbsDisconnect(ptContext->ptDbsEnv);
        kr_free(ptContext);
    }
}
Ejemplo n.º 24
0
void kr_param_persist_file_dump_post(void *ptResource, T_KRParamPersistConfig *ptConfig)
{
    cJSON *root = (cJSON *)ptResource;
    char *psFileName = ptConfig->value.file;
    
    char *data = cJSON_Print(root); cJSON_Delete(root);
    FILE *fp=fopen(psFileName, "w"); fprintf(fp, "%s", data); fflush(fp); fclose(fp);
    kr_free(data);
}
Ejemplo n.º 25
0
void kr_drop_db(T_KRDB *krdb)
{
    kr_list_foreach(krdb->pTableList, (KRForEachFunc)kr_drop_table, krdb);
    kr_list_destroy(krdb->pTableList);

    kr_list_foreach(krdb->pIndexList, (KRForEachFunc)kr_drop_db_index, krdb);
    kr_list_destroy(krdb->pIndexList);

    kr_free(krdb);
}
Ejemplo n.º 26
0
void kr_index_table_drop(T_KRIndexTable *ptIndexTable)
{
    T_KRTable *ptTable = ptIndexTable->ptTable;
    T_KRIndex *ptIndex = ptIndexTable->ptIndex;

    kr_list_remove(ptIndex->pIndexTableList, ptIndexTable);
    kr_list_remove(ptTable->pIndexTableList, ptIndexTable);

    kr_free(ptIndexTable);
}
Ejemplo n.º 27
0
void kr_hdi_init(T_KRHDI *ptHDI)
{
    /*initialize first*/
    ptHDI->eValueInd = KR_VALUE_UNSET;

    /*string comes from kr_strdup, need kr_free*/
    if (ptHDI->eValueType == KR_TYPE_STRING)
        kr_free(ptHDI->uValue.s);
    memset(&ptHDI->uValue, 0x00, sizeof(ptHDI->uValue));
}
Ejemplo n.º 28
0
void kr_data_item_ddi_free(void *priv) 
{
    T_KRDdi *ptDdi = (T_KRDdi *)priv;
    if (ptDdi != NULL) {
        kr_calc_destruct(ptDdi->ptFilterCalc);
        kr_calc_destruct(ptDdi->ptResultCalc);
        kr_hashtable_destroy(ptDdi->ptRelated);
        kr_free(ptDdi);
    }
}
Ejemplo n.º 29
0
static void kr_ntrees_free(T_KRNTree *node)
{
    while (node)
    {
        T_KRNTree *next = node->next;
        if (node->children)
            kr_ntrees_free (node->children);
        kr_free (node);
        node = next;
    }
}
Ejemplo n.º 30
0
void kr_ddi_init(T_KRDDI *ptDDI)
{
    /*initialize first*/
    ptDDI->eValueInd = KR_VALUE_UNSET;
    kr_hashtable_remove_all(ptDDI->ptRelated);

    /*string comes from kr_strdup, need kr_free*/
    if (ptDDI->eValueType == KR_TYPE_STRING)
        kr_free(ptDDI->uValue.s);
    memset(&ptDDI->uValue, 0x00, sizeof(ptDDI->uValue));
}