_DataReader _DataReaderNew ( const _TopicDescription topicDescription, const _TypeSupport typesupport, const gapi_dataReaderQos *qos, const struct gapi_dataReaderListener *a_listener, const gapi_statusMask mask, const _Subscriber subscriber) { _DataReader _this; v_readerQos readerQos; u_dataReader uReader; gapi_string topicName; char dataReaderId[256]; c_bool noError = TRUE; readerQos = u_readerQosNew(NULL); if ( readerQos != NULL ) { if ( gapi_kernelReaderQosCopyIn(qos, readerQos) ) { q_expr expr; c_value *params; topicName = _TopicDescriptionGetName (topicDescription); if (topicName) { snprintf (dataReaderId, sizeof(dataReaderId), "%sReader", topicName); gapi_free (topicName); } else { snprintf (dataReaderId, sizeof(dataReaderId), "dataReader"); } expr = _TopicDescriptionGetExpr(topicDescription); if (_ObjectGetKind(_Object(topicDescription)) == OBJECT_KIND_CONTENTFILTEREDTOPIC) { params = _ContentFilteredTopicParameters( (_ContentFilteredTopic)topicDescription); } else { params = NULL; } uReader = u_dataReaderNew(_SubscriberUsubscriber(subscriber), dataReaderId, expr, params, readerQos, FALSE); q_dispose(expr); os_free(params); noError = (uReader != NULL); if (noError) { _this = _DataReaderAlloc(); if ( _this != NULL ) { noError = _DataReaderInit(_this, subscriber, topicDescription, typesupport, a_listener, mask, uReader); if (!noError) { _EntityDispose(_Entity(_this)); } } if (!noError) { u_dataReaderFree(uReader); } } } else { noError = FALSE; } u_readerQosFree(readerQos); } else { noError = FALSE; } if (!noError) { _this = NULL; } return _this; }
_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; }
gapi_dataReader gapi_subscriber_create_datareader ( gapi_subscriber _this, const gapi_topicDescription a_topic, const gapi_dataReaderQos *qos, const struct gapi_dataReaderListener *a_listener, const gapi_statusMask mask) { _Subscriber subscriber; _DataReader datareader = NULL; gapi_dataReader result = NULL; _TopicDescription topicDescription = NULL; gapi_dataReaderQos *readerQos; gapi_context context; gapi_topicQos* topicQos; GAPI_CONTEXT_SET(context, _this, GAPI_METHOD_CREATE_DATAREADER); subscriber = gapi_subscriberClaim(_this, NULL); if ( subscriber ) { if ( !subscriber->builtin ) { topicDescription = _TopicDescriptionFromHandle(a_topic); } } if ( topicDescription ) { if ( qos == GAPI_DATAREADER_QOS_DEFAULT ) { readerQos = &subscriber->_defDataReaderQos; } else if ( qos == GAPI_DATAREADER_QOS_USE_TOPIC_QOS ) { _Topic topic = NULL; switch(_ObjectGetKind(_Object(topicDescription))) { case OBJECT_KIND_TOPIC: topic = _Topic(topicDescription); break; case OBJECT_KIND_CONTENTFILTEREDTOPIC: topic = _ContentFilteredTopicGetRelatedTopic(_ContentFilteredTopic(topicDescription)); break; default: topic = NULL; break; } if ( topic ) { topicQos = gapi_topicQos__alloc(); readerQos = gapi_dataReaderQos__alloc(); gapi_dataReaderQosCopy(&subscriber->_defDataReaderQos, readerQos); _TopicGetQos(topic, topicQos); gapi_mergeTopicQosWithDataReaderQos(topicQos,readerQos); gapi_free(topicQos); } else { readerQos = (gapi_dataReaderQos *)qos; } } else { readerQos = (gapi_dataReaderQos *)qos; } if ( gapi_dataReaderQosIsConsistent(readerQos, &context) == GAPI_RETCODE_OK ) { gapi_char *typeName; gapi_char *topicName; _DomainParticipant participant; _TypeSupport typeSupport; /* find topic with the participant for consistency */ typeName = _TopicDescriptionGetTypeName(topicDescription); topicName = _TopicDescriptionGetName(topicDescription); participant = _EntityParticipant(_Entity(subscriber)); /* find type support for the data type to find * data reader create function. */ typeSupport = _DomainParticipantFindType(participant, typeName); if(typeSupport) { /* if create function is NULL, take default from data reader */ datareader = _DataReaderNew(topicDescription, typeSupport, readerQos, a_listener, mask, subscriber); if ( datareader ) { _ENTITY_REGISTER_OBJECT(_Entity(subscriber), (_Object)datareader); } }else{ OS_REPORT_1(OS_WARNING, "gapi_subscriber_create_datareader", 0, "TypeSupport %s not found !", typeName); } gapi_free(typeName); gapi_free(topicName); } if (qos == GAPI_DATAREADER_QOS_USE_TOPIC_QOS) { gapi_free(readerQos); } } _EntityRelease(subscriber); if ( datareader ) { gapi_object statusHandle; statusHandle = _EntityHandle(_Entity(datareader)->status); result = (gapi_dataReader)_EntityRelease(datareader); } return result; }