_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; }
_Publisher _PublisherNew ( u_participant uParticipant, const gapi_publisherQos *qos, const struct gapi_publisherListener *a_listener, const gapi_statusMask mask, const _DomainParticipant participant) { v_publisherQos publisherQos; _Publisher newPublisher; assert(uParticipant); assert(qos); assert(participant); newPublisher = _PublisherAlloc(); if ( newPublisher ) { _EntityInit (_Entity(newPublisher), _Entity(participant)); gapi_dataWriterQosCopy (&gapi_dataWriterQosDefault, &newPublisher->_defDataWriterQos); if ( a_listener ) { newPublisher->_Listener = *a_listener; } } if ( newPublisher ) { publisherQos = u_publisherQosNew(NULL); if ( publisherQos ) { if ( !copyPublisherQosIn(qos, publisherQos)) { _EntityDispose(_Entity(newPublisher)); newPublisher = NULL; } } else { _EntityDispose(_Entity(newPublisher)); newPublisher = NULL; } } if ( newPublisher ) { u_publisher uPublisher; uPublisher = u_publisherNew (uParticipant, "publisher", publisherQos, FALSE); u_publisherQosFree(publisherQos); if ( uPublisher ) { U_PUBLISHER_SET(newPublisher, uPublisher); } else { _EntityDispose(_Entity(newPublisher)); newPublisher = NULL; } } if ( newPublisher ) { _Status status; status = _StatusNew(_Entity(newPublisher), STATUS_KIND_PUBLISHER, (struct gapi_listener *)a_listener, mask); if (status) { _EntityStatus(newPublisher) = status; if ( qos->partition.name._length == 0 ) { /* * behaviour of the kernel in case of an empty sequence * is that it is related to none of the partitions, * while DCPS expects it to be conected to all partitions. * Therefore this has to be done seperately. */ u_publisherPublish (U_PUBLISHER_GET(newPublisher), ""); } } else { u_publisherFree(U_PUBLISHER_GET(newPublisher)); _EntityDispose(_Entity(newPublisher)); newPublisher = NULL; } } return newPublisher; }
c_bool _DataReaderInit ( _DataReader _this, const _Subscriber subscriber, const _TopicDescription topicDescription, const _TypeSupport typesupport, const struct gapi_dataReaderListener *a_listener, const gapi_statusMask mask, const u_dataReader uReader) { c_bool noError; noError = ((_this != NULL) && (topicDescription != NULL) && (typesupport != NULL) && (uReader != NULL)); if (noError) { _EntityInit(_Entity(_this), _Entity(subscriber)); U_DATAREADER_SET(_this, uReader); u_entityAction(u_entity(uReader),getCopyInfo,_this); _this->topicDescription = topicDescription; if ( a_listener ) { _this->_Listener = *a_listener; } else { memset(&_this->_Listener, 0, sizeof(_this->_Listener)); } _this->readerCopy = _TypeSupportGetReaderCopy(typesupport); if (_this->readerCopy == NULL) { _this->readerCopy = _DataReaderCopy; } _this->copy_in = _TypeSupportCopyIn (typesupport); _this->copy_out = _TypeSupportCopyOut (typesupport); _this->copy_cache = _TypeSupportCopyCache (typesupport); _this->allocSize = _TypeSupportTopicAllocSize(typesupport); _this->allocBuffer = _TypeSupportTopicAllocBuffer(typesupport); _this->reader_mask.sampleStateMask = (c_long)0; _this->reader_mask.viewStateMask = (c_long)0; _this->reader_mask.instanceStateMask = (c_long)0; } if (noError) { _Status status; status = _StatusNew(_Entity(_this), STATUS_KIND_DATAREADER, (struct gapi_listener *)a_listener, mask); _EntityStatus(_this) = status; if (!status) { noError = FALSE; } } if (noError) { _TopicDescriptionIncUse(topicDescription); } return noError; }
_Subscriber _BuiltinSubscriberNew ( u_participant uParticipant, _DomainParticipantFactory factory, _DomainParticipant participant) { u_subscriber s; _Status status; _Subscriber newSubscriber = _SubscriberAlloc(); gapi_handle handle; _TypeSupport typeSupport; gapi_dataReaderQos rQos; long i; s = u_participantGetBuiltinSubscriber(uParticipant); if (s) { newSubscriber = _SubscriberAlloc(); if (newSubscriber != NULL) { _EntityInit(_Entity(newSubscriber), _Entity(participant)); U_SUBSCRIBER_SET(newSubscriber, s); status = _StatusNew(_Entity(newSubscriber), STATUS_KIND_SUBSCRIBER, NULL, 0); if (status) { for ( i = 0; i < MAX_BUILTIN_TOPIC; i++ ) { _DataReader reader = NULL; _Topic topic = NULL; typeSupport = _DomainParticipantFindTypeSupport(participant, _BuiltinTopicTypeName(i)); if (typeSupport) { c_iter uTopicList; u_topic uTopic; uTopicList = u_participantFindTopic(uParticipant, _BuiltinTopicName(i), C_TIME_ZERO); uTopic = c_iterTakeFirst(uTopicList); if (uTopic) { topic = _TopicFromKernelTopic(uTopic, _BuiltinTopicName(i), _BuiltinTopicTypeName(i), typeSupport, participant, NULL); while (uTopic) { uTopic = c_iterTakeFirst(uTopicList); /* multiple instances should not occure but * just in case this loop frees all references. */ assert(uTopic == NULL); u_entityFree(u_entity(uTopic)); } } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "failed to resolve User layer Topic " "'%s' for Participant 0x%x", _BuiltinTopicName(i), participant); } } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "Builtin TypeSupport for type '%s' is not " "yet registered for Participant 0x%x", _BuiltinTopicTypeName(i), participant); } if (topic) { initBuiltinDataReaderQos(&rQos); reader = _DataReaderNew(_TopicDescription(topic), typeSupport, &rQos, NULL, 0, newSubscriber); _EntityRelease(topic); } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "failed to create Builtin Topic '%s' " "for Participant 0x%x", _BuiltinTopicName(i), participant); } if ( reader ) { _ENTITY_REGISTER_OBJECT(_Entity(newSubscriber), (_Object)reader); handle = _EntityRelease(reader); gapi_entity_enable(handle); } } newSubscriber->builtin = TRUE; _EntityStatus(newSubscriber) = status; } else { _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } } return newSubscriber; }
_Subscriber _SubscriberNew ( u_participant uParticipant, const gapi_subscriberQos *qos, const struct gapi_subscriberListener *a_listener, const gapi_statusMask mask, const _DomainParticipant participant) { _Subscriber newSubscriber; v_subscriberQos subscriberQos; gapi_long len; assert(uParticipant); assert(qos); assert(participant); newSubscriber = _SubscriberAlloc(); if ( newSubscriber != NULL ) { _EntityInit(_Entity(newSubscriber), _Entity(participant)); gapi_dataReaderQosCopy (&gapi_dataReaderQosDefault, &newSubscriber->_defDataReaderQos); if ( a_listener ) { newSubscriber->_Listener = *a_listener; } } if (newSubscriber != NULL ) { subscriberQos = u_subscriberQosNew(NULL); if ( subscriberQos != NULL ) { if ( !copySubscriberQosIn(qos, subscriberQos) ) { _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } else { _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } if ( newSubscriber != NULL) { u_subscriber uSubscriber; uSubscriber = u_subscriberNew(uParticipant, "subscriber", subscriberQos, FALSE); u_subscriberQosFree(subscriberQos); if ( uSubscriber != NULL ) { U_SUBSCRIBER_SET(newSubscriber, uSubscriber); } else { _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } if ( newSubscriber != NULL) { _Status status; status = _StatusNew(_Entity(newSubscriber), STATUS_KIND_SUBSCRIBER, (struct gapi_listener *)a_listener, mask); if (status) { _EntityStatus(newSubscriber) = status; len = (gapi_long)qos->partition.name._length; if ( qos->partition.name._length == 0UL ) { /* * behaviour of the kernel in case of an empty sequence * is that it is related to none of the partitions, * while DCPS expects it to be conected to all partitions. * Therefore this has to be done seperately. */ u_subscriberSubscribe (U_SUBSCRIBER_GET(newSubscriber), ""); } newSubscriber->builtin = FALSE; } else { u_subscriberFree(U_SUBSCRIBER_GET(newSubscriber)); _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } return newSubscriber; }