Beispiel #1
0
gapi_returnCode_t
gapi_subscriber_set_qos (
    gapi_subscriber _this,
    const gapi_subscriberQos *qos)
{
    gapi_returnCode_t result = GAPI_RETCODE_OK;
    u_result uResult;
    _Subscriber subscriber;
    v_subscriberQos subscriberQos;
    gapi_context        context;

    GAPI_CONTEXT_SET(context, _this, GAPI_METHOD_SET_QOS);

    subscriber = gapi_subscriberClaim(_this, &result);

    if ( subscriber && qos ) {
        result = gapi_subscriberQosIsConsistent(qos, &context);
    } else {
        result = GAPI_RETCODE_BAD_PARAMETER;
    }

    if ((result == GAPI_RETCODE_OK ) && (_EntityEnabled(subscriber))) {
        gapi_subscriberQos * existing_qos = gapi_subscriberQos__alloc();

        result = gapi_subscriberQosCheckMutability(qos,
                                                   _SubscriberGetQos(subscriber,
                                                                     existing_qos),
                                                   &context);
        gapi_free(existing_qos);
    }



    if ( result == GAPI_RETCODE_OK ) {
        subscriberQos = u_subscriberQosNew(NULL);
        if (subscriberQos) {
            if ( copySubscriberQosIn(qos, subscriberQos) ) {
                uResult = u_entitySetQoS(_EntityUEntity(subscriber),
                                         (v_qos)(subscriberQos) );
                result = kernelResultToApiResult(uResult);
            } else {
                result = GAPI_RETCODE_OUT_OF_RESOURCES;
            }
            u_subscriberQosFree(subscriberQos);
        } else {
            result = GAPI_RETCODE_OUT_OF_RESOURCES;
        }
    }

    _EntityRelease(subscriber);

    return result;
}
Beispiel #2
0
static u_result create_builtin_readers (struct builtin_datareader_set *drset, u_participant p)
{
  v_subscriberQos sQos = NULL;
  v_readerQos rdQos = NULL;
  v_gid gid;
  c_value ps[1];

  drset->subscriber = NULL;
  drset->participant_dr = NULL;
  drset->subscription_dr = NULL;
  drset->publication_dr = NULL;
  
  if ((sQos = u_subscriberQosNew (NULL)) == NULL)
    goto fail;
  sQos->presentation.access_scope = V_PRESENTATION_TOPIC;
  if ((sQos->partition = os_strdup ("__BUILT-IN PARTITION__")) == NULL)
    goto fail;

  if ((rdQos = u_readerQosNew (NULL)) == NULL)
    goto fail;
  rdQos->durability.kind = V_DURABILITY_TRANSIENT;
  rdQos->reliability.kind = V_RELIABILITY_RELIABLE;
  rdQos->history.kind = V_HISTORY_KEEPLAST;
  rdQos->history.depth = 1;

  if ((drset->subscriber = u_subscriberNew (p, "DDSI2BuiltinSubscriber", sQos, TRUE)) == NULL)
    goto fail;
  gid = u_entityGid ((u_entity) drset->subscriber);
  ps[0].kind = V_ULONG;
  ps[0].is.ULong = gid.systemId;
  in_printf (IN_LEVEL_INFO, "create_builtin_readers: systemId = %lx\n", (unsigned long) ps[0].is.ULong);
  
  if ((drset->participant_dr = u_subscriberCreateDataReader (drset->subscriber, "DCPSParticipantReader", "select * from DCPSParticipant where key.systemId = %0", ps, rdQos, TRUE)) == NULL)
    goto fail;
  if ((drset->subscription_dr = u_subscriberCreateDataReader (drset->subscriber, "DCPSSubscriptionReader", "select * from DCPSSubscription where key.systemId = %0", ps, rdQos, TRUE)) == NULL)
    goto fail;
  if ((drset->publication_dr = u_subscriberCreateDataReader (drset->subscriber, "DCPSPublicationReader", "select * from DCPSPublication where key.systemId = %0", ps, rdQos, TRUE)) == NULL)
    goto fail;
  u_readerQosFree (rdQos);
  u_subscriberQosFree (sQos);
  return U_RESULT_OK;

 fail:
  destroy_builtin_readers (drset);
  if (rdQos)
    u_readerQosFree (rdQos);
  if (sQos)
    u_subscriberQosFree (sQos);
  return U_RESULT_INTERNAL_ERROR;
}
Beispiel #3
0
/**************************************************************
 * Protected functions
 **************************************************************/
