/************************************************************** * 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); }
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; }
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)); }
void v_observerInit( v_observer o, const c_char *name, v_statistics s, c_bool enable) { assert(o != NULL); assert(C_TYPECHECK(o,v_observer)); c_mutexInit(&o->mutex,SHARED_MUTEX); /* mutex to protect attributes */ c_condInit(&o->cv, &o->mutex, SHARED_COND); /* condition variable */ o->waitCount = 0; /* number of waiting threads */ o->eventMask = 0; /* specifies, interested events */ o->eventFlags = 0; /* ocurred events */ o->eventData = NULL; /* general post box for derived classes */ v_observableInit(v_observable(o),name, s, enable); }
v_deliveryWaitList v_deliveryWaitListNew( v_deliveryGuard _this, v_message msg) { v_deliveryWaitList waitlist = NULL; v_deliveryWaitList found; c_type type; assert(C_TYPECHECK(_this,v_deliveryGuard)); if (_this) { /* lookup or create a writer specific admin. */ type = c_subType(_this->waitlists); waitlist = c_new(type); c_free(type); if (waitlist) { waitlist->sequenceNumber = msg->sequenceNumber; waitlist->readerGID = copyReaderGIDsFromPublications(_this); waitlist->guard = _this; c_mutexInit(&waitlist->mutex, SHARED_MUTEX); c_condInit(&waitlist->cv, &waitlist->mutex, SHARED_COND); } found = c_tableInsert(_this->waitlists, waitlist); if (found != waitlist) { /* This should not happen! */ OS_REPORT(OS_ERROR, "v_deliveryWaitListNew",0, "detected inconsistent waitlist admin."); c_free(waitlist); waitlist = NULL; } } else { OS_REPORT(OS_ERROR, "v_deliveryWaitListNew",0, "Operation failed: illegal parameter (_this == NULL)."); } return waitlist; }
v_networkQueue v_networkQueueNew( c_base base, c_ulong queueSize, c_ulong priority, c_bool reliable, c_bool P2P, c_time resolution, v_networkQueueStatistics statistics) { v_networkQueue result = NULL; c_type type; c_equality equality; c_bool hasChanged; c_time now; type = c_resolve(base, "kernelModule::v_networkQueue"); assert(type); result = v_networkQueue(c_new(type)); c_free(type); if (result) { /* Queue properties */ result->maxMsgCount = queueSize; result->currentMsgCount = 0; /* Cached type */ result->statusMarkerType = c_resolve(base, "kernelModule::v_networkStatusMarker"); assert(result->statusMarkerType != NULL); result->sampleType = c_resolve(base, "kernelModule::v_networkQueueSample"); assert(result->sampleType != NULL); /* Linked list of in-use marker items */ result->firstStatusMarker = NULL; result->lastStatusMarker = NULL; /* Linked list of free marker and message items */ result->freeStatusMarkers = NULL; result->freeSamples = NULL; /* Init cv stuff */ c_mutexInit(&result->mutex, SHARED_MUTEX); c_condInit(&result->cv, &result->mutex, SHARED_COND); /* Currently no differentiation wrt qos */ result->priority = priority; result->reliable = reliable; result->P2P = P2P; result->statistics = statistics; equality = c_timeCompare(C_TIME_ZERO, resolution); if (equality == C_EQ) { result->periodic = FALSE; result->resolution = C_TIME_INFINITE; result->msecsResolution = 0xFFFFFFFF; result->phaseMilliSeconds = 0; result->nextWakeup = C_TIME_INFINITE; } else { assert(equality == C_LT); result->periodic = TRUE; result->resolution = resolution; TIME_TO_MSEC(resolution, result->msecsResolution); /* A semi-random phase to avoid wake-ups at the same time */ now = v_timeGet(); result->phaseMilliSeconds = ((c_ulong)(now.nanoseconds/1000000 * 1.618)) % result->msecsResolution; v_networkQueueUpdateNextWakeup(result, &hasChanged); assert(hasChanged); } result->threadWaiting = FALSE; } else { OS_REPORT(OS_ERROR, "v_networkQueueNew",0, "Failed to allocate network queue."); } return result; }