コード例 #1
0
ファイル: gapi_builtin.c プロジェクト: xrl/opensplice
_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;
}
コード例 #2
0
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;
}