v_qos
u_qosNew(
    v_qos tmpl)
{
    v_qos q;
    
    q = NULL;
    if (tmpl != NULL) {
        switch (tmpl->kind) {
        case V_PARTITION_QOS:
            q = (v_qos)u_partitionQosNew((v_partitionQos)tmpl);
        break;
        case V_PARTICIPANT_QOS:
            q = (v_qos)u_participantQosNew((v_participantQos)tmpl);
        break;
        case V_TOPIC_QOS:
            q = (v_qos)u_topicQosNew((v_topicQos)tmpl);
        break;
        case V_WRITER_QOS:
            q = (v_qos)u_writerQosNew((v_writerQos)tmpl);
        break;
        case V_READER_QOS:
            q = (v_qos)u_readerQosNew((v_readerQos)tmpl);
        break;
        case V_PUBLISHER_QOS:
            q = (v_qos)u_publisherQosNew((v_publisherQos)tmpl);
        break;
        case V_SUBSCRIBER_QOS:
            q = (v_qos)u_subscriberQosNew((v_subscriberQos)tmpl);
        break;
        case V_DATAVIEW_QOS:
            q = (v_qos)u_dataViewQosNew((v_dataViewQos)tmpl);
        break;
        default:
            OS_REPORT_1(OS_ERROR, "u_qosNew", 0, "unsupported qos %d", tmpl->kind);
        break;
        }
    }

    return q;
}
Beispiel #4
0
int
main(
    int argc,
    char* argv[])
{
    int result = 0;
    v_participantQos participantQos;
    u_result uresult;
    os_boolean success;
    v_subscriberQos subscriberQos;
    c_time resolution;
    c_base base;
    v_kernel kernel;

    /* Necessary to initialize the user layer. Do this just once per process.*/
    mlv_init ();
    uresult = u_userInitialise();
    mlv_setforreal (1);

    if(uresult == U_RESULT_OK){
        /* Allocate default participant qos*/
        participantQos = u_participantQosNew(NULL);

        {
          os_mutexAttr mattr;
          os_mutexAttrInit (&mattr);
          mattr.scopeAttr = OS_SCOPE_PRIVATE;
          os_mutexInit (&gluelock, &mattr);
        }

        if(participantQos){
            if(argc > 1){
                SERVICE_NAME = argv[1];
            }
            if(argc > 2){
                SERVICE_URI = argv[2];
            }
            /*create participant*/
            participant = u_participant(u_serviceNew(
                                SERVICE_URI, 0, SERVICE_NAME,
                                NULL,
                                U_SERVICE_NETWORKING,
                                (v_qos)participantQos));

            if(participant){
                struct cfgst *cfgst;
                ddsi2_participant_gid = u_entityGid (u_entity (participant));

                /*Notify kernel that I am initializing. */
                u_serviceChangeState(u_service(participant),STATE_INITIALISING);

                /*Start monitoring the splicedaemon state. I need to terminate if he says so*/
                u_serviceWatchSpliceDaemon(
                        u_service(participant),
                        in_discoveryWatchSpliced,
                        &terminate);

                if ((cfgst = config_init (participant, SERVICE_NAME)) != NULL)
                {
                  unsigned rtps_flags = 0;
                  struct nn_servicelease *servicelease;

                  open_tracing_file ();
                  /* Dependencies between default values is not
                     handled automatically by the config processing
                     (yet) */
                  if (config.many_sockets_mode)
                  {
                    if (config.max_participants == 0)
                      config.max_participants = 100;
                  }
                  if (NN_STRICT_P)
                  {
                    /* Should not be sending invalid messages when strict */
                    config.respond_to_rti_init_zero_ack_with_invalid_heartbeat = 0;
                    config.acknack_numbits_emptyset = 1;
                  }
                  config_print_and_free_cfgst (cfgst);

                  servicelease = nn_servicelease_new (participant);
                  nn_servicelease_start_renewing (servicelease);

                  myNetworkId = getNetworkId ();

                  u_entityAction(u_entity(participant), resolveKernelService, NULL);
                  base = c_getBase(service);
                  kernel = v_object(service)->kernel;
                  rtps_init (base, kernel, config.domainId, config.participantIndex,
                             rtps_flags, config.networkAddressString, config.peers);

                  /* Initialize entity administration. */
                  success = in_entityAdminInit(participant);

                  if(success){
                    /*Create subscriber to receive client writers' messages.*/
                    subscriberQos = u_subscriberQosNew(NULL);
                    os_free(subscriberQos->partition);
                    subscriberQos->partition = NULL;

                    clientSubscriber = u_subscriberNew(
                            participant,
                            "clientSubscriber",
                            subscriberQos,
                            TRUE);

                    if(clientSubscriber){
                      /*Create networkReader to be able to receive client writers' messages.*/
                      clientReader = u_networkReaderNew(
                              clientSubscriber,
                              "clientReader",
                              NULL,
                              TRUE);

                      if(clientReader){
                        resolution.seconds = 0;
                        resolution.nanoseconds = 10 * 1000 * 1000; /*10 ms*/

                        /*Create network queue*/
                        uresult = u_networkReaderCreateQueue(
                                clientReader,
                                1000, 0, FALSE, FALSE,
                                resolution,
                                TRUE, &queueId,
                                "DDSi");

                        if(uresult == U_RESULT_OK){
                          struct builtin_datareader_set drset;
                          u_entityAction(u_entity(clientReader), resolveKernelReader, NULL);

                          uresult = create_builtin_readers (&drset, participant);
                          if (uresult == U_RESULT_OK)
                          {
                            u_serviceChangeState(u_service(participant),STATE_OPERATIONAL);
                            uresult = attachAndMonitor(participant, &drset);

                            if((uresult != U_RESULT_OK) &&
                               (uresult != U_RESULT_DETACHING))
                            {
                              nn_log (LC_ERROR, "Abnormal termination...\n");
                              result = -1;
                            } else {
                              nn_log (LC_INFO, "Deleting entities...\n");
                            }
                            destroy_builtin_readers (&drset);
                          } else {
                            nn_log (LC_FATAL, "Could not create subscription + readers for builtin topics.\n");
                            result = -1;
                          }
                          terminate = TRUE;
                          v_networkReaderTrigger(vclientReader, queueId);
                          os_threadWaitExit(clientWriterThread, NULL);
                        } else {
                          nn_log (LC_FATAL, "Could not create networkQueue.\n");
                          result = -1;
                        }
                        /*Clean up networkReader*/
                        os_mutexLock (&gluelock);
                        u_networkReaderFree(clientReader);
                        clientReader = NULL;
                        vclientReader = NULL;
                        os_mutexUnlock (&gluelock);
                      } else {
                        nn_log (LC_FATAL, "Could not create networkReader.\n");
                        result = -1;
                      }
                      /*Clean up subscriber*/
                      u_subscriberFree(clientSubscriber);
                    } else {
                      nn_log (LC_FATAL, "Could not create subscriber.\n");
                      result = -1;
                    }

                    /*Clean up entity administration*/
                    in_entityAdminDestroy();
                  } else {
                    nn_log (LC_FATAL, "Could not initialize entity adminstration.\n");
                    result = -1;
                  }

                  /* RTPS layer now defines types, cleanup before detaching */
                  rtps_term();

                  /*Notify kernel that I've terminated*/
                  u_serviceChangeState(u_service(participant),STATE_TERMINATED);
                  nn_servicelease_free (servicelease);
                  /*Delete participant*/
                  uresult = u_serviceFree(u_service(participant));

                  if(uresult != U_RESULT_OK){
                    nn_log (LC_FATAL, "Deletion of participant failed.\n");
                    result = -1;
                  }
                } else {
                    nn_log (LC_FATAL, "Initialization of configuration failed.\n");
                    result = -1;
                }
            } else {
                nn_log (LC_FATAL, "Could not create participant.\n");
                result = -1;
            }
            u_participantQosFree (participantQos);
        } else {
            nn_log (LC_FATAL, "Could not allocate participantQos.\n");
            result = -1;
        }
        os_mutexDestroy (&gluelock);
        /* Detach user layer */
        mlv_setforreal (0);
        uresult = u_userDetach();
        mlv_fini ();

        if(uresult != U_RESULT_OK){
            nn_log (LC_FATAL, "Detachment of user layer failed.\n");
            result = -1;
        }
    } else {
        nn_log (LC_FATAL, "Initialization of user layer failed.\n");
        result = -1;
    }
    nn_log (LC_INFO, "Finis.\n");

    /* Must be really late, or nn_log becomes unhappy -- but it should
       be before os_osExit (which appears to be called from
       u_userExit(), which is not called by u_userDetach but by an
       exit handler, it appears.) */
    config_fini ();
    return result;
}
Beispiel #5
0
_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;
}