v_subscriber v_participantGetBuiltinSubscriber( v_participant p) { v_subscriberQos sQos; v_readerQos rQos; v_kernel kernel; c_bool create_builtin_readers = FALSE; assert(p != NULL); assert(C_TYPECHECK(p, v_participant)); c_mutexLock(&p->builtinLock); if (p->builtinSubscriber == NULL) { kernel = v_objectKernel(p); sQos = v_subscriberQosNew(kernel, NULL); sQos->presentation.access_scope = V_PRESENTATION_TOPIC; c_free(sQos->partition); sQos->partition = c_stringNew(c_getBase(c_object(kernel)), V_BUILTIN_PARTITION); sQos->entityFactory.autoenable_created_entities = TRUE; p->builtinSubscriber = v_subscriberNew(p, V_BUILTINSUBSCRIBER_NAME, sQos, TRUE); v_subscriberQosFree(sQos); create_builtin_readers = TRUE; c_mutexUnlock(&p->builtinLock); assert(p->builtinSubscriber != NULL); rQos = v_readerQosNew(kernel, NULL); rQos->durability.kind = V_DURABILITY_TRANSIENT; rQos->reliability.kind = V_RELIABILITY_RELIABLE; rQos->history.kind = V_HISTORY_KEEPLAST; rQos->history.depth = 1; #define _CREATE_READER_(topicName) {\ q_expr expr; \ v_dataReader dr; \ expr = q_parse("select * from " topicName);\ dr = v_dataReaderNew(p->builtinSubscriber, topicName "Reader", \ expr, NULL, rQos, TRUE);\ c_free(dr); \ q_dispose(expr); \ } _CREATE_READER_(V_PARTICIPANTINFO_NAME) _CREATE_READER_(V_TOPICINFO_NAME) _CREATE_READER_(V_PUBLICATIONINFO_NAME) _CREATE_READER_(V_SUBSCRIPTIONINFO_NAME) #undef _CREATE_READER_ v_readerQosFree(rQos); } else { c_mutexUnlock(&p->builtinLock); } return c_keep(p->builtinSubscriber); }
v_subscriberQos v_subscriberGetQos( v_subscriber s) { v_subscriberQos qos; assert(s != NULL); c_lockRead(&s->lock); qos = v_subscriberQosNew(v_objectKernel(s), s->qos); c_lockUnlock(&s->lock); return qos; }
v_subscriber v_subscriberNew( v_participant p, const c_char *name, v_subscriberQos qos, c_bool enable) { v_kernel kernel; v_subscriber s; v_subscriberQos q; v_entity found; v_accessMode access; kernel = v_objectKernel(p); /* ES, dds1576: If a partition policy was provided then we need to verify * if the partition policy does not contain any partition expressions for * which read access is not allowed. * If read access is not allowed for one of the partitions listed in the * partition policy of the qos, then the subscriber will not be created at * all. */ if(qos && qos->partition) { access = v_kernelPartitionAccessMode(kernel, qos->partition); } else { access = V_ACCESS_MODE_READ_WRITE;/* default */ } if(access == V_ACCESS_MODE_READ_WRITE || access == V_ACCESS_MODE_READ) { q = v_subscriberQosNew(kernel,qos); if (q != NULL) { s = v_subscriber(v_objectNew(kernel,K_SUBSCRIBER)); v_observerInit(v_observer(s),name, NULL, enable); s->qos = q; c_mutexInit(&s->sharesMutex, SHARED_MUTEX); if (q->share.enable) { v_lockShares(kernel); found = v_addShareUnsafe(kernel,v_entity(s)); if (found != v_entity(s)) { /* Make sure to set the partition list to NULL, because * v_publicFree will cause a crash in the v_subscriberDeinit * otherwise. */ s->partitions = NULL; /*v_publicFree to free reference held by the handle server.*/ v_publicFree(v_public(s)); /*Now free the local reference as well.*/ c_free(s); pa_increment(&(v_subscriber(found)->shareCount)); v_unlockShares(kernel); return c_keep(found); } s->shares = c_tableNew(v_kernelType(kernel,K_READER), "qos.share.name"); } else { s->shares = NULL; } s->shareCount = 1; s->partitions = v_partitionAdminNew(kernel); s->readers = c_setNew(v_kernelType(kernel,K_READER)); if (q->share.enable) { s->participant = kernel->builtin->participant; } else { s->participant = p; } c_lockInit(&s->lock,SHARED_LOCK); v_participantAdd(v_participant(s->participant),v_entity(s)); if (q->share.enable) { v_unlockShares(kernel); } if (enable) { v_subscriberEnable(s); } } else { OS_REPORT(OS_ERROR, "v_subscriberNew", 0, "Subscriber not created: inconsistent qos"); s = NULL; } } else { OS_REPORT(OS_ERROR, "v_subscriberNew", 0, "Subscriber not created: Access rights for one of the partitions listed in the partition list was not sufficient (i.e. read or readwrite)."); s = NULL; } return s; }