/************************************************************** * constructor/destructor **************************************************************/ void v_readerInit( v_reader r, const c_char *name, v_subscriber s, v_readerQos qos, v_statistics rs, c_bool enable) { v_kernel kernel; assert(r != NULL); assert(s != NULL); assert(C_TYPECHECK(r,v_reader)); assert(C_TYPECHECK(s,v_subscriber)); assert(C_TYPECHECK(qos, v_readerQos)); /* We demand the qos to be allocated in the kernel, by v_readerQosNew(). * This way we are sure that the qos is consistent! */ kernel = v_objectKernel(r); v_collectionInit(v_collection(r),name,rs,enable); r->subscriber = s; r->qos = c_keep(qos); r->subQos = c_keep(s->qos); /* reference is readonly */ r->entrySet.entries = c_setNew(v_kernelType(kernel,K_ENTRY)); c_mutexInit(&r->entrySet.mutex, SHARED_MUTEX); r->historicalDataRequest = NULL; r->historicalDataComplete = FALSE; c_condInit(&r->historicalDataCondition, &(v_observer(r)->mutex), SHARED_COND); }
void v_participantInit( v_participant p, const c_char *name, v_participantQos qos, v_statistics s, c_bool enable) { v_kernel kernel; c_base base; v_message builtinMsg; c_type writerProxyType; assert(C_TYPECHECK(p,v_participant)); assert(C_TYPECHECK(qos, v_participantQos)); kernel = v_objectKernel(p); base = c_getBase(p); v_observerInit(v_observer(p),name,s,enable); p->entities = c_setNew(c_resolve(base,"kernelModule::v_entity")); p->qos = c_keep(qos); /* Currently default LIVELINESS policy is used: kind=AUTOMATIC, * duration=INFINITE This setting implies no lease registration. */ p->lease = NULL; p->leaseManager = v_leaseManagerNew(kernel); p->resendQuit = FALSE; c_mutexInit(&p->resendMutex, SHARED_MUTEX); c_condInit(&p->resendCond, &p->resendMutex, SHARED_COND); writerProxyType = v_kernelType(kernel,K_PROXY); p->resendWriters = c_tableNew(writerProxyType, "source.index,source.serial"); p->builtinSubscriber = NULL; if (!v_observableAddObserver(v_observable(kernel),v_observer(p), NULL)) { if (name != NULL) { OS_REPORT_1(OS_WARNING,"Kernel Participant",0, "%s: Cannot observe Kernel events",name); } else { OS_REPORT(OS_WARNING,"Kernel Participant",0, "Cannot observe Kernel events"); } } c_mutexInit(&p->newGroupListMutex,SHARED_MUTEX); p->newGroupList = c_listNew(c_resolve(base, "kernelModule::v_group")); v_observerSetEventMask(v_observer(p), V_EVENT_NEW_GROUP); c_lockInit(&p->lock,SHARED_LOCK); c_mutexInit(&p->builtinLock,SHARED_MUTEX); /* Here the Builtin Topic of the participant is published. * This call mabe a noop in case builtin is disabled on kernel level. */ builtinMsg = v_builtinCreateParticipantInfo(kernel->builtin,p); v_writeBuiltinTopic(kernel, V_PARTICIPANTINFO_ID, builtinMsg); c_free(builtinMsg); }
void v_leaseManagerInit( v_leaseManager _this) { v_kernel k; assert(C_TYPECHECK(_this, v_leaseManager)); k = v_objectKernel(_this); c_mutexInit(&_this->mutex, SHARED_MUTEX); c_condInit(&_this->cond, &_this->mutex, SHARED_COND); _this->quit = FALSE; _this->firstLeaseToExpire = NULL; _this->leases = c_setNew(v_kernelType(k, K_LEASEACTION)); }
/************************************************************** * Protected functions **************************************************************/ void v_collectionInit( v_collection c, const c_char *name, v_statistics s, c_bool enable) { c_base base; assert(C_TYPECHECK(c,v_collection)); v_observerInit(v_observer(c), name, s, enable); base = c_getBase(c_object(c)); c->queries = c_setNew(c_resolve(base,"kernelModule::v_query")); }
void v_leaseInit( v_lease _this, v_kernel k, v_duration leaseDuration) { if (_this != NULL) { assert(C_TYPECHECK(_this, v_lease)); c_mutexInit(&_this->mutex,SHARED_MUTEX); _this->expiryTime = c_timeAdd(v_timeGet(), leaseDuration); _this->duration = leaseDuration; _this->observers = c_setNew(v_kernelType(k, K_LEASEMANAGER)); } }
void v_serviceFillNewGroups( v_service service) { c_set newGroups; C_STRUCT(v_event) ge; v_group g; v_kernel kernel; c_iter groups = NULL; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); kernel = v_objectKernel(service); newGroups = (c_voidp)c_setNew(v_kernelType(kernel, K_GROUP)); if (newGroups != NULL) { groups = v_groupSetSelectAll(kernel->groupSet); /* Take the first group and at the end notify the service about this new group. * But before push all other groups to the servive newGroup set so that only one trigger * is required to notify all groups. * The first group is automatically added to the newGroup set by the notification. * TODO : get rid of this mechanism. */ ge.data = v_group(c_iterTakeFirst(groups)); if (ge.data) { ge.kind = V_EVENT_NEW_GROUP; ge.source = v_observable(kernel); ospl_c_insert(newGroups, ge.data); while ((g = v_group(c_iterTakeFirst(groups))) != NULL) { ospl_c_insert(newGroups, g); c_free(g); } OSPL_BLOCK_EVENTS(service); c_free(service->newGroups); service->newGroups = (c_voidp)newGroups; OSPL_UNBLOCK_EVENTS(service); OSPL_TRIGGER_EVENT((service), &ge, NULL); } c_iterFree(groups); } }
void v_groupStreamInit( v_groupStream stream, const c_char *name, v_subscriber subscriber, v_readerQos qos) { v_kernel kernel; assert(C_TYPECHECK(stream, v_groupStream)); assert(C_TYPECHECK(subscriber, v_subscriber)); kernel = v_objectKernel(subscriber); stream->groups = c_setNew(v_kernelType(kernel,K_GROUP)); v_readerInit(v_reader(stream),name,subscriber,qos,NULL,TRUE); v_subscriberAddReader(subscriber,v_reader(stream)); }
void v_serviceFillNewGroups( v_service service) { c_set newGroups; C_STRUCT(v_event) ge; v_group g, oldGroup; c_iter oldGroups; v_kernel kernel; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); kernel = v_objectKernel(service); newGroups = (c_voidp)c_setNew(v_kernelType(kernel, K_GROUP)); if (newGroups != NULL) { addAllGroups(newGroups, kernel->groupSet); v_observerLock(v_observer(service)); g = v_group(c_read(newGroups)); /* need a group for the event */ if(v_observer(service)->eventData != NULL){ oldGroups = ospl_c_select((c_set)v_observer(service)->eventData, 0); oldGroup = v_group(c_iterTakeFirst(oldGroups)); while(oldGroup){ newGroups = c_setInsert(newGroups, oldGroup); c_free(oldGroup); oldGroup = v_group(c_iterTakeFirst(oldGroups)); } c_iterFree(oldGroups); } /* just for safety, when assertion are compiled out, free the prev set */ c_free((c_object)v_observer(service)->eventData); v_observer(service)->eventData = (c_voidp)newGroups; ge.kind = V_EVENT_NEW_GROUP; ge.source = v_publicHandle(v_public(kernel)); ge.userData = g; v_observerNotify(v_observer(service), &ge, NULL); v_observerUnlock(v_observer(service)); c_free(g); } }
void v_cfElementInit ( v_cfElement element, v_configuration config, const c_char *tagName) { c_type attrType; c_type nodeType; const c_char *keyList; assert(C_TYPECHECK(element, v_cfElement)); assert(tagName != NULL); v_cfNodeInit(v_cfNode(element), config, V_CFELEMENT, tagName); attrType = c_resolve(c_getBase(element), "kernelModule::v_cfAttribute"); nodeType = c_resolve(c_getBase(element), "kernelModule::v_cfNode"); keyList = "name"; element->attributes = c_tableNew(attrType, keyList); element->children = c_setNew(nodeType); }
void v_groupStreamInit( v_groupStream stream, const c_char *name, v_subscriber subscriber, v_readerQos qos, v_statistics rs, c_iter expr) { v_kernel kernel; assert(C_TYPECHECK(stream, v_groupStream)); assert(C_TYPECHECK(subscriber, v_subscriber)); kernel = v_objectKernel(subscriber); stream->groups = c_setNew(v_kernelType(kernel,K_GROUP)); stream->expr = c_listNew(c_resolve(c_getBase(stream), "::c_string")); c_iterWalk(expr, fillExprList, stream->expr); v_readerInit(v_reader(stream),name,subscriber,qos,rs,TRUE); v_subscriberAddReader(subscriber,v_reader(stream)); }
v_waitset v_waitsetNew( v_participant p) { v_waitset _this; v_kernel kernel; c_type proxyType; assert(C_TYPECHECK(p,v_participant)); kernel = v_objectKernel(p); _this = v_waitset(v_objectNew(kernel,K_WAITSET)); if (_this != NULL) { v_observerInit(v_observer(_this),"Waitset", NULL, TRUE); _this->participant = p; _this->eventCache = NULL; proxyType = v_kernelType(kernel,K_PROXY); _this->observables = c_setNew(proxyType); v_observerSetEventData(v_observer(_this), NULL); v_participantAdd(p, v_entity(_this)); } return _this; }
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; }
v_kernel v_kernelNew( c_base base, const c_char *name, v_kernelQos qos) { v_kernel kernel; v_kernelStatistics kernelStatistics; v_spliced sd; kernel = c_lookup(base,name); if (kernel != NULL) { assert(C_TYPECHECK(kernel,v_kernel)); kernel->userCount++; return kernel; } loadkernelModule(base); kernel = (v_kernel)c_new(c_resolve(base,"kernelModule::v_kernel")); if (!kernel) { OS_REPORT(OS_ERROR, "v_kernelNew",0, "Failed to allocate kernel."); return NULL; } v_objectKind(kernel) = K_KERNEL; v_object(kernel)->kernel = (c_voidp)kernel; kernel->handleServer = v_handleServerNew(base); #define INITTYPE(k,t,l) k->type[l] = c_resolve(base,#t) INITTYPE(kernel,kernelModule::v_kernel, K_KERNEL); INITTYPE(kernel,kernelModule::v_participant, K_PARTICIPANT); INITTYPE(kernel,kernelModule::v_waitset, K_WAITSET); INITTYPE(kernel,kernelModule::v_condition, K_CONDITION); INITTYPE(kernel,kernelModule::v_query, K_QUERY); INITTYPE(kernel,kernelModule::v_dataReaderQuery, K_DATAREADERQUERY); INITTYPE(kernel,kernelModule::v_dataViewQuery, K_DATAVIEWQUERY); INITTYPE(kernel,kernelModule::v_dataView, K_DATAVIEW); INITTYPE(kernel,kernelModule::v_dataViewSample, K_DATAVIEWSAMPLE); INITTYPE(kernel,kernelModule::v_dataViewInstance, K_DATAVIEWINSTANCE); INITTYPE(kernel,kernelModule::v_projection, K_PROJECTION); INITTYPE(kernel,kernelModule::v_mapping, K_MAPPING); INITTYPE(kernel,kernelModule::v_topic, K_TOPIC); INITTYPE(kernel,kernelModule::v_message, K_MESSAGE); INITTYPE(kernel,kernelModule::v_transaction, K_TRANSACTION); INITTYPE(kernel,kernelModule::v_dataReaderInstance, K_DATAREADERINSTANCE); INITTYPE(kernel,kernelModule::v_purgeListItem, K_PURGELISTITEM); INITTYPE(kernel,kernelModule::v_groupPurgeItem, K_GROUPPURGEITEM); INITTYPE(kernel,kernelModule::v_dataReaderSample, K_READERSAMPLE); INITTYPE(kernel,kernelModule::v_publisher, K_PUBLISHER); INITTYPE(kernel,kernelModule::v_subscriber, K_SUBSCRIBER); INITTYPE(kernel,kernelModule::v_partition, K_DOMAIN); INITTYPE(kernel,kernelModule::v_partitionInterest, K_DOMAININTEREST); INITTYPE(kernel,kernelModule::v_partitionAdmin, K_DOMAINADMIN); INITTYPE(kernel,kernelModule::v_reader, K_READER); INITTYPE(kernel,kernelModule::v_writer, K_WRITER); INITTYPE(kernel,kernelModule::v_writerGroup, K_WRITERGROUP); INITTYPE(kernel,kernelModule::v_group, K_GROUP); INITTYPE(kernel,kernelModule::v_groupInstance, K_GROUPINSTANCE); INITTYPE(kernel,kernelModule::v_groupSample, K_GROUPSAMPLE); INITTYPE(kernel,kernelModule::v_groupCacheItem, K_GROUPCACHEITEM); INITTYPE(kernel,kernelModule::v_cache, K_CACHE); INITTYPE(kernel,kernelModule::v_entry, K_ENTRY); INITTYPE(kernel,kernelModule::v_dataReaderEntry, K_DATAREADERENTRY); INITTYPE(kernel,kernelModule::v_groupAction, K_GROUPACTION); INITTYPE(kernel,kernelModule::v_groupStream, K_GROUPSTREAM); INITTYPE(kernel,kernelModule::v_groupQueue, K_GROUPQUEUE); INITTYPE(kernel,kernelModule::v_groupQueueSample, K_GROUPQUEUESAMPLE); INITTYPE(kernel,kernelModule::v_dataReader, K_DATAREADER); INITTYPE(kernel,kernelModule::v_deliveryService, K_DELIVERYSERVICE); INITTYPE(kernel,kernelModule::v_deliveryServiceEntry, K_DELIVERYSERVICEENTRY); INITTYPE(kernel,kernelModule::v_index, K_INDEX); INITTYPE(kernel,kernelModule::v_filter, K_FILTER); INITTYPE(kernel,kernelModule::v_readerStatus, K_READERSTATUS); INITTYPE(kernel,kernelModule::v_writerStatus, K_WRITERSTATUS); INITTYPE(kernel,kernelModule::v_partitionStatus, K_DOMAINSTATUS); INITTYPE(kernel,kernelModule::v_topicStatus, K_TOPICSTATUS); INITTYPE(kernel,kernelModule::v_subscriberStatus, K_SUBSCRIBERSTATUS); INITTYPE(kernel,kernelModule::v_status, K_PUBLISHERSTATUS); INITTYPE(kernel,kernelModule::v_status, K_PARTICIPANTSTATUS); INITTYPE(kernel,kernelModule::v_kernelStatus, K_KERNELSTATUS); INITTYPE(kernel,kernelModule::v_readerStatistics, K_READERSTATISTICS); INITTYPE(kernel,kernelModule::v_writerStatistics, K_WRITERSTATISTICS); INITTYPE(kernel,kernelModule::v_queryStatistics, K_QUERYSTATISTICS); INITTYPE(kernel,kernelModule::v_lease, K_LEASE); INITTYPE(kernel,kernelModule::v_leaseAction, K_LEASEACTION); INITTYPE(kernel,kernelModule::v_serviceManager, K_SERVICEMANAGER); INITTYPE(kernel,kernelModule::v_service, K_SERVICE); INITTYPE(kernel,kernelModule::v_serviceState, K_SERVICESTATE); INITTYPE(kernel,kernelModule::v_networking, K_NETWORKING); INITTYPE(kernel,kernelModule::v_durability, K_DURABILITY); INITTYPE(kernel,kernelModule::v_cmsoap, K_CMSOAP); INITTYPE(kernel,kernelModule::v_leaseManager, K_LEASEMANAGER); INITTYPE(kernel,kernelModule::v_groupSet, K_GROUPSET); INITTYPE(kernel,kernelModule::v_proxy, K_PROXY); INITTYPE(kernel,kernelModule::v_waitsetEvent, K_WAITSETEVENT); INITTYPE(kernel,kernelModule::v_waitsetEventHistoryDelete, K_WAITSETEVENTHISTORYDELETE); INITTYPE(kernel,kernelModule::v_waitsetEventHistoryRequest, K_WAITSETEVENTHISTORYREQUEST); INITTYPE(kernel,kernelModule::v_waitsetEventPersistentSnapshot, K_WAITSETEVENTPERSISTENTSNAPSHOT); INITTYPE(kernel,kernelModule::v_writerSample, K_WRITERSAMPLE); INITTYPE(kernel,kernelModule::v_writerInstance, K_WRITERINSTANCE); INITTYPE(kernel,kernelModule::v_writerInstanceTemplate, K_WRITERINSTANCETEMPLATE); INITTYPE(kernel,kernelModule::v_writerCacheItem, K_WRITERCACHEITEM); /* Networking types */ INITTYPE(kernel,kernelModule::v_networkReader, K_NETWORKREADER); INITTYPE(kernel,kernelModule::v_networkReaderEntry, K_NETWORKREADERENTRY); INITTYPE(kernel,kernelModule::v_networkMessage, K_NETWORKMESSAGE); INITTYPE(kernel,kernelModule::v_networkMapEntry, K_NETWORKMAPENTRY); INITTYPE(kernel,kernelModule::v_spliced, K_SPLICED); INITTYPE(kernel,kernelModule::v_configuration, K_CONFIGURATION); INITTYPE(kernel,kernelModule::v_registration, K_REGISTRATION); INITTYPE(kernel,kernelModule::v_historicalDataRequest,K_HISTORICALDATAREQUEST); INITTYPE(kernel,kernelModule::v_persistentSnapshotRequest,K_PERSISTENTSNAPSHOTREQUEST); INITTYPE(kernel,kernelModule::v_pendingDisposeElement,K_PENDINGDISPOSEELEMENT); #undef INITTYPE kernel->pendingDisposeList = c_listNew(v_kernelType(kernel, K_PENDINGDISPOSEELEMENT )); c_mutexInit(&kernel->pendingDisposeListMutex, SHARED_MUTEX); kernelStatistics = v_kernelStatisticsNew(kernel); v_observableInit(v_observable(kernel), V_KERNEL_VERSION, v_statistics(kernelStatistics), TRUE); c_lockInit(&kernel->lock,SHARED_LOCK); kernel->qos = v_kernelQosNew(kernel, qos); { os_time time; /* Fill GID with 'random' value */ memset(&kernel->GID, 0, sizeof(kernel->GID)); time = os_timeGet(); kernel->GID.systemId = time.tv_nsec; } kernel->participants = c_setNew(v_kernelType(kernel,K_PARTICIPANT)); kernel->partitions = c_tableNew(v_kernelType(kernel,K_DOMAIN),"name"); kernel->topics = c_tableNew(v_kernelType(kernel,K_TOPIC),"name"); kernel->groupSet = v_groupSetNew(kernel); kernel->serviceManager = v_serviceManagerNew(kernel); kernel->livelinessLM = v_leaseManagerNew(kernel); kernel->configuration = NULL; kernel->userCount = 1; kernel->transactionCount = 0; kernel->splicedRunning = TRUE; kernel->maxSamplesWarnLevel = V_KERNEL_MAX_SAMPLES_WARN_LEVEL_DEF; kernel->maxSamplesWarnShown = FALSE; kernel->maxSamplesPerInstanceWarnLevel = V_KERNEL_MAX_SAMPLES_PER_INSTANCES_WARN_LEVEL_DEF; kernel->maxSamplesPerInstanceWarnShown = FALSE; kernel->maxInstancesWarnLevel = V_KERNEL_MAX_INSTANCES_WARN_LEVEL_DEF; kernel->maxInstancesWarnShown = FALSE; kernel->enabledStatisticsCategories = c_listNew(c_resolve(base, "kernelModule::v_statisticsCategory")); c_mutexInit(&kernel->sharesMutex, SHARED_MUTEX); kernel->shares = c_tableNew(v_kernelType(kernel,K_SUBSCRIBER), "qos.share.name"); kernel->crc = v_crcNew(kernel, V_CRC_KEY); kernel->builtin = v_builtinNew(kernel); kernel->deliveryService = NULL; sd = v_splicedNew(kernel); c_free(sd); c_bind(kernel,name); return kernel; }