예제 #1
0
c_char*
cmx_readerSnapshotNew(
    const c_char* reader)
{
    u_entity e;
    c_char* result;
    struct cmx_readerSnapshotArg arg;
    os_mutex m;
    
    arg.success = FALSE;
    result = NULL;
    e = cmx_entityUserEntity(reader);
    
    if(e != NULL){    
        u_entityAction(e, cmx_readerSnapshotNewAction, &arg);
        
        if(arg.success == TRUE){
            m = cmx_getReaderSnapshotMutex();
            os_mutexLock(&m);
            readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot);
            os_mutexUnlock(&m);
            
            result = (c_char*)(os_malloc(60));
            os_sprintf(result, "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>", (c_address)(arg.snapshot));
        }
    }
    return result;
}
예제 #2
0
cmx_readerSnapshot
cmx_readerSnapshotLookup(
    const c_char* snapshot)
{
    c_char* copy;
    c_char* temp;
    cmx_readerSnapshot s;
    os_mutex m;
    
    s = NULL;
    
    if(snapshot != NULL){
        copy = (c_char*)(os_malloc(strlen(snapshot) + 1));
        os_strcpy(copy, snapshot);
        temp = strtok((c_char*)copy, "</>");    /*<readerSnapshot>*/
        temp = strtok(NULL, "</>");             /*<id>*/
        temp = strtok(NULL, "</>");             /*... the pointer*/
         
        if(temp != NULL){
            sscanf(temp, PA_ADDRFMT, (c_address *)(&s));
            
            m = cmx_getReaderSnapshotMutex();
            os_mutexLock(&m);
            
            if(c_iterContains(readerSnapshots, s) == FALSE){
                s = NULL;
            }
            os_mutexUnlock(&m);
        }
        os_free(copy);
    }
    return s;
}
예제 #3
0
void
cmx_readerSnapshotFree(
    c_char* snapshot)
{
    cmx_readerSnapshot s;
    c_char* sample;
    os_mutex m;
    
    s = cmx_readerSnapshotLookup(snapshot);
    
    if(s != NULL){   
        m = cmx_getReaderSnapshotMutex();
        os_mutexLock(&m);
        c_iterTake(readerSnapshots, s);
        os_mutexUnlock(&m);
            
        if(s->samples != NULL){
            sample = (c_char*)(c_iterTakeFirst(s->samples));
            
            while(sample != NULL){
                os_free(sample);
                sample = (c_char*)(c_iterTakeFirst(s->samples));
            }
            c_iterFree(s->samples);
        }
        os_free(s);
        os_free(snapshot);
    }
}
예제 #4
0
void
cmx_readerSnapshotFreeAll()
{
    cmx_readerSnapshot s;
    c_char* sample;
    os_mutex m;
    
    m = cmx_getReaderSnapshotMutex();
    os_mutexLock(&m);
    s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots));
    
    while(s != NULL){
        if(s->samples != NULL){
            sample = (c_char*)(c_iterTakeFirst(s->samples));
            
            while(sample != NULL){
                os_free(sample);
                sample = (c_char*)(c_iterTakeFirst(s->samples));
            }
            c_iterFree(s->samples);
        }
        os_free(s);
        s = cmx_readerSnapshot(c_iterTakeFirst(readerSnapshots));
    }
    os_mutexUnlock(&m);
}
예제 #5
0
c_char*
cmx_readerSnapshotNew(
    const c_char* reader)
{
    cmx_entity ce;
    c_char* result;
    struct cmx_readerSnapshotArg arg;
    os_mutex m;

    arg.success = FALSE;
    result = NULL;

    ce = cmx_entityClaim(reader);
    if(ce != NULL){
        if (u_observableAction(u_observable(ce->uentity),
                               cmx_readerSnapshotNewAction,
                               &arg) == U_RESULT_OK)
        {
            if(arg.success == TRUE){
                m = cmx_getReaderSnapshotMutex();
                os_mutexLock(&m);
                readerSnapshots = c_iterInsert(readerSnapshots, arg.snapshot);
                os_mutexUnlock(&m);

                result = (c_char*)(os_malloc(60));
                os_sprintf(result,
                           "<readerSnapshot><id>"PA_ADDRFMT"</id></readerSnapshot>",
                           (c_address)(arg.snapshot));
            }
        }
        cmx_entityRelease(ce);
    }
    return result;
}