/************************************************************** * constructor/destructor **************************************************************/ u_writerQos u_writerQosNew( u_writerQos tmpl) { u_result result; u_writerQos q; q = os_malloc(sizeof(C_STRUCT(v_writerQos))); if (q != NULL) { if (tmpl != NULL) { *q = *tmpl; q->userData.size = tmpl->userData.size; if (tmpl->userData.size > 0) { q->userData.value = os_malloc(tmpl->userData.size); memcpy(q->userData.value,tmpl->userData.value,tmpl->userData.size); } else { q->userData.value = NULL; } } else { result = u_writerQosInit(q); if (result != U_RESULT_OK) { u_writerQosFree(q); q = NULL; } } } return q; }
/* ReturnCode_t * set_qos( * in DataWriterQos qos); * * Function will operate independent of the enable flag */ gapi_returnCode_t gapi_dataWriter_set_qos ( gapi_dataWriter _this, const gapi_dataWriterQos *qos) { gapi_returnCode_t result = GAPI_RETCODE_OK; u_result uResult; _DataWriter dataWriter; v_writerQos dataWriterQos; gapi_context context; GAPI_CONTEXT_SET(context, _this, GAPI_METHOD_SET_QOS); dataWriter = gapi_dataWriterClaim(_this, &result); if ( dataWriter != NULL ) { result = gapi_dataWriterQosIsConsistent(qos, &context); } else { result = GAPI_RETCODE_BAD_PARAMETER; } if (( result == GAPI_RETCODE_OK ) && (_EntityEnabled(dataWriter))) { gapi_dataWriterQos *existing_qos = gapi_dataWriterQos__alloc(); result = gapi_dataWriterQosCheckMutability(qos, _DataWriterGetQos(dataWriter, existing_qos), &context); gapi_free(existing_qos); } if ( result == GAPI_RETCODE_OK ) { dataWriterQos = u_writerQosNew(NULL); if (dataWriterQos) { if ( copyWriterQosIn(qos, dataWriterQos) ) { uResult = u_entitySetQoS(_EntityUEntity(dataWriter), (v_qos)(dataWriterQos) ); result = kernelResultToApiResult(uResult); u_writerQosFree(dataWriterQos); } else { result = GAPI_RETCODE_OUT_OF_RESOURCES; } } else { result = GAPI_RETCODE_OUT_OF_RESOURCES; } } _EntityRelease(dataWriter); return result; }
gapi_dataWriterQos * _DataWriterGetQos ( _DataWriter dataWriter, gapi_dataWriterQos * qos) { v_writerQos dataWriterQos; u_writer uWriter; assert(dataWriter); uWriter = U_WRITER_GET(dataWriter); if ( u_entityQoS(u_entity(uWriter), (v_qos*)&dataWriterQos) == U_RESULT_OK ) { copyWriterQosOut(dataWriterQos, qos); u_writerQosFree(dataWriterQos); } return qos; }
_DataWriter _DataWriterNew ( const _Topic topic, const _TypeSupport typesupport, const gapi_dataWriterQos *qos, const struct gapi_dataWriterListener *a_listener, const gapi_statusMask mask, const _Publisher publisher) { _DataWriter newDataWriter; v_writerQos writerQos; u_writer uWriter; _TypeSupport typeSupport = (_TypeSupport)typesupport; char dataWriterId[256]; gapi_string topicName; newDataWriter = _DataWriterAlloc(); if ( newDataWriter != NULL ) { _EntityInit(_Entity(newDataWriter), _Entity(publisher)); newDataWriter->topic = topic; if ( a_listener ) { newDataWriter->listener = *a_listener; } writerQos = u_writerQosNew(NULL); if ( (writerQos != NULL) ) { if ( !copyWriterQosIn(qos, writerQos) ) { u_writerQosFree (writerQos); _EntityDispose(_Entity(newDataWriter)); newDataWriter = NULL; } } else { _EntityDispose(_Entity(newDataWriter)); newDataWriter = NULL; } } if ( newDataWriter != NULL ) { u_writerCopy copy_action; newDataWriter->copy_in = _TypeSupportCopyIn(typeSupport); newDataWriter->copy_out = _TypeSupportCopyOut(typeSupport); newDataWriter->copy_cache = _TypeSupportCopyCache(typeSupport); copy_action = _TypeSupportGetWriterCopy(typeSupport); if (!copy_action) { copy_action = _DataWriterCopy; } topicName = _TopicDescriptionGetName (_TopicDescription(topic)); if (topicName) { snprintf (dataWriterId, sizeof (dataWriterId), "%sWriter", topicName); gapi_free (topicName); } else { snprintf (dataWriterId, sizeof (dataWriterId), "dataWriter"); } uWriter = u_writerNew(_PublisherUpublisher(publisher), dataWriterId, _TopicUtopic(topic), copy_action, writerQos, FALSE); if ( uWriter != NULL ) { U_WRITER_SET(newDataWriter, uWriter); } else { _EntityDispose(_Entity(newDataWriter)); newDataWriter = NULL; } u_writerQosFree(writerQos); } if ( newDataWriter != NULL ) { _Status status; status = _StatusNew(_Entity(newDataWriter), STATUS_KIND_DATAWRITER, (struct gapi_listener *)a_listener, mask); _EntityStatus(newDataWriter) = status; if (status) { _TopicDescriptionIncUse(_TopicDescription(topic)); } else { u_writerFree(uWriter); _EntityDispose(_Entity(newDataWriter)); newDataWriter = NULL; } } return newDataWriter; }