コード例 #1
0
ファイル: cmx_writer.c プロジェクト: diorahman/opensplice
void
cmx_writerDataTypeAction(
    v_entity entity,
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    c_type type;
    struct cmx_writerTypeArg *arg;
    arg = (struct cmx_writerTypeArg *)args;
    
    type = NULL;
    
    switch(v_object(entity)->kind){
    case K_WRITER:
        type = v_topicDataType(v_writer(entity)->topic);      
    break;
    default:
        OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Trying to resolve dataType of writer that is not a writer.\n");
        assert(FALSE);
    break;
    }
    
    if(type != NULL){
        ser = sd_serializerXMLMetadataNew(c_getBase(type));
        data = sd_serializerSerialize(ser, type);
        arg->result = sd_serializerToString(ser, data);
        sd_serializedDataFree(data);
        sd_serializerFree(ser);
    }
}
コード例 #2
0
ファイル: cmx_reader.c プロジェクト: AmitShah/opensplice
v_actionResult
cmx_readerReadCopy(
    c_object o,
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    v_dataReaderSample sample, newer;
    struct cmx_readerArg *arg;
    v_actionResult result;

    result = 0;
    if(o != NULL){
        sample = v_dataReaderSample(o);

        if(v_stateTest(v_readerSampleState(sample), L_READ)){
            v_actionResultSet(result, V_PROCEED);
        } else {
            sample = v_dataReaderSample(o);
            newer = sample->newer;
            sample->newer = NULL;

            arg = (struct cmx_readerArg *)args;
            ser = sd_serializerXMLNewTyped(c_getType(o));
            data = sd_serializerSerialize(ser, o);
            arg->result = sd_serializerToString(ser, data);
            sd_serializedDataFree(data);
            sd_serializerFree(ser);

            sample->newer = newer;
        }
    }
    return result;
}
コード例 #3
0
ファイル: cmx_participant.c プロジェクト: osrf/opensplice
const c_char*
cmx_participantRegisterType(
    const c_char* participant,
    const c_char* type)
{
    sd_serializer serializer;
    sd_serializedData meta_data;
    cmx_entityKernelArg kernelArg;
    c_type topicType;
    cmx_entity ce;
    const c_char* result;
    const c_char* msg;

    ce = cmx_entityClaim(participant);
    if(ce != NULL){
        kernelArg = cmx_entityKernelArg(os_malloc(C_SIZEOF(cmx_entityKernelArg)));
        if (u_observableAction(u_observable(ce->uentity),
                               cmx_entityKernelAction,
                               (c_voidp)kernelArg) == U_RESULT_OK)
        {
            serializer = sd_serializerXMLMetadataNew(c_getBase(c_object(kernelArg->kernel)));

            if(serializer != NULL){
                meta_data = sd_serializerFromString(serializer, type);

                if (meta_data != NULL) {
                    topicType = c_type(sd_serializerDeserialize(serializer, meta_data));

                    if (topicType == NULL) {
                        msg = sd_serializerLastValidationMessage(serializer);
                        OS_REPORT(OS_ERROR,
                                  CM_XML_CONTEXT, 0,
                                  "Data type could not be registered, "
                                  "because it is not valid: %s",
                                  msg);
                        result = CMX_RESULT_FAILED;
                    } else {
                        result = CMX_RESULT_OK;
                    }
                    sd_serializedDataFree(meta_data);
                } else {
                    OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Construction of serialized data failed.");
                    result = CMX_RESULT_FAILED;
                }
                sd_serializerFree(serializer);
            } else {
                OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Serializer could not be initialized");
                result = CMX_RESULT_FAILED;
            }
        } else {
            OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Kernel object could not be retrieved");
            result = CMX_RESULT_FAILED;
        }
        os_free(kernelArg);
        cmx_entityRelease(ce);
    } else {
        result = CMX_RESULT_FAILED;
    }
    return result;
}
コード例 #4
0
ファイル: cmx_reader.c プロジェクト: AmitShah/opensplice
v_actionResult
cmx_readerCopy(
    c_object o,
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    struct cmx_readerArg *arg;
    v_dataReaderSample sample, older;
    v_actionResult result = 0;
    v_lifespanSample next;

    arg = (struct cmx_readerArg *)args;

    if(o != NULL){
        sample = v_dataReaderSample(o);
        older = sample->older;
        next = sample->_parent._parent.next;
        sample->older = NULL;
        sample->_parent._parent.next = NULL;

        ser = sd_serializerXMLNewTyped(c_getType(o));
        data = sd_serializerSerialize(ser, o);
        arg->result = sd_serializerToString(ser, data);
        sd_serializedDataFree(data);
        sd_serializerFree(ser);

        sample->older = older;
        sample->_parent._parent.next = next;
    }
    return result;
}
コード例 #5
0
ファイル: cmx_reader.c プロジェクト: xrl/opensplice_dds
c_bool
cmx_readerReadCopy(
    c_object o, 
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    v_dataReaderSample sample, prev;
    struct cmx_readerArg *arg;
    c_bool result;
    
    result = FALSE;
        
    if(o != NULL){
        sample = v_dataReaderSample(o);
        
        if(v_stateTest(v_readerSampleState(sample), L_READ)){
            result = TRUE;
        } else {
            sample = v_dataReaderSample(o);
            prev = sample->prev;
            sample->prev = NULL;
                    
            arg = (struct cmx_readerArg *)args;
            ser = sd_serializerXMLNewTyped(c_getType(o));
            data = sd_serializerSerialize(ser, o);
            arg->result = sd_serializerToString(ser, data);
            sd_serializedDataFree(data);
            sd_serializerFree(ser);
            
            sample->prev = prev;
        }
    }
    return result;
}
コード例 #6
0
ファイル: cmx_reader.c プロジェクト: xrl/opensplice_dds
c_bool
cmx_readerCopy(
    c_object o, 
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    struct cmx_readerArg *arg;
    v_dataReaderSample sample, prev;
    
    arg = (struct cmx_readerArg *)args;
    
    if(o != NULL){
        sample = v_dataReaderSample(o);
        prev = sample->prev;
        sample->prev = NULL;
        
        ser = sd_serializerXMLNewTyped(c_getType(o));
        data = sd_serializerSerialize(ser, o);
        arg->result = sd_serializerToString(ser, data);
        sd_serializedDataFree(data);
        sd_serializerFree(ser);

        sample->prev = prev;
    }
    return FALSE;
}
コード例 #7
0
ファイル: d_topicInfo.c プロジェクト: xrl/opensplice_dds
static c_type
cloneType(
    c_base src,
    c_base dst,
    c_type object)
{
    sd_serializer serializer, deserializer;
    sd_serializedData data;
    c_char* xmlData;
    c_type result;

    result = NULL;
    serializer = sd_serializerXMLTypeinfoNew(src, FALSE);
    deserializer = sd_serializerXMLTypeinfoNew(dst, FALSE);

    if(serializer && deserializer){
        data = sd_serializerSerialize(serializer, object);

        if(data){
            xmlData = sd_serializerToString(serializer, data);
            sd_serializedDataFree(data);

            if(xmlData){
                data = sd_serializerFromString(deserializer, xmlData);

                if(data){
                    result = c_type(sd_serializerDeserializeValidated(
                            deserializer, data));
                    sd_serializedDataFree(data);
                }
                os_free(xmlData);
            }
        }
        sd_serializerFree(serializer);
        sd_serializerFree(deserializer);
    }
    return result;
}
コード例 #8
0
ファイル: jni_writer.c プロジェクト: xrl/opensplice_dds
static c_bool
jni_writerCopy(
    c_type type, 
    void *data, 
    void *to)
{
    jni_writerCopyArg copyArg;
    sd_serializedData serData;
    
    copyArg = (jni_writerCopyArg)data;
    serData = sd_serializerFromString(copyArg->writer->deserializer, copyArg->xmlData);
    sd_serializerDeserializeIntoValidated(copyArg->writer->deserializer, serData, to);
    sd_serializedDataFree(serData);
    
    return TRUE;
}
コード例 #9
0
ファイル: cmx_writer.c プロジェクト: diorahman/opensplice
void
cmx_writerUnregisterCopy(
    v_entity entity,
    c_voidp args)
{
    v_writer kw;
    v_message message;
    void *to;
    sd_serializer ser;
    sd_serializedData data;
    sd_validationResult valResult;
    struct cmx_writerArg *arg;
    
    arg = (struct cmx_writerArg *)args;
    
    kw = v_writer(entity);
    message = v_topicMessageNew(kw->topic);
    to = C_DISPLACE(message,v_topicDataOffset(kw->topic));
    
    ser = sd_serializerXMLNewTyped(v_topicDataType(kw->topic));
    data = sd_serializerFromString(ser, arg->result);
    sd_serializerDeserializeIntoValidated(ser, data, to);
    valResult = sd_serializerLastValidationResult(ser);
        
    if(valResult != SD_VAL_SUCCESS){
        OS_REPORT_2(OS_ERROR, CM_XML_CONTEXT, 0, 
                    "Unregister of userdata failed.\nReason: %s\nError: %s\n",
                    sd_serializerLastValidationMessage(ser),
                    sd_serializerLastValidationLocation(ser));           
        arg->success = CMX_RESULT_FAILED;
    } else {
        arg->success = CMX_RESULT_OK;
    }
    sd_serializedDataFree(data);
    sd_serializerFree(ser);
    
    /* Note that the last param of v_writerWriteDispose is NULL,
       performance can be improved if the instance is provided. */    
    v_writerUnregister(kw,message,v_timeGet(),NULL);
    c_free(message);
}
コード例 #10
0
c_bool
cmx_writerHistoryCopy(
    c_object sample, 
    c_voidp args)
{
    struct cmx_writerSnapshotArg* arg;
    sd_serializedData data;
    c_char* xml;
    
    arg = (struct cmx_writerSnapshotArg*)args;
    
    if(arg->serializer == NULL){
        arg->serializer = sd_serializerXMLNewTyped(c_getType(sample));
    }
    
    data = sd_serializerSerialize(arg->serializer, sample);
    xml = sd_serializerToString(arg->serializer, data);
    arg->snapshot->samples = c_iterInsert(arg->snapshot->samples, xml);
    sd_serializedDataFree(data);
    
    return TRUE;
}
コード例 #11
0
void
cmx_readerSnapshotNewAction(
    v_entity e, 
    c_voidp args)
{
    v_dataReader reader;
    c_iter instances;
    v_dataReaderInstance instance;
    v_dataReaderSample sample, prev;
    v_query query;
    c_bool release;
    sd_serializer ser;
    sd_serializedData data;
    struct cmx_readerSnapshotArg* arg;
    
    release = FALSE;
    arg = (struct cmx_readerSnapshotArg*)args;
    reader = NULL;
    instances = NULL;
    ser = NULL;
    
    switch(v_object(e)->kind){
    case K_DATAREADER:
        reader = v_dataReader(e);
        arg->success = TRUE;
        arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot)));
        v_observerLock(v_observer(reader));
        
        if(reader->index->objects){
            instances = c_select(reader->index->notEmptyList, 0);
        }
    break;
    case K_QUERY:
    case K_DATAREADERQUERY:
        query = v_query(e);
        reader = v_dataReader(v_querySource(query));
        
        if(reader != NULL){
            release = TRUE;
            arg->success = TRUE;
            arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot)));
            v_observerLock(v_observer(reader));
            
            switch(v_object(query)->kind){
            case K_DATAREADERQUERY:
                if(v_dataReaderQuery(query)->instanceQ){
                    instances = c_select((c_collection)(v_dataReaderQuery(query)->instanceQ), 0);
                }
            break;
            default:
                OS_REPORT_1(OS_ERROR, CM_XML_CONTEXT, 0, 
                    "cmx_readerSnapshotNewAction unknown kind (%d).",
                    v_object(query)->kind);
            break;
            }
        }
    break;
    default:
    break;
    }
    if(arg->success == TRUE){
        arg->snapshot->samples = c_iterNew(NULL);
    }
    if(instances != NULL){
        instance = v_dataReaderInstance(c_iterTakeFirst(instances));
        
        while(instance != NULL){
            sample = c_keep(v_dataReaderInstanceHead(instance));
            
            if(sample != NULL){
                prev = sample->prev;
                sample->prev = NULL;
                
                if(ser == NULL){
                    ser = sd_serializerXMLNewTyped(c_getType(c_object(sample)));
                }
                data = sd_serializerSerialize(ser, c_object(sample));
                arg->snapshot->samples = c_iterInsert(arg->snapshot->samples, 
                                                sd_serializerToString(ser, data));
                sd_serializedDataFree(data);
                sample->prev = prev;
                c_free(sample);
            }
            c_free(instance);
            instance = v_dataReaderInstance(c_iterTakeFirst(instances));
        }
        c_iterFree(instances);
    }
    if(reader != NULL){
        v_observerUnlock(v_observer(reader));
        
        if(release == TRUE){
            c_free(reader);
        }
    }
    if(ser != NULL){
        sd_serializerFree(ser);
    }
}
コード例 #12
0
ファイル: cmx_reader.c プロジェクト: AmitShah/opensplice
void
cmx_readerDataTypeAction(
    v_entity entity,
    c_voidp args)
{
    sd_serializer ser;
    sd_serializedData data;
    c_type type;
    v_dataReader r;
    v_query query;
    v_topic topic;
    struct cmx_readerArg *arg;
    arg = (struct cmx_readerArg *)args;

    type = NULL;

    switch(v_object(entity)->kind){

    case K_DATAREADER:
        r = v_dataReader(entity);
        v_observerLock(v_observer(r));
        topic = v_dataReaderGetTopic(r);
        type = v_topicDataType(topic);
        c_free(topic);
        v_observerUnlock(v_observer(r));
    break;
    case K_DATAREADERQUERY:
        query = v_query(entity);
        r = v_dataReader(v_querySource(query));
        v_observerLock(v_observer(r));
        topic = v_dataReaderGetTopic(r);
        type = v_topicDataType(topic);
        c_free(topic);
        v_observerUnlock(v_observer(r));
        c_free(r);
    break;
    case K_NETWORKREADER:
        OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
                  "Resolving data type of networkReader unsupported.\n");
        assert(FALSE);
    break;
    case K_GROUPQUEUE:
        OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
                  "Resolving data type of groupQueue unsupported.\n");
        assert(FALSE);
    break;
    default:
        OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
                  "Trying to resolve dataType of unknown reader type.\n");
        assert(FALSE);
    break;
    }

    if(type != NULL){
        ser = sd_serializerXMLMetadataNew(c_getBase(type));
        data = sd_serializerSerialize(ser, type);
        arg->result = sd_serializerToString(ser, data);
        sd_serializedDataFree(data);
        sd_serializerFree(ser);
    }
}
コード例 #13
0
ファイル: cmx_readerSnapshot.c プロジェクト: osrf/opensplice
void
cmx_readerSnapshotNewAction(
    v_public p,
    c_voidp args)
{
    v_dataReader reader;
    c_iter instances;
    v_dataReaderInstance instance;
    v_dataReaderSample sample;
    v_query query;
    c_bool release;
    sd_serializer ser;
    sd_serializedData data;
    struct cmx_readerSnapshotArg* arg;

    release = FALSE;
    arg = (struct cmx_readerSnapshotArg*)args;
    reader = NULL;
    instances = NULL;
    ser = NULL;

    switch(v_object(p)->kind){
    case K_DATAREADER:
        reader = v_dataReader(p);
        arg->success = TRUE;
        arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot)));
        v_observerLock(v_observer(reader));

        if(reader->index->objects){
            instances = ospl_c_select(reader->index->notEmptyList, 0);
        }
    break;
    case K_QUERY:
    case K_DATAREADERQUERY:
        query = v_query(p);
        reader = v_dataReader(v_querySource(query));

        if(reader != NULL){
            release = TRUE;
            arg->success = TRUE;
            arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot)));
            v_observerLock(v_observer(reader));

            switch(v_object(query)->kind){
            case K_DATAREADERQUERY:
                if(v_dataReaderQuery(query)->instanceQ){
                    instances = ospl_c_select((c_collection)(v_dataReaderQuery(query)->instanceQ), 0);
                }
            break;
            default:
                OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
                    "cmx_readerSnapshotNewAction unknown kind (%d).",
                    v_object(query)->kind);
            break;
            }
        }
    break;
    default:
    break;
    }
    if(arg->success == TRUE){
        arg->snapshot->samples = c_iterNew(NULL);
    }
    if(instances != NULL){
        v_dataReaderSample sampleShallowCopy = NULL;
        instance = v_dataReaderInstance(c_iterTakeFirst(instances));

        while(instance != NULL){
            v_state ivState = instance->_parent._parent.state & (L_DISPOSED | L_NOWRITERS | L_NEW);

            sample = v_dataReaderInstanceOldest(instance);
            if (sample != NULL) {
                do {
                    v_state state = ivState | ((sample->_parent.sampleState & (L_READ | L_LAZYREAD)) ? L_READ : 0);

                    if (sampleShallowCopy == NULL) {
                        sampleShallowCopy = c_new(c_getType(c_object(sample)));
                    }
                    memcpy(sampleShallowCopy, sample, c_typeSize(c_getType(sampleShallowCopy)));
                    sampleShallowCopy->newer = NULL;
                    sampleShallowCopy->_parent.sampleState &= ~(L_DISPOSED | L_NOWRITERS | L_NEW | L_READ | L_LAZYREAD);
                    sampleShallowCopy->_parent.sampleState |= state;

                    if(ser == NULL){
                        ser = sd_serializerXMLNewTyped(c_getType(c_object(sampleShallowCopy)));
                    }
                    data = sd_serializerSerialize(ser, c_object(sampleShallowCopy));
                    arg->snapshot->samples = c_iterInsert(arg->snapshot->samples, sd_serializerToString(ser, data));
                    sd_serializedDataFree(data);

                    sample = sample->newer;
                } while (sample != NULL);
            }
            c_free(instance);
            instance = v_dataReaderInstance(c_iterTakeFirst(instances));
        }
        c_iterFree(instances);

        if (sampleShallowCopy != NULL) {
            memset(sampleShallowCopy, 0, c_typeSize(c_getType(sampleShallowCopy)));
            c_free(sampleShallowCopy);
        }
    }
    if(reader != NULL){
        v_observerUnlock(v_observer(reader));

        if(release == TRUE){
            c_free(reader);
        }
    }
    if(ser != NULL){
        sd_serializerFree(ser);
    }
}