u_instanceHandle u_instanceHandleNew( v_public object) { v_handle handle; u_instanceHandleTranslator translator; c_long id; if (object) { handle = v_publicHandle(object); if (handle.serial != (handle.serial & HANDLE_SERIAL_MASK)) { handle.serial = (handle.serial & HANDLE_SERIAL_MASK); OS_REPORT(OS_ERROR,"u_instanceHandleNew",0, "handle.serial exceeds HANDLE_SERIAL_MASK"); } id = u_userServerId(v_public(object)); if (id != (id & HANDLE_SERVER_MASK)) { id = (id & HANDLE_SERVER_MASK); OS_REPORT(OS_ERROR,"u_instanceHandleNew",0, "ServerId exceeds HANDLE_SERVER_MASK"); } translator.lid.lifecycleId = (handle.serial | id); translator.lid.localId = handle.index; } else { translator.handle = 0; } return translator.handle; }
void cmx_participantDomainsAction( v_public p, c_voidp args) { cmx_walkEntityArg arg; c_iter partitions; v_entity partition; c_bool proceed; c_char* xmlEntity; arg = cmx_walkEntityArg(args); partitions = v_resolvePartitions(v_objectKernel(p), "*"); partition = v_entity(c_iterTakeFirst(partitions)); while(partition != NULL){ proceed = cmx_entityNewFromWalk(v_public(partition), &arg->entityArg); if(proceed == TRUE){ xmlEntity = arg->entityArg.result; arg->list = c_iterInsert(arg->list, xmlEntity); arg->length += strlen(xmlEntity); } c_free(partition); partition = v_entity(c_iterTakeFirst(partitions)); } c_iterFree(partitions); }
void v_entryRemoveGroup( v_entry entry, v_group group) { c_query query; q_expr qExpr; c_value params[2]; c_iter groups; v_proxy proxy, proxy2; v_handle handle; assert(entry != NULL); assert(C_TYPECHECK(entry,v_entry)); assert(group != NULL); assert(C_TYPECHECK(group,v_group)); handle = v_publicHandle(v_public(group)); qExpr = (q_expr)q_parse("source.index = %0 and source.server = %1"); params[0] = c_longValue(handle.index); params[1] = c_addressValue(handle.server); query = c_queryNew(entry->groups, qExpr, params); q_dispose(qExpr); groups = c_select(query, 0); c_free(query); assert(c_iterLength(groups) <= 1); proxy = v_proxy(c_iterTakeFirst(groups)); proxy2 = c_remove(entry->groups, proxy, NULL, NULL); c_iterFree(groups); c_free(proxy); c_free(proxy2); }
void cmx_participantFindTopicAction( v_public p, c_voidp args) { cmx_walkEntityArg arg; c_iter topics; v_entity topic; c_bool proceed; c_char* xmlEntity; arg = cmx_walkEntityArg(args); topics = v_resolveTopics(v_objectKernel(p), cmx_walkParticipantArg(arg)->topicName); topic = v_entity(c_iterTakeFirst(topics)); while(topic != NULL){ proceed = cmx_entityNewFromWalk(v_public(topic), &arg->entityArg); if(proceed == TRUE){ xmlEntity = arg->entityArg.result; arg->list = c_iterInsert(arg->list, xmlEntity); arg->length += strlen(xmlEntity); } c_free(topic); topic = v_entity(c_iterTakeFirst(topics)); } c_iterFree(topics); }
c_bool v_entryAddGroup( v_entry entry, v_group group) { v_proxy proxy; v_proxy found; c_bool result; assert(C_TYPECHECK(entry,v_entry)); assert(C_TYPECHECK(group,v_group)); proxy = v_proxyNew(v_objectKernel(group), v_publicHandle(v_public(group)), NULL); found = c_insert(entry->groups, proxy); if(found != proxy){ /* The group was already available in the groupset. This can happen if * the reader gets notified of the group it has just created. In that * case the administration should not be updated. */ result = FALSE; } else { result = TRUE; } c_free(proxy); return result; }
void v_collectionFree( v_collection c) { v_query q; assert(C_TYPECHECK(c,v_collection)); q = v_query(c_take(c->queries)); while (q != NULL) { /* The v_publicFree shouldn't be here, because it should be the * responsibility of the 'creator' of the query to have this * knowledge and perform the v_publicFree. The only thing that should be * required here is freeing the reference to the query by doing a * c_free. * * Because it is not exactly clear where the v_publicFree should be * performed, it is performed here for now. */ v_publicFree(v_public(q)); c_free(q); q = v_query(c_take(c->queries)); } v_observerFree(v_observer(c)); }
c_bool v_waitsetAttach ( v_waitset _this, v_observable o, c_voidp userData) { c_bool result; v_proxy proxy; findProxyArgument arg; assert(_this != NULL); assert(C_TYPECHECK(_this,v_waitset)); arg.observable = v_publicHandle(v_public(o)); arg.proxy = NULL; v_waitsetLock(_this); c_setWalk(_this->observables, findProxy,&arg); if (arg.proxy == NULL) { /* no proxy to the observer exists */ proxy = v_proxyNew(v_objectKernel(_this), arg.observable, userData); c_insert(_this->observables,proxy); c_free(proxy); } v_waitsetUnlock(_this); result = v_observableAddObserver(o,v_observer(_this), userData); /* wakeup blocking threads to evaluate new condition. */ if (v_observerWaitCount(_this)) { v_waitsetTrigger(_this, NULL); } return result; }
c_bool v_waitsetDetach ( v_waitset _this, v_observable o) { c_bool result; v_proxy found; findProxyArgument arg; void* userDataRemoved = NULL; assert(_this != NULL); assert(C_TYPECHECK(_this,v_waitset)); arg.observable = v_publicHandle(v_public(o)); arg.proxy = NULL; v_waitsetLock(_this); c_setWalk(_this->observables,findProxy,&arg); if (arg.proxy != NULL) { /* proxy to the observer found */ found = c_remove(_this->observables,arg.proxy,NULL,NULL); assert(found == arg.proxy); c_free(found); } v_waitsetUnlock(_this); result = v_observableRemoveObserver(o,v_observer(_this), &userDataRemoved); v_waitsetClearRemovedObserverPendingEvents(_this, userDataRemoved); /* wakeup blocking threads to evaluate new condition. */ if (v_observerWaitCount(_this)) { v_waitsetTrigger(_this, NULL); } return result; }
v_listener v_listenerNew( v_participant p, c_bool combine) { v_listener _this; v_kernel kernel; assert(C_TYPECHECK(p,v_participant)); kernel = v_objectKernel(p); _this = v_listener(v_objectNew(kernel,K_LISTENER)); if (_this != NULL) { v_publicInit(v_public(_this)); (void)c_mutexInit(c_getBase(_this), &_this->mutex); c_condInit(c_getBase(_this), &_this->cv, &_this->mutex); _this->participant = p; _this->eventList = NULL; _this->lastEvent = NULL; v_participantAdd(p, v_object(_this)); _this->terminate = FALSE; _this->waitCount = 0; _this->combine = combine; } return _this; }
DDS::ReturnCode_t DDS::OpenSplice::Utils::copyStatusOut( const v_deadlineMissedInfo &from, DDS::OfferedDeadlineMissedStatus &to) { DDS::ReturnCode_t result; v_object instance; result = DDS::RETCODE_ERROR; to.total_count = from.totalCount; to.total_count_change = from.totalChanged; if (!v_handleIsNil(from.instanceHandle)) { if (v_handleClaim(from.instanceHandle, &instance) == V_HANDLE_OK) { to.last_instance_handle = u_instanceHandleNew(v_public(instance)); if (v_handleRelease(from.instanceHandle) == V_HANDLE_OK) { result = DDS::RETCODE_OK; } } } else { result = DDS::RETCODE_OK; } return result; }
/** * PRE: observer must be locked. */ void v_groupStreamNotifyDataAvailable( v_groupStream stream) { /* This Notify method is part of the observer-observable pattern. * It is designed to be invoked when _this object as observer receives * an event from an observable object. * It must be possible to pass the event to the subclass of itself by * calling <subclass>Notify(_this, event, userData). * This implies that _this cannot be locked within any Notify method * to avoid deadlocks. * For consistency _this must be locked by v_observerLock(_this) before * calling this method. */ C_STRUCT(v_event) event; c_bool changed; assert(stream != NULL); assert(C_TYPECHECK(stream,v_groupStream)); changed = v_statusNotifyDataAvailable(v_entity(stream)->status); if (changed) { event.kind = V_EVENT_DATA_AVAILABLE; event.source = v_publicHandle(v_public(stream)); event.userData = NULL; v_observableNotify(v_observable(stream), &event); } return; }
void v_partitionFree( v_partition partition) { assert(C_TYPECHECK(partition,v_partition)); v_publicFree(v_public(partition)); }
void v_subscriberFree( v_subscriber s) { v_kernel kernel; v_participant p; v_reader o; v_entity found; c_long sc; kernel = v_objectKernel(s); sc = (c_long)pa_decrement(&(s->shareCount)); if (sc > 0) return; if(sc == 0){ v_observableRemoveObserver(v_observable(kernel->groupSet),v_observer(s), NULL); if (s->qos->share.enable) { found = v_removeShare(kernel,v_entity(s)); assert(found == v_entity(s)); c_free(found); } while ((o = c_take(s->readers)) != NULL) { switch (v_objectKind(o)) { case K_DATAREADER: v_dataReaderFree(v_dataReader(o)); break; case K_DELIVERYSERVICE: v_deliveryServiceFree(v_deliveryService(o)); break; case K_GROUPQUEUE: v_groupQueueFree(v_groupQueue(o)); break; case K_NETWORKREADER: v_networkReaderFree(v_networkReader(o)); break; default: OS_REPORT_1(OS_ERROR, "v_subscriber", 0, "Unknown reader %d", v_objectKind(o)); assert(FALSE); break; } c_free(o); } p = v_participant(s->participant); if (p != NULL) { v_participantRemove(p,v_entity(s)); s->participant = NULL; } v_publicFree(v_public(s)); } else { OS_REPORT_1(OS_ERROR, "v_subscriberFree", 0, "subscriber already freed (shareCount is now %d).", sc); assert(sc == 0); } }
static void getEntityGid ( v_entity e, c_voidp arg) { v_gid *gid = (v_gid *) arg; *gid = v_publicGid(v_public(e)); }
static void copySampleInfoView ( v_readerSample sample, v_message message, gapi_sampleInfo *to ) { v_state state; v_dataReaderSample master; v_dataViewInstance viewInstance; v_dataReaderInstance masterInstance; viewInstance = (v_dataViewInstance)sample->instance; master = v_dataReaderSample(v_dataViewSampleTemplate(sample)->sample); masterInstance = (v_dataReaderInstance)v_readerSampleInstance(master); state = v_readerSample(sample)->sampleState; if (v_stateTest (state, L_READ)) { to->sample_state = GAPI_READ_SAMPLE_STATE; } else { to->sample_state = GAPI_NOT_READ_SAMPLE_STATE; } if (v_stateTest (state, L_NEW)) { to->view_state = GAPI_NEW_VIEW_STATE; } else { to->view_state = GAPI_NOT_NEW_VIEW_STATE; } state = masterInstance->instanceState; to->instance_state = GAPI_ALIVE_INSTANCE_STATE; if (v_stateTest (state, L_NOWRITERS)) { to->instance_state = GAPI_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE; } if (v_stateTest (state, L_DISPOSED)) { to->instance_state = GAPI_NOT_ALIVE_DISPOSED_INSTANCE_STATE; } /* Data is always valid for views */ to->valid_data = TRUE; to->source_timestamp.sec = (gapi_long)(message->writeTime.seconds); to->source_timestamp.nanosec = (gapi_unsigned_long)(message->writeTime.nanoseconds); to->disposed_generation_count = master->disposeCount; to->no_writers_generation_count = master->noWritersCount; to->sample_rank = 0; to->generation_rank = 0; to->absolute_generation_rank = 0; to->instance_handle = u_instanceHandleNew(v_public(viewInstance)); to->publication_handle = u_instanceHandleFromGID(master->publicationHandle); to->reception_timestamp.sec = (gapi_long)(master->insertTime.seconds); to->reception_timestamp.nanosec = (gapi_unsigned_long)(master->insertTime.nanoseconds); }
void v_listenerDeinit( v_listener _this) { assert(_this != NULL); assert(C_TYPECHECK(_this,v_listener)); if (_this == NULL) { return; } v_publicDeinit(v_public(_this)); }
static u_result handleGroup( v_service service, v_group group) { v_networkReaderEntry entry; in_printf(IN_LEVEL_FINE, "Found new group '%s.%s'; adding networkReaderEntry...\n", v_entity(group->partition)->name, v_entity(group->topic)->name); entry = v_networkReaderEntryNew( vclientReader, group, v_publicGid(v_public(service)).systemId, 1, 0); if (group->topic->qos->durability.kind >= V_DURABILITY_TRANSIENT) { /* For transient topics, DDSI readers are spontaneously generated to ensure data will indeed arrive -- FIXME: currently no provision is made to ensure no "early" publications are lost while DDSI discovery is still digesting these readers. For convenience, we use the regular DDS<->DDSI mapping to handle these ficitious readers, and we pretend these ficitious readers are owned by the DDSI service participant. That one has been created, and as luck has it, the participants are discovered before the groups are. So we just look it up. */ v_builtinTopicKey pkey; in_participant p; in_printf(IN_LEVEL_FINE, "Group is transient - creating DDSI data reader...\n"); os_mutexLock (&gluelock); pkey = u_entityGid ((u_entity) participant); if ((p = in_participantLookup (&pkey)) == NULL) in_printf (IN_LEVEL_SEVERE, "handleGroup: participant lookup of self failed, transient data may not work\n"); else { if (!in_fictitiousTransientReaderNew (p, group)) { in_printf (IN_LEVEL_SEVERE, "handleGroup: creation of fictitious transient data reader failed, transient data may not work\n"); } } os_mutexUnlock (&gluelock); } v_networkReaderEntryNotifyConnected(entry, SERVICE_NAME); v_networkReaderRemoteActivityDetected(vclientReader); return U_RESULT_OK; }
void v_participantDeleteHistoricalData( v_participant participant, const c_char* partitionExpr, const c_char* topicExpr) { c_iter matchingGroups; v_group group; c_time t; c_value params[2]; C_STRUCT(v_event) event; C_STRUCT(v_historyDeleteEventData) hde; assert(participant != NULL); assert(C_TYPECHECK(participant, v_participant)); assert(partitionExpr); assert(topicExpr); if(partitionExpr && topicExpr){ params[0] = c_stringValue((c_string)partitionExpr); params[1] = c_stringValue((c_string)topicExpr); c_lockRead(&participant->lock); t = v_timeGet(); matchingGroups = v_groupSetSelect( v_objectKernel(participant)->groupSet, "partition.name like %0 AND topic.name like %1", params); c_lockUnlock(&participant->lock); group = v_group(c_iterTakeFirst(matchingGroups)); while(group){ v_groupDeleteHistoricalData(group, t); c_free(group); group = v_group(c_iterTakeFirst(matchingGroups)); } c_iterFree(matchingGroups); hde.partitionExpression = (c_char *)partitionExpr; hde.topicExpression = (c_char *)topicExpr; hde.deleteTime = t; event.kind = V_EVENT_HISTORY_DELETE; event.source = v_publicHandle(v_public(participant)); event.userData = &hde; v_observableNotify(v_observable(v_objectKernel(participant)),&event); } return; }
v_public v_gidClaim ( v_gid id, v_kernel kernel) { v_handle handle; v_object o = NULL; if (v_gidIsFromKernel(id, kernel)) { handle = gidToHandle(id,kernel); v_handleClaim(handle, &o); /* Ignore result */ assert(C_TYPECHECK(o,v_public)); } return v_public(o); }
void v_participantResendManagerRemoveWriter( v_participant p, v_writer w) { C_STRUCT(v_proxy) wp; v_proxy found; wp.source = v_publicHandle(v_public(w)); wp.userData = NULL; c_mutexLock(&p->resendMutex); found = c_remove(p->resendWriters, &wp, NULL, NULL); c_free(found); /* remove local reference transferred from collection */ c_mutexUnlock(&p->resendMutex); }
void v_waitsetTrigger( v_waitset _this, c_voidp eventArg) { C_STRUCT(v_event) event; assert(_this != NULL); assert(C_TYPECHECK(_this,v_waitset)); v_waitsetLock(_this); event.kind = V_EVENT_TRIGGER; event.source = v_publicHandle(v_public(_this)); event.userData = NULL; v_waitsetWakeup(_this, &event, eventArg); v_waitsetUnlock(_this); }
void v_participantAssertLiveliness( v_participant p) { C_STRUCT(v_event) event; assert(p != NULL); assert(C_TYPECHECK(p,v_participant)); event.kind = V_EVENT_LIVELINESS_ASSERT; event.source = v_publicHandle(v_public(p)); event.userData = NULL; /* Walk over all entities and assert liveliness on all writers */ c_lockWrite(&p->lock); c_walk(p->entities, assertLivelinessPublisher, &event); c_lockUnlock(&p->lock); }
void u_cfNodeInit( u_cfNode _this, const u_participant participant, const v_cfNode kNode) { v_configuration config; assert(_this != NULL); assert(participant != NULL); assert(kNode != NULL); config = v_cfNodeConfiguration(kNode); _this->configuration = u_handleNew(v_public(config)); _this->participant = participant; _this->kind = v_cfNodeKind(kNode); _this->id = kNode->id; }
/* put at end of list */ void v_deadLineInstanceListInsertInstance( v_deadLineInstanceList list, v_instance instance) { v_instance head = v_instance(list); v_kernel k; v_result result; assert(C_TYPECHECK(instance,v_instance)); assert(C_TYPECHECK(list,v_deadLineInstanceList)); assert(v_instanceAlone(instance)); assert(c_refCount(list) > 0); assert(c_refCount(instance) > 0); /* As the instance is put at the end of the list no need to update the lease! */ v_instanceUpdate(instance); /* Updates instance checkTime */ v_instanceAppend(head,instance); if (list->deadlineLease == NULL) { if (c_timeCompare(list->leaseDuration, C_TIME_INFINITE) != C_EQ) { k = v_objectKernel(list->leaseManager); list->deadlineLease = v_leaseNew(k, list->leaseDuration); if(list->deadlineLease) { result = v_leaseManagerRegister( list->leaseManager, list->deadlineLease, list->actionId, v_public(list->actionObject), TRUE /* repeat lease if expired */); if(result != V_RESULT_OK) { c_free(list->deadlineLease); list->deadlineLease = NULL; OS_REPORT_1(OS_ERROR, "v_deadLineInstanceList", 0, "A fatal error was detected when trying to register the deadline lease." "The result code was %d.", result); } } } } }
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_deadLineInstanceListSetDuration( v_deadLineInstanceList list, v_duration duration) { v_kernel k; v_result result; assert(C_TYPECHECK(list,v_deadLineInstanceList)); list->leaseDuration = duration; if (list->deadlineLease != NULL) { if (c_timeCompare(duration, C_TIME_INFINITE) != C_EQ) { v_leaseRenew(list->deadlineLease,duration); } else { v_leaseManagerDeregister(list->leaseManager, list->deadlineLease); c_free(list->deadlineLease); list->deadlineLease = NULL; } } else { if ((v_objectKind(v_instance(list)->prev) != K_DEADLINEINSTANCE) && /* not in list */ (c_timeCompare(duration, C_TIME_INFINITE) != C_EQ)) { /* new instance */ k = v_objectKernel(list->leaseManager); list->deadlineLease = v_leaseNew(k, duration); if(list->deadlineLease) { result = v_leaseManagerRegister( list->leaseManager, list->deadlineLease, list->actionId, v_public(list->actionObject), TRUE /* repeat lease if expired */); if(result != V_RESULT_OK) { c_free(list->deadlineLease); list->deadlineLease = NULL; OS_REPORT_1(OS_ERROR, "v_deadLineInstanceList", 0, "A fatal error was detected when trying to register the deadline lease." "The result code was %d.", result); } } } } }
void v_participantResendManagerAddWriter( v_participant p, v_writer w) { v_proxy wp, found; assert(C_TYPECHECK(p,v_participant)); wp = v_proxyNew(v_objectKernel(w), v_publicHandle(v_public(w)), NULL); c_mutexLock(&p->resendMutex); found = c_insert(p->resendWriters, wp); assert((found->source.index == wp->source.index) && (found->source.serial == wp->source.serial)); c_condBroadcast(&p->resendCond); c_mutexUnlock(&p->resendMutex); c_free(wp); }
c_bool v_entryGroupExists( v_entry entry, v_group group) { c_bool r; struct groupExistsArg arg; assert(entry != NULL); assert(C_TYPECHECK(entry,v_entry)); assert(group != NULL); assert(C_TYPECHECK(group,v_group)); arg.exists = FALSE; arg.proxy = v_proxyNew(v_objectKernel(group), v_publicHandle(v_public(group)), NULL); r = c_tableWalk(entry->groups, groupExists, &arg); c_free(arg.proxy); return arg.exists; }
void v_dataViewInstanceRemove( v_dataViewInstance instance) { v_dataViewInstance found; assert(C_TYPECHECK(instance,v_dataViewInstance)); if (instance->sampleCount == 0) { CHECK_ZERO_INSTANCE(instance); found = c_remove(v_dataView(instance->dataView)->instances,instance,NULL,NULL); assert(found == instance); instance->dataView = NULL; v_publicFree(v_public(instance)); c_free(instance); } else { CHECK_INSTANCE(instance); } }
/** * This method will invalidate a handle and mark the resources as ready for reuse. * Note that the info and handle musr correspond and that info is locked. */ static void v_handleInvalidate ( v_handle handle, v_handleInfo *info) { v_handleServer server; c_object entity; server = v_handleServer((c_object)handle.server); assert(C_TYPECHECK(server,v_handleServer)); if (server) { c_mutexLock(&server->mutex); info->nextFree = server->firstFree; server->firstFree = handle.index; info->serial = (info->serial + 1) % MAXSERIAL; entity = info->object; info->object = NULL; c_mutexUnlock(&server->mutex); c_mutexUnlock(&info->mutex); v_publicDispose(v_public(entity)); } }