/* Walk admin namespaces */ static void areFellowNameSpacesCompatible( d_nameSpace adminNs, c_voidp args) { struct compatibilityHelper* walkData; d_networkAddress address; char* localPartitions; char* remotePartitions; walkData = (struct compatibilityHelper*)args; walkData->ns = adminNs; if (!d_fellowNameSpaceWalk(walkData->fellow, isFellowNameSpaceCompatible, walkData)) { walkData->compatible = FALSE; localPartitions = d_nameSpaceGetPartitions(adminNs); remotePartitions = d_nameSpaceGetPartitions(walkData->fellowNs); address = d_fellowGetAddress (walkData->fellow); OS_REPORT_2(OS_ERROR, D_CONTEXT, 0, "Namespace '%s' from fellow '%d' is incompatible with local namespace.", d_nameSpaceGetName(adminNs), address->systemId); OS_REPORT_2(OS_ERROR, D_CONTEXT, 0, "Partition expressions are '%s'(local) and '%s'(remote).", localPartitions, remotePartitions); d_networkAddressFree(address); os_free (localPartitions); os_free (remotePartitions); } }
u_result u_subscriberDeleteContainedEntities ( u_subscriber _this) { u_result result; u_reader reader; c_iter list; if (_this != NULL) { result = u_entityLock(u_entity(_this)); if (result == U_RESULT_OK) { list = _this->readers; _this->readers = NULL; /* Unlock here because following code will take this lock. */ u_entityUnlock(u_entity(_this)); reader = c_iterTakeFirst(list); while (reader) { switch (u_entityKind(u_entity(reader))) { case U_READER: result = u_dataReaderDeleteContainedEntities(u_dataReader(reader)); result = u_dataReaderFree(u_dataReader(reader)); break; case U_GROUPQUEUE: result = u_groupQueueFree(u_groupQueue(reader)); break; case U_DATAVIEW: result = u_dataViewFree(u_dataView(reader)); break; case U_NETWORKREADER: result = u_networkReaderFree(u_networkReader(reader)); break; default: OS_REPORT_2(OS_WARNING, "u_subscriberDeleteContainedEntities",0, "invalid object type: " "For Subscriber = 0x%x, found Reader type = %s.", _this, u_kindImage(u_entityKind(u_entity(reader)))); assert(0); break; } u_entityDereference(u_entity(_this)); reader = c_iterTakeFirst(list); } c_iterFree(list); } else { OS_REPORT_2(OS_WARNING, "u_subscriberDeleteContainedEntities",0, "Operation u_entityLock failed: " "Subscriber = 0x%x, result = %s.", _this, u_resultImage(result)); } } else { OS_REPORT(OS_WARNING, "u_subscriberDeleteContainedEntities",0, "Invalid Subscriber <NULL>."); result = U_RESULT_ILL_PARAM; } return result; }
static void u__userDetach( void) { u_user u; u_domain domain; u_result r; c_long i; u = u__userLock(); if (u) { /* Disable access to user-layer for all other threads except for this thread. * Any following user access from other threads is gracefully * aborted. */ u->detachThreadId = os_threadIdSelf(); /* Unlock the user-layer * Part of following code requires to unlock the user object * This is allowed now all other threads will abort when * trying to claim the lock */ u__userUnlock(); for (i = 1; (i <= u->domainCount); i++) { domain = u->domainList[i].domain; if (domain) { r = u_domainDetachParticipants(domain); if (r != U_RESULT_OK) { OS_REPORT_2(OS_ERROR, "user::u_user::u_userDetach", 0, "Operation u_domainDetachParticipants(0x%x) failed." OS_REPORT_NL "result = %s", domain, u_resultImage(r)); } else { r = u_domainFree(domain); if (r != U_RESULT_OK) { OS_REPORT_2(OS_ERROR, "user::u_user::u_userDetach", 0, "Operation u_domainFree(0x%x) failed." OS_REPORT_NL "result = %s", domain, u_resultImage(r)); } } } } /* user = NULL; * ES: This was set to NULL here by RP, but this causes errors later on * when u_userExit is performed. So commented this out here. As I can * not explain why we would need to set it to NULL here. */ } }
u_result u_serviceFree( u_service _this) { u_result result; c_bool destroy; result = u_entityLock(u_entity(_this)); if (result == U_RESULT_OK) { destroy = u_entityDereference(u_entity(_this)); /* if refCount becomes zero then this call * returns true and destruction can take place */ if (destroy) { if (u_entityOwner(u_entity(_this))) { result = u_serviceDeinit(_this); } else { /* This user entity is a proxy, meaning that it is not fully * initialized, therefore only the entity part of the object * can be deinitialized. * It would be better to either introduce a separate proxy * entity for clarity or fully initialize entities and make * them robust against missing information. */ result = u_entityDeinit(u_entity(_this)); } if (result == U_RESULT_OK) { u_entityDealloc(u_entity(_this)); } else { OS_REPORT_2(OS_WARNING, "u_serviceFree",0, "Operation u_serviceDeinit failed: " "Service = 0x%x, result = %s.", _this, u_resultImage(result)); u_entityUnlock(u_entity(_this)); } } else { u_entityUnlock(u_entity(_this)); } } else { OS_REPORT_2(OS_WARNING, "u_serviceFree",0, "Operation u_entityLock failed: " "Service = 0x%x, result = %s.", _this, u_resultImage(result)); } return result; }
/** \brief Release the acquired mutex * * \b os_mutexUnlock calls \b pthread_mutex_unlock to release * the posix \b mutex. */ os_result os_mutexUnlock ( os_mutex *mutex) { int result; os_result rv; assert (mutex != NULL); #ifdef OSPL_STRICT_MEM assert(mutex->signature == OS_MUTEX_MAGIC_SIG); result = pthread_mutex_unlock (&mutex->mutex); #else result = pthread_mutex_unlock (mutex); #endif if (result == 0) { rv= os_resultSuccess; } else { OS_REPORT_2(OS_ERROR,"os_mutexUnlock",0, "Operation failed: mutex 0x%x, result = %s", mutex, strerror(result)); assert(OS_FALSE); rv= os_resultFail; } return rv; }
jni_result jni_writerWrite( jni_writer wri, const c_char* xmlUserData) { jni_result r; jni_writerCopyArg copyArg; sd_validationResult valResult; if( (wri == NULL) || (xmlUserData == NULL) || (wri->uwriter == NULL) || (xmlUserData == NULL)){ r = JNI_RESULT_BAD_PARAMETER; } else{ copyArg = os_malloc(C_SIZEOF(jni_writerCopyArg)); copyArg->writer = wri; copyArg->xmlData = xmlUserData; r = jni_convertResult(u_writerWrite(wri->uwriter, copyArg, u_timeGet(), U_INSTANCEHANDLE_NIL)); valResult = sd_serializerLastValidationResult(wri->deserializer); if(valResult != SD_VAL_SUCCESS){ OS_REPORT_2(OS_ERROR, CONT_DCPSJNI, 0, "Write of userdata failed.\nReason: %s\nError: %s\n", sd_serializerLastValidationMessage(wri->deserializer), sd_serializerLastValidationLocation(wri->deserializer)); r = JNI_RESULT_ERROR; } os_free(copyArg); } return r; }
/** * Read environment properties. In particular ones that can't be left until * there is a requirement to log. */ void os_reportInit(os_boolean forceReInit) { static os_boolean doneOnce = OS_FALSE; char *envValue; os_mutexAttr attr; os_result osr; if (!doneOnce || forceReInit) { if (!doneOnce) { osr = os_mutexAttrInit(&attr); if(osr == os_resultSuccess) { attr.scopeAttr = OS_SCOPE_PRIVATE; osr = os_mutexInit(&reportMutex, &attr); } if(osr != os_resultSuccess) { OS_REPORT(OS_WARNING, "os_reportInit", 0, "Unable to create report mutex"); } } doneOnce = OS_TRUE; envValue = os_getenv(os_env_verbosity); if (envValue != NULL) { if (os_reportSetVerbosity(envValue) == os_resultFail) { OS_REPORT_3(OS_WARNING, "os_reportInit", 0, "Cannot parse report verbosity %s value \"%s\"," " reporting verbosity remains %s", os_env_verbosity, envValue, os_reportTypeText[os_reportVerbosity]); } } if (os_procIsOpenSpliceDomainDaemon()) { /** @todo dds2881 - Change default to OS_FALSE ? */ doAppend = OS_TRUE; } envValue = os_getenv(os_env_append); if (envValue != NULL) { os_boolean shouldAppend; if (os_configIsTrue(envValue, &shouldAppend) == os_resultFail) { OS_REPORT_2(OS_WARNING, "os_reportInit", 0, "Cannot parse report %s value \"%s\"," " reporting append mode unchanged", os_env_append, envValue); } else { os_reportSetDoAppend(shouldAppend); } } } }
c_object c_checkType ( c_object o, const c_char *name) { c_type type; c_string str; c_bool found = FALSE; c_bool stop = FALSE; if (o == NULL) { return NULL; } c_assertValidDatabaseObject(o); assert(c_refCount(o) > 0); assert(name != NULL); type = c__getType(o); while (!found && !stop) { str = c_metaObject(type)->name; if (str == NULL) { found = TRUE; /** assume TRUE **/ } else if (strcmp(str,name) != 0) { switch (c_baseObject(type)->kind) { case M_CLASS: type = c_type(c_class(type)->extends); if (type == NULL) { if ((strcmp(str,"c_base") == 0) && (strcmp(name,"c_module") == 0)) { found = TRUE; } stop = TRUE; } break; case M_TYPEDEF: type = c_typeDef(type)->alias; if (type == NULL) { stop = TRUE; } break; default: stop = TRUE; } } else { found = TRUE; } } if (!found) { #ifndef NDEBUG if(o != NULL){ str = c_metaObject(c__getType(o))->name; OS_REPORT_2(OS_ERROR, "Database", 0, "Type mismatch: object type is %s but %s was expected\n", str,name); } #endif return NULL; } return o; }
u_groupQueue u_groupQueueNew( u_subscriber s, const c_char *name, c_ulong queueSize, v_readerQos qos) { u_participant p; u_groupQueue _this = NULL; v_subscriber ks = NULL; v_groupQueue kn; u_result result; if (name != NULL) { if (s != NULL) { result = u_entityWriteClaim(u_entity(s),(v_entity*)(&ks)); if (result == U_RESULT_OK) { assert(ks); kn = v_groupQueueNew(ks,name,queueSize,qos); if (kn != NULL) { p = u_entityParticipant(u_entity(s)); _this = u_entityAlloc(p,u_groupQueue,kn,TRUE); if (_this != NULL) { result = u_groupQueueInit(_this,s); if (result != U_RESULT_OK) { OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0, "Initialisation failed. " "For groupQueue: <%s>.", name); u_groupQueueFree(_this); } } else { OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0, "Create proxy failed. " "For groupQueue: <%s>.", name); } c_free(kn); } else { OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0, "Create kernel entity failed. " "For groupQueue: <%s>.", name); } result = u_entityRelease(u_entity(s)); } else { OS_REPORT_2(OS_WARNING, "u_groupQueueNew", 0, "Claim Subscriber (0x%x) failed. " "For groupQueue: <%s>.", s, name); } } else { OS_REPORT_1(OS_ERROR,"u_groupQueueNew",0, "No Subscriber specified. " "For groupQueue: <%s>", name); } } else { OS_REPORT(OS_ERROR,"u_groupQueueNew",0, "No name specified."); } return _this; }
c_bool u_cfDataSizeValueFromString( c_char *str, c_ulong *ul) { c_bool result; c_char *temp; c_char chp; c_ulong base,res,retval = 0; result = TRUE; assert(str); temp = os_malloc(strlen(str) +1); if (temp != NULL) { strcpy (temp,str); retval = sscanf(temp, "%u%c",&res, &chp); if (retval == 1) { base =1; } else if (retval == 2) { switch(chp) { case 'K': base = 1024; break; case 'M': base = pow(1024,2); break; case 'G': base = pow(1024,3); break; default: OS_REPORT_1(OS_ERROR, "u_cfDataSizeValueFromString", 0, "Invalid size specifier (%c)", chp); base =1; break; } } else { OS_REPORT_1(OS_ERROR, "u_cfDataSizeValueFromString", 0, "Invalid size value (%s)", str); res = 0; base = 1; } /* boundary checking */ if (res > C_MAX_ULONG(L)/base) { *ul = C_MAX_ULONG(L); OS_REPORT_2(OS_WARNING, "u_cfDataSizeValueFromString", 0, "Configuration parameter value (%s) exceeds maximum size ulong, value changed to %lu",str,C_MAX_ULONG(L)); } else { *ul = res*base; } os_free(temp); } else { result =0; OS_REPORT_1(OS_ERROR, "u_cfDataSizeValueFromString", 0, "Malloc failed for configuration parameter value (%s)", str); } return result; }
/** \brief Initialize the mutex taking the mutex attributes * into account * * \b os_mutexInit calls \b pthread_mutex_init to intialize the * posix \b mutex * * In case the scope attribute is \b OS_SCOPE_SHARED, the posix * mutex "pshared" attribute is set to \b PTHREAD_PROCESS_SHARED * otherwise it is set to \b PTHREAD_PROCESS_PRIVATE. */ os_result os_mutexInit ( os_mutex *mutex, const os_mutexAttr *mutexAttr) { pthread_mutexattr_t mattr; int result = 0; os_result rv; assert (mutex != NULL); assert (mutexAttr != NULL); #ifdef OSPL_STRICT_MEM assert (mutex->signature != OS_MUTEX_MAGIC_SIG); #endif pthread_mutexattr_init (&mattr); if (mutexAttr->scopeAttr == OS_SCOPE_SHARED) { result = pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED); } else { result = pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_PRIVATE); } #ifdef OSPL_PRIO_INHERIT_SUPPORTED /* only if priority inheritance is supported in the pthread lib */ if ((result == 0) && ospl_mtx_prio_inherit) { result = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); } #endif if (result == 0) { #ifdef OSPL_STRICT_MEM result = pthread_mutex_init (&mutex->mutex, &mattr); #else result = pthread_mutex_init (mutex, &mattr); if (result == EBUSY) { os_mutexDestroy (mutex); result = pthread_mutex_init (mutex, &mattr); } #endif } pthread_mutexattr_destroy (&mattr); if (result == 0) { rv = os_resultSuccess; #ifdef OSPL_STRICT_MEM mutex->signature = OS_MUTEX_MAGIC_SIG; #endif } else { OS_REPORT_2(OS_ERROR,"os_mutexInit",0, "Operation failed: mutex 0x%x, result = %s", mutex, strerror(result)); assert(OS_FALSE); rv = os_resultFail; } return rv; }
u_result u_topicFree( u_topic _this) { u_result result; c_bool destroy; result = u_entityLock(u_entity(_this)); if (result == U_RESULT_OK) { destroy = u_entityDereference(u_entity(_this)); /* if refCount becomes zero then this call * returns true and destruction can take place */ if (destroy) { result = u_topicDeinit(_this); if (result == U_RESULT_OK) { u_entityDealloc(u_entity(_this)); } else { OS_REPORT_2(OS_WARNING, "u_topicFree",0, "Operation u_topicDeinit failed: " "Topic = 0x%x, result = %s.", _this, u_resultImage(result)); u_entityUnlock(u_entity(_this)); } } else { u_entityUnlock(u_entity(_this)); } } else { OS_REPORT_2(OS_WARNING, "u_topicFree",0, "Operation u_entityLock failed: " "Topic = 0x%x, result = %s.", _this, u_resultImage(result)); } return result; }
os_result os_signalHandlerSetHandler( os_signal signal, os_actionHandler handler) { os_sigset mask; os_result result; os_sigaction action; int r; /* block all signals during handling of a signal */ result = os_sigsetFill(&mask); if (result != os_resultSuccess) { OS_REPORT_2(OS_ERROR, "os_signalHandlerInit", 0, "os_sigsetFill(0x%x) failed, result = %d", &action.sa_mask, result); } else { action = os_sigactionNew(handler, &mask, SA_SIGINFO); } if (result == os_resultSuccess) { r = os_sigsetDel(&action.sa_mask, signal); if (r < 0) { OS_REPORT_3(OS_ERROR, "os_signalHandlerInit", 0, "os_sigsetDel(0x%x, %d) failed, result = %d", &action, signal, r); result = os_resultFail; assert(OS_FALSE); } } if (result == os_resultSuccess) { r = os_sigactionSet(signal, &action, &old_signalHandler[signal]); if (r < 0) { OS_REPORT_4(OS_ERROR, "os_signalHandlerInit", 0, "os_sigactionSet(%d, 0x%x, 0x%x) failed, result = %d", signal, &action, &old_signalHandler[signal], r); result = os_resultFail; assert(OS_FALSE); } } return result; }
void v_checkMaxSamplesPerInstanceWarningLevel( v_kernel _this, c_ulong count) { if(count >= _this->maxSamplesPerInstanceWarnLevel && !_this->maxSamplesPerInstanceWarnShown) { OS_REPORT_2(OS_WARNING, "v_checkMaxSamplesPerInstanceWarningLevel",0, "The number of samples per instance '%d' has surpassed the " "warning level of '%d' samples per instance.", count, _this->maxSamplesPerInstanceWarnLevel); _this->maxSamplesPerInstanceWarnShown = TRUE; } }
void cmx_writerUnregisterCopy( v_entity entity, c_voidp args) { v_writer kw; v_message message; void *to; sd_serializer ser; sd_serializedData data; sd_validationResult valResult; struct cmx_writerArg *arg; arg = (struct cmx_writerArg *)args; kw = v_writer(entity); message = v_topicMessageNew(kw->topic); to = C_DISPLACE(message,v_topicDataOffset(kw->topic)); ser = sd_serializerXMLNewTyped(v_topicDataType(kw->topic)); data = sd_serializerFromString(ser, arg->result); sd_serializerDeserializeIntoValidated(ser, data, to); valResult = sd_serializerLastValidationResult(ser); if(valResult != SD_VAL_SUCCESS){ OS_REPORT_2(OS_ERROR, CM_XML_CONTEXT, 0, "Unregister of userdata failed.\nReason: %s\nError: %s\n", sd_serializerLastValidationMessage(ser), sd_serializerLastValidationLocation(ser)); arg->success = CMX_RESULT_FAILED; } else { arg->success = CMX_RESULT_OK; } sd_serializedDataFree(data); sd_serializerFree(ser); /* Note that the last param of v_writerWriteDispose is NULL, performance can be improved if the instance is provided. */ v_writerUnregister(kw,message,v_timeGet(),NULL); c_free(message); }
static void checkTopicKeyList ( v_entity e, c_voidp arg) { c_array keyList = v_topicMessageKeyList(e); checkTopicKeyListArg *info = (checkTopicKeyListArg *) arg; c_long i; gapi_char *name; c_long size; c_iter iter; gapi_boolean equal = TRUE; iter = c_splitString(info->keyList, " \t,"); if ( iter ) { size = c_arraySize(keyList); for ( i = 0; equal && (i < size); i++ ) { name = (gapi_char *)c_iterResolve(iter, topicKeyCompare, keyNameFromField(keyList[i])); if ( !name ) { equal = FALSE; OS_REPORT_2(OS_API_INFO, "gapi::kernelCheckTopicKeyList", 0, "incompatible key <%s> found for topic <%s>", keyNameFromField(keyList[i]), v_entityName(e)); } } name = c_iterTakeFirst(iter); while ( name ) { os_free(name); name = c_iterTakeFirst(iter); } c_iterFree(iter); } info->equal = equal; }
void gapi_typeParseError ( sd_errorReport report) { if ( report ) { if ( report->message ) { if ( report->location ) { OS_REPORT_3(OS_API_INFO, TYPEPARSE_CONTEXT, 0, "%s : %s at %s", TYPEPARSE_ERROR, report->message, report->location); } else { OS_REPORT_2(OS_API_INFO, TYPEPARSE_CONTEXT, 0, "%s : %s", TYPEPARSE_ERROR, report->message); } } else { OS_REPORT(OS_API_INFO, TYPEPARSE_CONTEXT, 0, TYPEPARSE_ERROR); } } else { OS_REPORT(OS_API_INFO, TYPEPARSE_CONTEXT, 0, TYPEPARSE_ERROR); } }
u_result u_subscriberInit( u_subscriber _this, u_participant p) { u_result result; if (_this != NULL) { result = u_dispatcherInit(u_dispatcher(_this)); if (result == U_RESULT_OK) { _this->readers = NULL; _this->participant = p; result = u_participantAddSubscriber(p,_this); } } else { OS_REPORT_2(OS_ERROR, "u_subscriberInit",0, "Illegal parameter: _this = 0x%x, participant = 0x%x.", _this,p); result = U_RESULT_ILL_PARAM; } return result; }
u_result u_topicDeinit( u_topic _this) { u_result result; if (_this != NULL) { result = u_participantRemoveTopic(_this->participant, _this); if (result == U_RESULT_OK) { result = u_dispatcherDeinit(u_dispatcher(_this)); if (result == U_RESULT_OK) { if (_this->name) { os_free(_this->name); _this->name = NULL; } } else { OS_REPORT_1(OS_WARNING, "u_topicDeinit", 0, "Operation u_dispatcherDeinit failed. " "Topic = 0x%x", _this); } } else { OS_REPORT_2(OS_WARNING, "u_topicDeinit", 0, "The Topic (0x%x) could not be removed " "from the Participant (0x%x).", _this, _this->participant); } } else { OS_REPORT(OS_ERROR, "u_topicDeinit", 0, "Illegal parameter: Topic == NULL."); result = U_RESULT_ILL_PARAM; } return result; }
u_group u_groupNew( u_participant participant, const c_char *partitionName, const c_char *topicName, v_duration timeout) { u_result r; v_participant kparticipant; v_kernel kernel; v_topic ktopic; v_partition kpartition; v_group kgroup; c_iter topics; os_time delay; u_group group = NULL; if ((partitionName != NULL) && (topicName != NULL)) { if (participant != NULL) { r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant)); if (r == U_RESULT_OK){ assert(kparticipant); kernel = v_objectKernel(kparticipant); topics = v_resolveTopics(kernel,topicName); if (c_iterLength(topics) == 0) { c_iterFree(topics); delay.tv_sec = timeout.seconds; delay.tv_nsec = timeout.nanoseconds; os_nanoSleep(delay); topics = v_resolveTopics(v_objectKernel(kparticipant), topicName); } if (c_iterLength(topics) > 1) { OS_REPORT_1(OS_WARNING, "u_groupNew", 0, "Internal error: " "Multiple topics found with name = <%s>.", topicName); } ktopic = c_iterTakeFirst(topics); /* If ktopic == NULL, the topic definition is unknown. * This is not critical since it may become known in the near future. * In that case the caller is responsible for retrying to create this group, * and log something if, eventually, the group still cannot be created. */ if (ktopic != NULL) { kpartition = v_partitionNew(kernel, partitionName, NULL); if (kpartition != NULL) { kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic); if (kgroup != NULL) { group = u_groupCreate(kgroup, participant); if (group == NULL) { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create proxy failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kgroup); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create kernel entity failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kpartition); } else { OS_REPORT_2(OS_ERROR,"u_groupNew", 0, "Failed to create partition. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(ktopic); } ktopic = c_iterTakeFirst(topics); while (ktopic != NULL) { c_free(ktopic); ktopic = c_iterTakeFirst(topics); } c_iterFree(topics); r = u_entityRelease(u_entity(participant)); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Claim kernel participant failed." "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "No participant specified. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Illegal parameter." "partitionName = <0x%x>, topicName = <0x%x>.", partitionName, topicName); } return group; }
/* See header-file for */ unsigned int DDS::DataReader_impl::set_ParallelReadThreadCount( unsigned int value ) { DDS::ReturnCode_t exc = DDS::RETCODE_OK; if(os_mutexLock(&dr_mutex) != os_resultSuccess) { OS_REPORT(OS_FATAL, "CCPP", 0, "Failed to claim mutex"); exc = DDS::RETCODE_ERROR; goto fatal_mtx; } if(pdc){ /* Signal eventual current threads to shutdown */ pdc_terminateWorkers(pdc); /* Join threads */ pdc_joinWorkers(workers, nrofWorkers); /* Assert that all threads are actually stopped, so the terminate flag is * reset (last one to stop will do this). */ assert(pdc->terminate == 0); delete workers; workers = NULL; /* If the requested size is 0 or 1, this will both result in a single-threaded * copy, so we don't have to start any extra threads. If previously there * were threads created, we can now cleanup the context as well. */ if(value <= 1){ delete pdc; pdc = NULL; } } if(value > 1){ if(!pdc){ /* Create a parallelDemarshalling context. */ try{ if((pdc = new ccpp_parDemContext()) == NULL) { exc = DDS::RETCODE_OUT_OF_RESOURCES; goto err_out_of_resources; } } catch (::DDS::ReturnCode_t e){ exc = e; goto err_out_of_resources; } } os_threadAttr thrAttrs; os_result result; if((result = os_threadAttrInit(&thrAttrs)) != os_resultSuccess){ exc = DDS::RETCODE_ERROR; goto err_thr_attrs; } if((workers = new os_threadId[value - 1]) == NULL){ exc = DDS::RETCODE_OUT_OF_RESOURCES; goto err_workers_alloc; } assert(pdcMainFnc); assert(nrofWorkers == 0); for(nrofWorkers = 0; nrofWorkers < (value - 1); nrofWorkers++){ result = os_threadCreate( &workers[nrofWorkers], "parDemWorker", /* TODO: pretty name */ &thrAttrs, pdcMainFnc, (void*)pdc); if(result != os_resultSuccess){ nrofWorkers--; /* If a thread was started (nrofWorkers > 0), then something * happened and we warn that not all threads could be started * (probably due to out of resources condition). * If no threads were started at all, an error occurred. */ OS_REPORT_2(nrofWorkers ? OS_WARNING : OS_ERROR, "CCPP", result, "Starting a parallel demarshalling worker thread failed; %d out of %d requested threads are available for parallel demarshalling.", nrofWorkers + 1, value); if(nrofWorkers == 0) { exc = DDS::RETCODE_ERROR; goto err_thread_start; } else { break; } } } } os_mutexUnlock(&dr_mutex); /* When a ParallelReadThreadCount of x is requested only x - 1 threads are * started, since the application thread is performing read actions as well */ return nrofWorkers + 1; /* Error handling */ err_thread_start: err_workers_alloc: err_thr_attrs: err_out_of_resources: os_mutexUnlock(&dr_mutex); fatal_mtx: assert(exc != DDS::RETCODE_OK); throw exc; }
jni_writer jni_writerNew( jni_publisher pub, jni_topic top, v_writerQos qos) { jni_writer wri; u_result ur; struct jni_writerTypeArg arg; if((pub == NULL) || (top == NULL)){ OS_REPORT_2(OS_ERROR, "jni_writerNew", 0, "Bad parameter; jni_publisher (%p) and jni_topic (%p) may not be NULL.", pub, top); goto err_badParam; } assert(pub->upublisher); assert(top->utopic); if((ur = u_entityAction(u_entity(top->utopic), jni_writerTypeAction, &arg)) != U_RESULT_OK){ OS_REPORT_1(OS_ERROR, "jni_writerNew", ur, "Failed to invoke jni_writerTypeAction(...) on top->utopic; u_entityAction(...) returned %s.", u_resultImage(ur)); goto err_getWriterType; } if(arg.type == NULL){ /* Error reported by jni_writerTypeAction */ goto err_getWriterType; } if((wri = os_malloc(sizeof *wri)) == NULL){ OS_REPORT_1(OS_ERROR, "jni_writerNew", 0, "Memory claim of %" PA_PRIuSIZE " denied.", sizeof *wri); goto err_malloc; } if((wri->deserializer = sd_serializerXMLNewTyped(arg.type)) == NULL){ /* Error reported by sd_serializerXMLNewTyped */ goto err_sd_serializerXMLNewTyped; } if((wri->uwriter = u_writerNew(pub->upublisher, NULL, top->utopic, jni_writerCopy, qos, TRUE)) == NULL){ /* Error reported by u_writerNew */ goto err_uwriterNew; } wri->publisher = pub; wri->topic = top; return wri; /* Error handling */ err_uwriterNew: sd_serializerFree(wri->deserializer); err_sd_serializerXMLNewTyped: os_free(wri); err_malloc: /* No undo for jni_writerTypeAction */ err_getWriterType: err_badParam: return NULL; }
static int lockPages( v_kernel k, const c_char *name) { v_configuration cfg; v_cfElement root; v_cfElement service; v_cfData data; int lock; c_char *path; c_iter iter; int iterLength; c_value value; assert(k); lock = 0; cfg = v_getConfiguration(k); if (cfg != NULL) { root = v_configurationGetRoot(cfg); if (root != NULL) { path = (c_char *)os_malloc(strlen(SERVICE_PATH) + strlen(name)); /* NULL terminator is covered by '%s' in SERVICE_PATH constant */ os_sprintf(path, SERVICE_PATH, name); iter = v_cfElementXPath(root, path); iterLength = c_iterLength(iter); os_free(path); if (iterLength == 1) { service = v_cfElement(c_iterTakeFirst(iter)); c_iterFree(iter); iter = v_cfElementXPath(service, "Locking/#text"); iterLength = c_iterLength(iter); if (iterLength == 1) { data = v_cfData(c_iterTakeFirst(iter)); if (u_cfValueScan(v_cfDataValue(data), V_BOOLEAN, &value)) { if (value.is.Boolean) { lock = 1; OS_REPORT_1(OS_INFO,"lockPages", 0, "service '%s': Locking enabled", name); } } else { OS_REPORT_1(OS_WARNING,"lockPages", 0, "Failed to retrieve Locking for service '%s': Locking disabled", name); } } } else if (iterLength > 1) { OS_REPORT_2(OS_WARNING,"lockPages", 0, "Multiple configuration found for service '%s' (too many: %d): Locking disabled", name, iterLength); } else { OS_REPORT_1(OS_WARNING,"lockPages", 0, "Could not get configuration for service '%s' (non-existent): Locking disabled", name); } c_iterFree(iter); c_free(root); } } return lock; }
void u_userExit( void) { u_user u; u_domain domain; os_result mr = os_resultFail; u_result r; c_long i; u = u__userLock(); if (u) { /* Disable access to user-layer for all other threads except for this thread. * Any following user access from other threads is gracefully * aborted. */ u->detachThreadId = os_threadIdSelf(); /* Unlock the user-layer * Part of following code requires to unlock the user object * This is allowed now all other threads will abort when * trying to claim the lock */ u__userUnlock(); for (i = 1; (i <= u->domainCount); i++) { domain = u->domainList[i].domain; if (domain) { r = u_domainDetachParticipants(domain); if (r != U_RESULT_OK) { OS_REPORT_2(OS_ERROR, "user::u_user::u_userExit", 0, "Operation u_domainDetachParticipants(0x%x) failed." OS_REPORT_NL "result = %s", domain, u_resultImage(r)); } else { r = u_domainFree(domain); if (r != U_RESULT_OK) { OS_REPORT_2(OS_ERROR, "user::u_user::u_userExit", 0, "Operation u_domainFree(0x%x) failed." OS_REPORT_NL "result = %s", domain, u_resultImage(r)); } } } } user = NULL; /* Destroy the user-layer mutex */ mr = os_mutexDestroy(&u->mutex); if(mr != os_resultSuccess){ OS_REPORT_1(OS_ERROR, "user::u_user::u_userExit",0, "Operation os_mutexDestroy(0x%x) failed:" OS_REPORT_NL "os_result == %d.", mr); } /* Free the user-object */ os_free(u); } /* Even if access to the user layer is denied, we still need to cleanup * the signal handler, which includes waiting for the threads to exit * the DDS database */ os_signalHandlerFree(); /* De-init the OS-abstraction layer */ os_osExit(); }
static v_networkQueue v_networkReaderSelectBestQueueIgnoreReliability( v_networkReader reader, v_messageQos qos, c_bool requiresP2P, const char *partitionName, const char *topicName) { unsigned int n; v_networkQueue currentQueue; v_networkQueue bestQueue = NULL; v_networkQueue possiblyBestQueue = NULL; v_networkQueue bestAlternativeQueue = NULL; c_bool P2PMatches = FALSE; c_ulong prio,queuePrio; assert(reader != NULL); assert(C_TYPECHECK(reader, v_networkReader)); assert(qos != NULL); assert(partitionName != NULL); assert(topicName != NULL); /* Transform kernel prio to networking prio */ if (v_messageQos_getTransportPriority(qos) >= 0) { prio = (c_ulong)v_messageQos_getTransportPriority(qos); } else { prio = 0; } /* First select the best queue */ for (n=0; (n<reader->nofQueues) && (bestQueue == NULL); ++n) { currentQueue = reader->queues[n]; P2PMatches = (requiresP2P == v_networkQueueP2P(currentQueue)); if (P2PMatches) { queuePrio = v_networkQueuePriority(currentQueue); if (prio == queuePrio) { /* An exact match! Stop here */ bestQueue = currentQueue; } else { if (prio < queuePrio) { /* This queue might be the best fit, it offers higher prio * than requested */ if (possiblyBestQueue != NULL) { if (queuePrio < possiblyBestQueue->priority) { possiblyBestQueue = currentQueue; } } else { possiblyBestQueue = currentQueue; } } if (possiblyBestQueue == NULL) { /* No queue fits until now, but this queue * might be the best alternative if no queue * offers the requested prio at all */ if (bestAlternativeQueue != NULL) { if (queuePrio > bestAlternativeQueue->priority) { bestAlternativeQueue = currentQueue; } } else { bestAlternativeQueue = currentQueue; } } } } } if (bestQueue == NULL) { bestQueue = possiblyBestQueue; } if (bestQueue == NULL) { bestQueue = bestAlternativeQueue; } if (bestQueue == NULL) { OS_REPORT_2(OS_WARNING, "v_networkReaderSelectBestQueue", 0, "Unable to select best fitting queue for partition \"%s\", " "topic \"%s\". Switching to default", partitionName, topicName); bestQueue = reader->defaultQueue; } return bestQueue; }
static v_networkQueue v_networkReaderSelectBestQueueByReliability( v_networkReader reader, v_messageQos qos, c_bool requiresP2P, const char *partitionName, const char *topicName) { unsigned int n; v_networkQueue currentQueue; v_networkQueue bestQueue = NULL; v_networkQueue possiblyBestQueue = NULL; v_networkQueue bestAlternativeQueue = NULL; c_bool reliabilityMatches = FALSE; c_bool P2PMatches = FALSE; c_bool reliable; c_ulong prio,queuePrio; assert(reader != NULL); assert(C_TYPECHECK(reader, v_networkReader)); assert(qos != NULL); assert(partitionName != NULL); assert(topicName != NULL); /* Transform kernel prio to networking prio */ prio = v_messageQos_getTransportPriority(qos); reliable = v_messageQos_isReliable(qos); /* First select the best queue */ if (prio < NW_MAX_QUEUE_CACHE_PRIO) { if (reliable) { bestQueue = reader->queueCache[prio+NW_MAX_QUEUE_CACHE_PRIO]; } else { bestQueue = reader->queueCache[prio]; } } if (!bestQueue) { for (n=0; (n<reader->nofQueues) && (bestQueue == NULL); n++) { currentQueue = reader->queues[n]; /* Check on reliability */ if (reliable) { reliabilityMatches = v_networkQueueReliable(currentQueue); } else { reliabilityMatches = !v_networkQueueReliable(currentQueue); } P2PMatches = (requiresP2P == v_networkQueueP2P(currentQueue)); if (reliabilityMatches && P2PMatches) { queuePrio = v_networkQueuePriority(currentQueue); if (prio == queuePrio) { /* An exact match! Stop here */ bestQueue = currentQueue; } else { if (prio < queuePrio) { /* This queue might be the best fit, it offers higher prio * than requested */ if (possiblyBestQueue != NULL) { if (queuePrio < possiblyBestQueue->priority) { possiblyBestQueue = currentQueue; } } else { possiblyBestQueue = currentQueue; } } if (possiblyBestQueue == NULL) { /* No queue fits until now, but this queue * might be the best alternative if no queue * offers the requested prio at all */ if (bestAlternativeQueue != NULL) { if (queuePrio > bestAlternativeQueue->priority) { bestAlternativeQueue = currentQueue; } } else { bestAlternativeQueue = currentQueue; } } } } } if (bestQueue == NULL) { bestQueue = possiblyBestQueue; } if (bestQueue == NULL) { bestQueue = bestAlternativeQueue; } if (bestQueue == NULL) { OS_REPORT_2(OS_WARNING, "v_networkReaderSelectBestQueue", 0, "Unable to select best fitting queue for partition \"%s\", " "topic \"%s\". Switching to default", partitionName, topicName); bestQueue = reader->defaultQueue; } if (prio < NW_MAX_QUEUE_CACHE_PRIO) { /* Store found bestQueue in the cache, while maintaining * correct reference counts on the Queues */ if (reliable) { c_free(reader->queueCache[prio+NW_MAX_QUEUE_CACHE_PRIO]); reader->queueCache[prio+NW_MAX_QUEUE_CACHE_PRIO] = c_keep(bestQueue); } else { c_free(reader->queueCache[prio]); reader->queueCache[prio] = c_keep(bestQueue); } } } return bestQueue; }
d_storeResult d_groupInfoInject( d_groupInfo _this, const d_store store, u_participant participant, d_group* group) { d_storeResult result; u_group ugroup; u_partition upartition; v_partitionQos partitionQos; v_duration timeout; c_string name; if(_this && store && participant){ result = d_topicInfoInject(_this->topic, store, participant); if(result == D_STORE_RESULT_OK){ partitionQos = u_partitionQosNew(NULL); if(partitionQos) { d_storeReport(store, D_LEVEL_FINE, "PartitionQoS created.\n"); upartition = u_partitionNew(participant, _this->partition, partitionQos); if(upartition) { name = d_topicInfoGetName(_this->topic); d_storeReport(store, D_LEVEL_FINE, "Partition %s created.\n", _this->partition); timeout.seconds = 0; timeout.nanoseconds = 0; ugroup = u_groupNew(participant, _this->partition, name, timeout); if(ugroup) { d_storeReport(store, D_LEVEL_INFO, "Group %s.%s created.\n", _this->partition, name); *group = d_groupNew(_this->partition, name, D_DURABILITY_PERSISTENT, _this->completeness, _this->quality); u_entityAction(u_entity(ugroup), setKernelGroup, *group); u_entityFree(u_entity(ugroup)); result = D_STORE_RESULT_OK; } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "Group %s.%s could NOT be created.\n", _this->partition, name); OS_REPORT_2(OS_ERROR, "d_groupInfoInject", (os_int32)result, "Group %s.%s could NOT be created.\n", _this->partition, name); } c_free(name); u_partitionFree(upartition); } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "Partition %s could NOT be created.\n", _this->partition); OS_REPORT_1(OS_ERROR, "d_groupInfoInject", (os_int32)result, "Partition %s could NOT be created.\n", _this->partition); } u_partitionQosFree(partitionQos); } else { result = D_STORE_RESULT_OUT_OF_RESOURCES; d_storeReport(store, D_LEVEL_SEVERE, "PartitionQos could NOT be created.\n"); OS_REPORT(OS_ERROR, "d_groupInfoInject", (os_int32)result, "PartitionQos could NOT be created.\n"); } } } else { result = D_STORE_RESULT_ILL_PARAM; } return result; }
_Subscriber _BuiltinSubscriberNew ( u_participant uParticipant, _DomainParticipantFactory factory, _DomainParticipant participant) { u_subscriber s; _Status status; _Subscriber newSubscriber = _SubscriberAlloc(); gapi_handle handle; _TypeSupport typeSupport; gapi_dataReaderQos rQos; long i; s = u_participantGetBuiltinSubscriber(uParticipant); if (s) { newSubscriber = _SubscriberAlloc(); if (newSubscriber != NULL) { _EntityInit(_Entity(newSubscriber), _Entity(participant)); U_SUBSCRIBER_SET(newSubscriber, s); status = _StatusNew(_Entity(newSubscriber), STATUS_KIND_SUBSCRIBER, NULL, 0); if (status) { for ( i = 0; i < MAX_BUILTIN_TOPIC; i++ ) { _DataReader reader = NULL; _Topic topic = NULL; typeSupport = _DomainParticipantFindTypeSupport(participant, _BuiltinTopicTypeName(i)); if (typeSupport) { c_iter uTopicList; u_topic uTopic; uTopicList = u_participantFindTopic(uParticipant, _BuiltinTopicName(i), C_TIME_ZERO); uTopic = c_iterTakeFirst(uTopicList); if (uTopic) { topic = _TopicFromKernelTopic(uTopic, _BuiltinTopicName(i), _BuiltinTopicTypeName(i), typeSupport, participant, NULL); while (uTopic) { uTopic = c_iterTakeFirst(uTopicList); /* multiple instances should not occure but * just in case this loop frees all references. */ assert(uTopic == NULL); u_entityFree(u_entity(uTopic)); } } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "failed to resolve User layer Topic " "'%s' for Participant 0x%x", _BuiltinTopicName(i), participant); } } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "Builtin TypeSupport for type '%s' is not " "yet registered for Participant 0x%x", _BuiltinTopicTypeName(i), participant); } if (topic) { initBuiltinDataReaderQos(&rQos); reader = _DataReaderNew(_TopicDescription(topic), typeSupport, &rQos, NULL, 0, newSubscriber); _EntityRelease(topic); } else { OS_REPORT_2(OS_WARNING,"_BuiltinSubscriberNew",0, "failed to create Builtin Topic '%s' " "for Participant 0x%x", _BuiltinTopicName(i), participant); } if ( reader ) { _ENTITY_REGISTER_OBJECT(_Entity(newSubscriber), (_Object)reader); handle = _EntityRelease(reader); gapi_entity_enable(handle); } } newSubscriber->builtin = TRUE; _EntityStatus(newSubscriber) = status; } else { _EntityDispose(_Entity(newSubscriber)); newSubscriber = NULL; } } } return newSubscriber; }
void v_serviceInit( v_service service, v_serviceManager manager, const c_char *name, const c_char *extStateName, v_participantQos qos, v_statistics stats) { c_char *typeName; v_duration lp = {300, 0}; v_kernel kernel; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); assert(C_TYPECHECK(qos, v_participantQos)); assert(name != NULL); kernel = v_objectKernel(service); v_participantInit(v_participant(service), name, qos, stats, TRUE); service->state = v_serviceManagerRegister(manager, service, extStateName); service->lease = v_leaseNew(kernel, lp); if(service->lease) { v_result result; result = v_leaseManagerRegister( kernel->livelinessLM, service->lease, V_LEASEACTION_SERVICESTATE_EXPIRED, v_public(service->state), FALSE/*do not repeat */); if(result != V_RESULT_OK) { c_free(service->lease); service->lease = NULL; OS_REPORT_1(OS_ERROR, "v_service", 0, "A fatal error was detected when trying to register the liveliness lease " "to the liveliness lease manager of the kernel. The result code was %d.", result); } } else { OS_REPORT(OS_ERROR, "v_service", 0, "Unable to create a liveliness lease! Most likely not enough shared " "memory available to complete the operation."); } if(service->lease)/* aka everything is ok so far */ { v_result result; c_iter participants; v_participant splicedParticipant; participants = v_resolveParticipants(kernel, V_SPLICED_NAME); assert(c_iterLength(participants) == 1 || 0 == strcmp(name, V_SPLICED_NAME)); splicedParticipant = v_participant(c_iterTakeFirst(participants)); if(splicedParticipant) { result = v_leaseManagerRegister( v_participant(service)->leaseManager, v_service(splicedParticipant)->lease, V_LEASEACTION_SERVICESTATE_EXPIRED, v_public(v_service(splicedParticipant)->state), FALSE /* only observing, do not repeat */); if(result != V_RESULT_OK) { c_free(service->lease); service->lease = NULL; OS_REPORT_3(OS_ERROR, "v_service", 0, "A fatal error was detected when trying to register the spliced's liveliness lease " "to the lease manager of participant %p (%s). The result code was %d.", service, name, result); } } c_iterFree(participants); } if (service->state != NULL) { /* check if state has correct type */ typeName = c_metaScopedName(c_metaObject(c_getType(c_object(service->state)))); if (extStateName == NULL) { extStateName = VSERVICESTATE_NAME; } if (strcmp(typeName, extStateName) == 0) { if (strcmp(name, V_SPLICED_NAME) != 0) { /* Splicedaemon may not observer itself! */ v_serviceWatchSplicedaemon(service); } } else { OS_REPORT_2(OS_ERROR, "v_service", 0, "Requested state type (%s) differs with existing state type (%s)", extStateName, typeName); c_free(service->state); service->state = NULL; } os_free(typeName); } }
void d_nameSpacesListenerAction( d_listener listener, d_message message) { d_durability durability; d_admin admin; d_publisher publisher; d_fellow fellow; c_bool allowed; d_nameSpace nameSpace, localNameSpace, oldFellowNameSpace; c_ulong count; d_configuration config; d_nameSpacesRequest nsRequest; d_networkAddress sender; d_subscriber subscriber; d_sampleChainListener sampleChainListener; struct compatibilityHelper helper; d_adminStatisticsInfo info; c_bool added; os_time srcTime , curTime, difTime, maxDifTime; struct checkFellowMasterHelper fellowMasterHelper; d_name role; c_iter fellowNameSpaces; d_nameSpace ns; assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_LISTENER)); admin = d_listenerGetAdmin(listener); publisher = d_adminGetPublisher(admin); durability = d_adminGetDurability(admin); config = d_durabilityGetConfiguration(durability); fellowNameSpaces = NULL; d_printTimedEvent (durability, D_LEVEL_FINE, D_THREAD_NAMESPACES_LISTENER, "Received nameSpace from fellow %d (his master: %d, confirmed: %d, mergeState: %s, %d).\n", message->senderAddress.systemId, d_nameSpaces(message)->master.systemId, d_nameSpaces(message)->masterConfirmed, d_nameSpaces(message)->state.role, d_nameSpaces(message)->state.value); sender = d_networkAddressNew(message->senderAddress.systemId, message->senderAddress.localId, message->senderAddress.lifecycleId); fellow = d_adminGetFellow(admin, sender); if(!fellow){ d_printTimedEvent (durability, D_LEVEL_FINE, D_THREAD_NAMESPACES_LISTENER, "Fellow %d unknown, administrating it.\n", message->senderAddress.systemId); fellow = d_fellowNew(sender, message->senderState); d_fellowUpdateStatus(fellow, message->senderState, v_timeGet()); added = d_adminAddFellow(admin, fellow); if(added == FALSE){ d_fellowFree(fellow); fellow = d_adminGetFellow(admin, sender); assert(fellow); } else { fellow = d_adminGetFellow(admin, sender); /*Do this to allow fellowFree at the end*/ nsRequest = d_nameSpacesRequestNew(admin); d_messageSetAddressee(d_message(nsRequest), sender); d_publisherNameSpacesRequestWrite(publisher, nsRequest, sender); d_nameSpacesRequestFree(nsRequest); } } d_fellowUpdateStatus(fellow, message->senderState, v_timeGet()); nameSpace = d_nameSpaceFromNameSpaces(config, d_nameSpaces(message)); if(d_fellowGetCommunicationState(fellow) == D_COMMUNICATION_STATE_APPROVED){ /* Get old namespace of fellow */ oldFellowNameSpace = d_nameSpaceCopy (d_fellowGetNameSpace (fellow, nameSpace)); /* Update master of fellow nameSpace */ added = d_fellowAddNameSpace(fellow, nameSpace); /* Create namespace with local policy (if a match exists) */ localNameSpace = d_nameSpaceNew (config, d_nameSpaceGetName(nameSpace)); /* If namespace is created, add to administration */ if (localNameSpace) { /* Copy partitions to local nameSpace */ d_nameSpaceCopyPartitions (localNameSpace, nameSpace); d_adminAddNameSpace (admin, localNameSpace); d_nameSpaceFree (localNameSpace); } /* If fellow is master for a namespace, report it to admin */ fellowMasterHelper.admin = admin; fellowMasterHelper.fellow = d_fellowGetAddress(fellow); fellowMasterHelper.oldNameSpace = oldFellowNameSpace; checkFellowMasterWalk (nameSpace, &fellowMasterHelper); d_free (fellowMasterHelper.fellow); /* If the namespace was not added to the fellow (because it already existed there), free it */ if(!added){ d_nameSpaceFree(nameSpace); } d_nameSpaceFree (oldFellowNameSpace); } else { info = d_adminStatisticsInfoNew(); d_fellowSetExpectedNameSpaces(fellow, d_nameSpaces(message)->total); d_fellowAddNameSpace(fellow, nameSpace); count = d_fellowNameSpaceCount(fellow); if(count == d_nameSpaces(message)->total){ allowed = isFellowStateCompatible(durability, fellow); if(allowed == TRUE){ config = d_durabilityGetConfiguration(durability); helper.fellow = fellow; helper.compatible = TRUE; d_adminNameSpaceWalk (admin, areFellowNameSpacesCompatible, &helper); if(helper.compatible == TRUE){ if(config->timeAlignment == TRUE){ curTime.tv_sec = d_readerListener(listener)->lastInsertTime.seconds; curTime.tv_nsec = d_readerListener(listener)->lastInsertTime.nanoseconds; srcTime.tv_sec = d_readerListener(listener)->lastSourceTime.seconds; srcTime.tv_nsec = d_readerListener(listener)->lastSourceTime.nanoseconds; maxDifTime.tv_sec = 1; /*1s*/ maxDifTime.tv_nsec = 0; difTime = os_timeAbs(os_timeSub(curTime, srcTime)); if(os_timeCompare(difTime, maxDifTime) == OS_MORE){ d_printTimedEvent (durability, D_LEVEL_WARNING, D_THREAD_NAMESPACES_LISTENER, "Estimated time difference including latency with " \ "fellow %d is %f seconds, which is larger then " \ "expected.\n", message->senderAddress.systemId, os_timeToReal(difTime)); OS_REPORT_2(OS_WARNING, D_CONTEXT, 0, "Estimated time difference including latency " \ "with fellow '%d' is larger then expected " \ "(%f seconds). Durability alignment might not be " \ "reliable. Please align time between these nodes " \ "and restart.", message->senderAddress.systemId, os_timeToReal(difTime)); } else { d_printTimedEvent (durability, D_LEVEL_FINER, D_THREAD_NAMESPACES_LISTENER, "Estimated time difference including latency with " \ "fellow %d is %f seconds.\n", message->senderAddress.systemId, os_timeToReal(difTime)); } } /* Set role of fellow (take native role from namespace) */ role = d_nameSpaceGetRole(nameSpace); d_fellowSetRole (fellow, role); os_free (role); d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_APPROVED); info->fellowsApprovedDif += 1; subscriber = d_adminGetSubscriber(admin); sampleChainListener = d_subscriberGetSampleChainListener(subscriber); if(sampleChainListener){ d_sampleChainListenerTryFulfillChains(sampleChainListener, NULL); } /* Check if the fellow is master for one or more namespaces and report this to admin */ fellowNameSpaces = c_iterNew(NULL); /* Collect fellow namespaces */ d_fellowNameSpaceWalk (fellow, collectFellowNsWalk, fellowNameSpaces); fellowMasterHelper.admin = admin; fellowMasterHelper.fellow = d_fellowGetAddress(fellow); fellowMasterHelper.oldNameSpace = NULL; c_iterWalk (fellowNameSpaces, checkFellowMasterWalk, &fellowMasterHelper); while ((ns = c_iterTakeFirst(fellowNameSpaces))) { d_nameSpaceFree(ns); } c_iterFree(fellowNameSpaces); d_free (fellowMasterHelper.fellow); } else { info->fellowsIncompatibleDataModelDif += 1; d_printTimedEvent (durability, D_LEVEL_WARNING, D_THREAD_NAMESPACES_LISTENER, "Communication with fellow %d NOT approved, because data model is not compatible\n", message->senderAddress.systemId); d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_DATA_MODEL); } } else { info->fellowsIncompatibleStateDif += 1; d_printTimedEvent (durability, D_LEVEL_WARNING, D_THREAD_NAMESPACES_LISTENER, "Communication with fellow %d NOT approved, because state is not compatible my state: %d, fellow state: %d\n", message->senderAddress.systemId, d_durabilityGetState(durability), message->senderState); d_fellowSetCommunicationState(fellow, D_COMMUNICATION_STATE_INCOMPATIBLE_STATE); } } else { d_printTimedEvent (durability, D_LEVEL_WARNING, D_THREAD_NAMESPACES_LISTENER, "Received %u of %u nameSpaces from fellow %u.\n", count, d_nameSpaces(message)->total, message->senderAddress.systemId); } d_adminUpdateStatistics(admin, info); d_adminStatisticsInfoFree(info); } d_fellowFree(fellow); d_networkAddressFree(sender); return; }