d_table d_tableNew( int ( * compare )(), void ( * cleanAction )() ) { d_table table; assert(compare != 0); /* Allocate table object */ table = (d_table)d_malloc(C_SIZEOF(d_table), "Table"); if (table) { /* QAC EXPECT 3892; */ /* Call super-init */ d_objectInit(d_object(table), D_TABLE, (d_objectDeinitFunc)d_tableDeinit); /* Initialize table object */ ut_avlCTreedefInit (&table->td, offsetof (C_STRUCT(d_tableNode), avlnode), offsetof (C_STRUCT(d_tableNode), object), (int (*) (const void *, const void *)) compare, 0, UT_AVL_TREEDEF_FLAG_INDKEY); ut_avlCInit (&table->td, &table->tree); table->cleanAction = cleanAction; } return table; }
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; }
void v_topicAdapterNotify( v_topicAdapter adapter, v_event event, c_voidp userData) { C_STRUCT(v_event) e; c_bool forward = TRUE; OS_UNUSED_ARG(userData); assert(adapter != NULL); assert(C_TYPECHECK(adapter,v_topicAdapter)); assert(event != NULL); switch (event->kind) { case V_EVENT_ALL_DATA_DISPOSED: v_statusNotifyAllDataDisposed(v_entity(adapter)->status); break; case V_EVENT_INCONSISTENT_TOPIC: v_statusNotifyInconsistentTopic(v_entity(adapter)->status); break; default: forward = FALSE; break; } if (forward) { e.kind = event->kind; e.source = v_observable(adapter); e.data = NULL; (void)v_entityNotifyListener(v_entity(adapter), &e); } }
/************************************************************** * constructor/destructor **************************************************************/ u_writerQos u_writerQosNew( u_writerQos tmpl) { u_result result; u_writerQos q; q = os_malloc(sizeof(C_STRUCT(v_writerQos))); if (q != NULL) { if (tmpl != NULL) { *q = *tmpl; q->userData.size = tmpl->userData.size; if (tmpl->userData.size > 0) { q->userData.value = os_malloc(tmpl->userData.size); memcpy(q->userData.value,tmpl->userData.value,tmpl->userData.size); } else { q->userData.value = NULL; } } else { result = u_writerQosInit(q); if (result != U_RESULT_OK) { u_writerQosFree(q); q = NULL; } } } return q; }
/** * 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; }
/************************************************************** * constructor/destructor **************************************************************/ v_dataViewQos u_dataViewQosNew( v_dataViewQos tmpl) { v_dataViewQos q; u_result result; int len; q = os_malloc(sizeof(C_STRUCT(v_dataViewQos))); if (q != NULL) { if (tmpl != NULL) { /* Copy non-reference fields */ *q = *tmpl; /* Copy reference fields */ if (tmpl->userKey.enable){ if (tmpl->userKey.expression != NULL) { len = strlen(tmpl->userKey.expression); q->userKey.expression = os_malloc(len+1); os_strncpy(q->userKey.expression, tmpl->userKey.expression, len); q->userKey.expression[len] = 0; } else { q->userKey.expression = NULL; } } } else { result = u_dataViewQosInit(q); if (result != U_RESULT_OK) { u_dataViewQosFree(q); q = NULL; } } } return q; }
/************************************************************** * constructor/destructor **************************************************************/ v_publisherQos u_publisherQosNew( v_publisherQos tmpl) { u_result result; v_publisherQos q; q = os_malloc(sizeof(C_STRUCT(v_publisherQos))); if (q != NULL) { if (tmpl != NULL) { *q = *tmpl; q->groupData.size = tmpl->groupData.size; if (tmpl->groupData.size > 0) { q->groupData.value = os_malloc(tmpl->groupData.size); memcpy(q->groupData.value,tmpl->groupData.value,tmpl->groupData.size); } else { q->groupData.value = NULL; } if (tmpl->partition != NULL) { q->partition = os_strdup(tmpl->partition); } else { q->partition = NULL; } } else { result = u_publisherQosInit(q); if (result != U_RESULT_OK) { u_publisherQosFree(q); q = NULL; } } } return q; }
/************************************************************** * constructor/destructor **************************************************************/ sr_serviceInfo sr_serviceInfoNew( u_cfElement info, const char *defaultConfigURI) { sr_serviceInfo si; int result; /** * Note: We are not able to assign a reasonable value to the member * 'procId', since we do not know the type and the OS layer does not * provide us with a initial value. */ if (info != NULL) { si = (sr_serviceInfo)os_malloc((os_uint32)sizeof(C_STRUCT(sr_serviceInfo))); if (si != NULL) { result = cfgGetInfo(si, info, defaultConfigURI); if (result) { sr_serviceInfoFree(si); si = NULL; } } } else { si = NULL; } return si; }
void q_swapExpr( q_expr oldExpr, q_expr newExpr) { C_STRUCT(q_expr) e; memcpy(&e,oldExpr,C_SIZEOF(q_expr)); memcpy(oldExpr,newExpr,C_SIZEOF(q_expr)); memcpy(newExpr,&e,C_SIZEOF(q_expr)); }
/* assumes the owning home of this data reader is locked as well as any related homes needed to manage relations. */ void DJA_ObjectReaderBridge_us_doLSReadPreProcessing( DK_ReadInfo* readInfo, DK_ObjectReader* objReader) { JNIEnv* env = NULL; DLRL_LS_object ls_reader = NULL; DJA_CachedJNITypedTopic* typedTopicCachedData= NULL; DLRL_Exception* exception = NULL; DK_TopicInfo* topicInfo = NULL; /* allocate the readInfo on stack to prevent an alloc. */ C_STRUCT(saj_dstInfo) dst; DLRL_INFO(INF_ENTER); assert(readInfo); assert(objReader); /* get the cached JNI data from the user data field of the associated cached topic jni info from the main topic of */ /* the object home */ topicInfo = DK_ObjectReader_us_getTopicInfo(objReader); ls_reader = DK_ObjectReader_us_getLSReader(objReader); typedTopicCachedData = (DJA_CachedJNITypedTopic*)DK_TopicInfo_us_getTopicUserData(topicInfo); assert(typedTopicCachedData); env = (JNIEnv*)readInfo->userData; exception = readInfo->exception; dst.javaEnv = env; /* Setting the java object to NIL means that the copy out function will construct a new object */ dst.javaObject = NULL; dst.javaClass = typedTopicCachedData->typedTopic_class; /* can also be done once when entering the reader copy (getting the long value) */ dst.copyProgram = (saj_copyCache)(*env)->GetLongField(env, (jobject)ls_reader, typedTopicCachedData->typedReader_copyCache_fid); if(!dst.copyProgram){ DLRL_Exception_THROW(exception, DLRL_DCPS_ERROR, "Failed to retrieve the copy algoritm from a DCPS DataReader. " "Check DCPS error log file for (possibly) more information."); } /* set java DCPS copy out routine user data */ readInfo->dstInfo = &dst; readInfo->copyOut = saj_copyOutStruct; /* continue the read in the kernel. This ensure the stack remains intact (the dst was allocated on stack!) */ DK_ObjectReader_us_doRead(objReader, exception, readInfo); DLRL_Exception_PROPAGATE(exception); DLRL_Exception_EXIT(exception); DLRL_INFO(INF_EXIT); }
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 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_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); } }
static void _DataReaderViewCopyIn ( c_type type, void *data, void *to) { c_base base = c_getBase(c_object(type)); readerViewCopyInInfo *info = data; if (info->reader->copy_cache) { C_STRUCT(gapi_srcInfo) dataInfo; dataInfo.copyProgram = info->reader->copy_cache; dataInfo.src = info->data; info->reader->copy_in (base, &dataInfo, to); } else { info->reader->copy_in (base, info->data, to); } }
static c_bool _DataWriterCopy ( c_type type, void *data, void *to) { c_bool result; c_base base = c_getBase(c_object(type)); writerInfo *info = (writerInfo *)data; if (info->writer->copy_cache) { C_STRUCT(gapi_srcInfo) dataInfo; dataInfo.copyProgram = info->writer->copy_cache; dataInfo.src = info->data; result = info->writer->copy_in (base, &dataInfo, to); } else { result = info->writer->copy_in (base, info->data, to); } return result; }
v_topic v_lookupTopic( v_kernel kernel, const char *name) { v_topic topicFound; C_STRUCT(v_topic) dummyTopic; c_base base = c_getBase(c_object(kernel)); /* Create a dummy topic for look-up */ memset(&dummyTopic, 0, sizeof(dummyTopic)); ((v_entity)(&dummyTopic))->name = c_stringNew(base,name); topicFound = NULL; c_lockRead(&kernel->lock); /* This does not remove anything because the alwaysFalse function always * returns false */ c_remove(kernel->topics, &dummyTopic, alwaysFalse, &topicFound); c_lockUnlock(&kernel->lock); c_free(((v_entity)(&dummyTopic))->name); return topicFound; }
static c_array copyReaderGIDsFromPublications( v_deliveryGuard _this) { /* copy system Ids from _this->publications */ C_STRUCT(copySystemIdsArg) arg; c_long size; if (_this->publications) { size = c_count(_this->publications); } else { size = 0; } if (size > 0) { arg.readerGID = c_arrayNew(_this->gidType,size); arg.index = 0; c_walk(_this->publications, copySystemIds, &arg); } else { arg.readerGID = NULL; } return arg.readerGID; }
v_result v_kernelCreatePersistentSnapshot( v_kernel _this, const c_char * partition_expression, const c_char * topic_expression, const c_char * uri) { v_result result = V_RESULT_OK; C_STRUCT(v_event) event; v_persistentSnapshotRequest request; request = v_persistentSnapshotRequestNew(_this, partition_expression, topic_expression, uri); if(request) { event.kind = V_EVENT_PERSISTENT_SNAPSHOT; event.source = v_publicHandle(v_public(_this)); event.userData = request; v_observableNotify(v_observable(_this),&event); } else { result = V_RESULT_OUT_OF_MEMORY; } return result; }
if (_this == NULL) { name = os_strdup("<NULL>"); } else { if (_this->name == NULL) { name = os_strdup("<NULL>"); } else { name = os_strdup(_this->name); } } return name; } static void GetDomainConfig( cf_element config, C_STRUCT(u_domainConfig) *domainConfig, os_sharedAttr *shm_attr) { cf_element dc = NULL; cf_element child; cf_element name; cf_data elementData; cf_element size; cf_element threshold; cf_element address; cf_element heap; cf_element locked; c_value value; cf_attribute attr; assert(config != NULL); assert(domainConfig != NULL);
/************************************************************** * Public functions **************************************************************/ c_bool v_serviceStateChangeState( v_serviceState serviceState, v_serviceStateKind stateKind) { c_bool changed; C_STRUCT(v_event) event; assert(C_TYPECHECK(serviceState, v_serviceState)); c_lockWrite(&serviceState->lock); switch (stateKind) { case STATE_NONE: break; case STATE_DIED: if ((serviceState->stateKind != STATE_NONE) && (serviceState->stateKind != STATE_TERMINATED)) { serviceState->stateKind = stateKind; } break; case STATE_INITIALISING: if ((serviceState->stateKind == STATE_NONE) || (serviceState->stateKind == STATE_DIED)) { serviceState->stateKind = stateKind; } break; case STATE_OPERATIONAL: if (serviceState->stateKind == STATE_INITIALISING) { serviceState->stateKind = stateKind; } break; case STATE_INCOMPATIBLE_CONFIGURATION: if ((serviceState->stateKind == STATE_OPERATIONAL) || (serviceState->stateKind == STATE_INITIALISING)) { serviceState->stateKind = stateKind; } break; case STATE_TERMINATING: if ((serviceState->stateKind == STATE_INITIALISING) || (serviceState->stateKind == STATE_OPERATIONAL)) { serviceState->stateKind = stateKind; } break; case STATE_TERMINATED: if (serviceState->stateKind == STATE_TERMINATING) { serviceState->stateKind = stateKind; } break; default: OS_REPORT_1(OS_ERROR,"Kernel::ServiceState",0, "Unkown state (%d) kind provided.",stateKind); assert(FALSE); /* unknown state */ break; } if (serviceState->stateKind == stateKind) { changed = TRUE; } else { changed = FALSE; } c_lockUnlock(&serviceState->lock); event.kind = V_EVENT_SERVICESTATE_CHANGED; event.source = v_publicHandle(v_public(serviceState)); event.userData = NULL; v_observableNotify(v_observable(serviceState),&event); return changed; }
void _DataReaderCopy ( gapi_dataSampleSeq *samples, gapi_readerInfo *info) { unsigned int i, len; gapi_fooSeq *data_seq = info->data_buffer; gapi_sampleInfoSeq *info_seq = info->info_buffer; void *dst; if (samples) { if (samples->_length > info->max_samples) { len = info->max_samples; } else { len = samples->_length; } if (len > 0) { if (data_seq->_buffer == NULL) { if (!info->copy_cache) { data_seq->_buffer = info->alloc_buffer( len); } else { data_seq->_buffer = gapi_copyOutAllocBuffer( info->copy_cache, len); } memset(data_seq->_buffer,0,info->alloc_size*len); data_seq->_maximum = len; data_seq->_release = FALSE; info_seq->_buffer = gapi_sampleInfoSeq_allocbuf(len); info_seq->_maximum = len; info_seq->_release = FALSE; if (*info->loan_registry == NULL) { *info->loan_registry = (void *)gapi_loanRegistry_new(); } gapi_loanRegistry_register((gapi_loanRegistry)*info->loan_registry, data_seq->_buffer, info_seq->_buffer); } { C_STRUCT(gapi_dstInfo) dstInfo; dstInfo.copyProgram = info->copy_cache; for ( i = 0; i < len; i++ ) { dst = &data_seq->_buffer[i*info->alloc_size]; if (info->copy_cache){ dstInfo.dst = dst; dstInfo.buf = data_seq->_buffer; info->copy_out (samples->_buffer[i].data, &dstInfo); } else { info->copy_out (samples->_buffer[i].data, dst); } info_seq->_buffer[i] = samples->_buffer[i].info; } } } data_seq->_length = len; info_seq->_length = len; info->num_samples = len; } }
cms_service cms_serviceNew( const c_char* name, const c_char* uri) { cms_service service; c_bool success; const c_char* init; C_STRUCT(v_participantQos) q; struct sockaddr_in addr; socklen_t len; os_result errcode; char* ipTagStr = NULL; char* xmlStr = NULL; u_result result; os_result res; os_ifAttributes *ifList; os_uint32 nofIf, i; service = NULL; if(uri != NULL) { init = cmx_initialise(); if(strcmp(init, CMS_RESULT_OK) == 0) { service = cms_service(os_malloc(C_SIZEOF(cms_service))); cms_object(service)->kind = CMS_SERVICE; service->terminate = FALSE; service->leaseThread = NULL; service->clients = NULL; service->soap = NULL; service->configuration = NULL; service->garbageCollector = NULL; service->uservice = u_serviceNew(uri, CMSERVICE_ATTACH_TIMEOUT, name, NULL, U_SERVICE_CMSOAP, NULL); if(service->uservice != NULL) { /*disable all events.*/ u_dispatcherSetEventMask(u_dispatcher(service->uservice), 0); u_entityAction(u_entity(service->uservice), cms_serviceActionGroups, NULL); u_serviceChangeState(service->uservice, STATE_INITIALISING); success = cms_serviceInit(name, service); result = u_participantQosInit((v_participantQos)&q); if (result == U_RESULT_OK) { /* Insert service information in userData QoS */ len = sizeof(struct sockaddr); errcode = os_sockGetsockname (service->soap->master, (struct sockaddr*)&addr, len); if(errcode == os_resultSuccess) { OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "SOAP service is reachable via port %d",ntohs(addr.sin_port)); ifList = os_malloc(MAX_INTERFACES * sizeof(*ifList)); #ifdef WITH_IPV6 res = os_sockQueryIPv6Interfaces(ifList, (os_uint32)MAX_INTERFACES, &nofIf); #else res = os_sockQueryInterfaces(ifList, (os_uint32)MAX_INTERFACES, &nofIf); #endif /* SOAP userdata layout: * <TunerService> * <Ip>x.x.x.x:port</Ip> [<Ip>x.x.x.x</Ip>]... * </TunerService> */ if (res == os_resultSuccess) { os_char tmp[64]; int chars; for (i = 0; i < nofIf; i++) { /* ignore the local loopback interface */ if (!os_sockaddrIsLoopback((os_sockaddr*)&ifList[i].address)) { os_sprintf(tmp,"%s",inet_ntoa(((os_sockaddr_in*)&ifList[i].address)->sin_addr)); if (strcmp(tmp,"0.0.0.0") != 0) { chars = os_sprintf(tmp, IP_TAG, inet_ntoa(((os_sockaddr_in*)&ifList[i].address)->sin_addr), ntohs(addr.sin_port)); if (chars > 0) { if (ipTagStr) { ipTagStr = os_realloc(ipTagStr, strlen(ipTagStr) + chars + 1); } else { ipTagStr = os_malloc(chars + 1); *ipTagStr = '\0'; } ipTagStr = os_strcat(ipTagStr, tmp); } } } } } else { if(service->configuration->verbosity >= 1) { OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not get SOAP ip address."); } ipTagStr = os_malloc((strlen(IP_TAG) + INET6_ADDRSTRLEN_EXTENDED)); os_sprintf (ipTagStr, IP_TAG, "127.0.0.1", ntohs(addr.sin_port)); } os_free(ifList); xmlStr = os_malloc(strlen(ipTagStr) + strlen(SOAP_TAG)+1); os_sprintf (xmlStr, SOAP_TAG, ipTagStr); os_free(ipTagStr); q.userData.size = strlen(xmlStr); q.userData.value = os_malloc(q.userData.size); memcpy(q.userData.value, xmlStr, q.userData.size); if(service->configuration->verbosity >= 5) { OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "SOAP userData: %s", xmlStr); } os_free(xmlStr); } else { q.userData.size = 0; q.userData.value = NULL; if(service->configuration->verbosity >= 1) { OS_REPORT(OS_WARNING, CMS_CONTEXT, 0, "Could not get SOAP port."); } } result = u_entitySetQoS(u_entity(service->uservice), (v_qos)&q); if (result != U_RESULT_OK) { if(service->configuration->verbosity >= 1) { OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not update the participantQos for publication of the SOAP ip address and port."); } } os_free(q.userData.value); } else { if(service->configuration->verbosity >= 1) { OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not initiate participantQos for SOAP service ip address and port publication."); } } if(success == FALSE) { cms_serviceFree(service); service = NULL; } else { u_serviceWatchSpliceDaemon(service->uservice, cms_serviceSplicedaemonListener, service); u_serviceChangeState(service->uservice, STATE_OPERATIONAL); } } else { OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_serviceNew: user layer service could not be created."); cms_serviceFree(service); service = NULL; } } else { if(service && service->configuration->verbosity >= 1) { OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_serviceNew: C&M API could not be initialized."); } } } else { if(service && service->configuration->verbosity > 0) { OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_serviceNew: no uri supplied."); } } return service; }
v_historyResult v_readerWaitForHistoricalDataWithCondition( v_reader _this, c_char* filter, c_char* params[], c_ulong paramsLength, c_time minSourceTime, c_time maxSourceTime, struct v_resourcePolicy *resourceLimits, c_time timeout) { c_iter entries; c_object e; v_historyResult result; v_historicalDataRequest request; c_bool doRequest, doWait; struct historicalWaitArg arg; C_STRUCT(v_event) event; arg._expire_time = c_timeAdd(v_timeGet(), timeout); arg._status = TRUE; request = v_historicalDataRequestNew(v_objectKernel(_this), filter, params, paramsLength, minSourceTime, maxSourceTime, resourceLimits); if(request){ V_READER_LOCK(_this); if(_this->historicalDataRequest) { /* Historical data request already in progress or complete, check * whether request is equal to the original one. */ doRequest = FALSE; if(v_historicalDataRequestEquals(request, _this->historicalDataRequest)){ /* Request is equal to original request*/ result = V_HISTORY_RESULT_OK; if(_this->historicalDataComplete){ /* Request has already been fulfilled. Consider this call * a no-operation. */ doWait = FALSE; } else { /* Request is still in progress, wait for data to arrive*/ doWait = TRUE; } } else { /* The requested parameters are not equal to the originally * requested set. Return a precondition not met. */ doWait = FALSE; result = V_HISTORY_RESULT_PRE_NOT_MET; } c_free(request); } else { /* No active request, so validate it now.*/ if(v_historicalDataRequestIsValid(request, _this)){ /* This request is valid, so request data.*/ doRequest = TRUE; doWait = TRUE; result = V_HISTORY_RESULT_OK; _this->historicalDataRequest = request; } else { /* Request is not valid, so return bad parameter.*/ doRequest = FALSE; doWait = FALSE; result = V_HISTORY_RESULT_BAD_PARAM; c_free(request); } } V_READER_UNLOCK(_this); } else { doRequest = FALSE; doWait = FALSE; result = V_HISTORY_RESULT_ERROR; } if(doWait){ v_readerEntrySetLock(_this); entries = c_select(_this->entrySet.entries, 0); v_readerEntrySetUnlock(_this); if(doRequest){ /* Historical data must be requested, since this is the first time * the operation is called and the request is valid. */ if (_this->qos->durability.kind == V_DURABILITY_VOLATILE) { /* If reader is volatile, the historical data from the * group(s) has/have not been retrieved yet, so do it now. */ e = c_iterTakeFirst(entries); while (e != NULL) { getHistoricalData(e, _this->historicalDataRequest); c_free(e); e = c_iterTakeFirst(entries); } c_iterFree(entries); } event.kind = V_EVENT_HISTORY_REQUEST; event.source = v_publicHandle(v_public(_this)); event.userData = _this->historicalDataRequest; v_observableNotify(v_observable(v_objectKernel(_this)),&event); } V_READER_LOCK(_this); if(!_this->historicalDataComplete){ if (c_timeCompare(timeout, C_TIME_INFINITE) != C_EQ) { if (c_condTimedWait(&_this->historicalDataCondition, &V_READER_GET_LOCK(_this), timeout) != SYNC_RESULT_SUCCESS) { result = V_HISTORY_RESULT_TIMEOUT; } } else if (c_condWait(&_this->historicalDataCondition, &V_READER_GET_LOCK(_this)) != SYNC_RESULT_SUCCESS) { result = V_HISTORY_RESULT_TIMEOUT; } assert( (result == V_HISTORY_RESULT_OK) == _this->historicalDataComplete); } V_READER_UNLOCK(_this); } return result; }
u_result u_userInitialise( void) { u_user u; u_result rm = U_RESULT_OK; os_mutexAttr mutexAttr; os_uint32 initCount; void* initUser; os_result osResult; os_signalHandlerExitRequestCallback exitRequestCallback; os_signalHandlerExceptionCallback exceptionCallback; initCount = pa_increment(&_ospl_userInitCount); /* If initCount == 0 then an overflow has occurred. * This can only realistically happen when u_userDetach() * is called more often than u_userInitialize(). */ assert(initCount != 0); os_osInit(); if (initCount == 1) { /* Will start allocating the object, so it should currently be empty. */ assert(user == NULL); /* Use indirection, as user != NULL is a precondition for user-layer * functions, so make sure it only holds true when the user-layer is * initialized. */ initUser = os_malloc(sizeof(C_STRUCT(u_user))); if (initUser == NULL) { /* Initialization failed, so decrement the initialization counter. */ pa_decrement(&_ospl_userInitCount); os_osExit(); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Allocation of user admin failed: out of memory."); rm = U_RESULT_OUT_OF_MEMORY; } else { u = u_user(initUser); os_mutexAttrInit(&mutexAttr); mutexAttr.scopeAttr = OS_SCOPE_PRIVATE; os_mutexInit(&u->mutex,&mutexAttr); osResult = os_signalHandlerNew(); if(osResult != os_resultSuccess) { /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Failed to create the signal handler. No proper signal handling can be performed."); rm = U_RESULT_INTERNAL_ERROR; } else { exitRequestCallback = os_signalHandlerSetExitRequestCallback(u__userExitRequestCallbackWrapper); if(exitRequestCallback && exitRequestCallback != u__userExitRequestCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exit request callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } if(rm == U_RESULT_OK){ exceptionCallback = os_signalHandlerSetExceptionCallback(u__userExceptionCallbackWrapper); if(exceptionCallback && exceptionCallback != u__userExceptionCallbackWrapper) { initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT(OS_ERROR, "u_userInitialise", 0, "Replaced an exception callback on the signal handler while this was not expected."); rm = U_RESULT_INTERNAL_ERROR; } } if(rm == U_RESULT_OK) { u->domainCount = 0; u->protectCount = 0; u->detachThreadId = OS_THREAD_ID_NONE; /* This will mark the user-layer initialized */ user = initUser; } } } } else { if(user == NULL){ os_time sleep = {0, 100000}; /* 100ms */ /* Another thread is currently initializing the user-layer. Since * user != NULL is a precondition for calls after u_userInitialise(), * a sleep is performed, to ensure that (if succeeded) successive * user-layer calls will also actually pass.*/ os_nanoSleep(sleep); } if(user == NULL){ /* Initialization did not succeed, undo increment and return error */ initCount = pa_decrement(&_ospl_userInitCount); OS_REPORT_1(OS_ERROR,"u_userInitialise",0, "Internal error: User-layer should be initialized " "(initCount = %d), but user == NULL (waited 100ms).", initCount); rm = U_RESULT_INTERNAL_ERROR; } } return rm; }
}; /************************************************************** * Private functions **************************************************************/ static const char * substituteConstants( const char *xmlValue) __attribute__((nonnull)) __attribute__((pure)); static qp_result processElement( cf_element element, C_STRUCT(qp_parseContext) ctx) __attribute__((nonnull)); static qp_result processContainedElements( c_iter elements, C_STRUCT(qp_parseContext) ctx); static qp_result processElementData( cf_data data, C_STRUCT(qp_parseContext) ctx) __attribute__((nonnull)); static qp_result processAttribute(
/* * Class: DDS_QosProvider * Method: jniGetDatawriterQos * Signature: (LDDS/NamedDataWriterQosHolder;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL SAJ_FUNCTION(jniGetDatawriterQos)( JNIEnv *env, jobject jqosProvider, jobject jqosHolder, jstring jid) { saj_qosProvider qosProvider; gapi_returnCode_t result; qp_result qpr; const char * strId; C_STRUCT(saj_dstInfo) dst; /* Parameter checking */ if(jqosHolder == NULL){ result = GAPI_RETCODE_BAD_PARAMETER; OS_REPORT(OS_API_INFO, SAJ_FUNCTION_STR(jniGetDatawriterQos), result, "Bad parameter. NamedDataWriterQosHolder may not be null."); goto bad_param; } if((qosProvider = (saj_qosProvider)saj_read_gapi_address(env, jqosProvider)) == NULL){ /* Don't set API_INFO; this is collateral damage detected, not a new error. */ result = GAPI_RETCODE_PRECONDITION_NOT_MET; goto bad_param; } strId = jid ? (*env)->GetStringUTFChars (env, jid, NULL) : NULL; jniQosProviderCheckError(env, exception); dst.copyProgram = qosProvider->wCache; dst.javaObject = NULL; dst.javaEnv = env; qpr = qp_qosProviderGetDataWriterQos(qosProvider->qp, strId, &dst); if(qpr == QP_RESULT_OK){ /* store the Named-Qos object in the Holder object */ (*env)->SetObjectField(env, jqosHolder, GET_CACHED(namedDataWriterQosHolder_value_fid), dst.javaObject); jniQosProviderCheckError(env, exception); /* delete the local reference to the Named-Qos object */ (*env)->DeleteLocalRef(env, dst.javaObject); jniQosProviderCheckError(env, exception); result = GAPI_RETCODE_OK; } else if (qpr == QP_RESULT_NO_DATA){ result = GAPI_RETCODE_NO_DATA; } else { result = GAPI_RETCODE_ERROR; } if(strId){ (*env)->ReleaseStringUTFChars (env, jid, strId); jniQosProviderCheckError(env, exception); } return (jint)result; /* Error handling */ exception: jniQosProviderHandleException(env, SAJ_FUNCTION_STR(jniGetDataWriterQos)); result = GAPI_RETCODE_ERROR; bad_param: return (jint)result; }
/* * Class: DDS_QosProvider * Method: jniQosProviderNew * Signature: (Ljava/lang/String;Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL SAJ_FUNCTION(jniQosProviderNew)( JNIEnv *env, jobject jqosProvider, jstring juri, jstring jprofile) { saj_qosProvider _this; qp_qosProvider qp; const char *strUri; const char *strProfile; C_STRUCT(qp_qosProviderInputAttr) qpAttr; strUri = juri ? (*env)->GetStringUTFChars (env, juri, NULL) : NULL; jniQosProviderCheckError(env, err_strUri); strProfile = jprofile ? (*env)->GetStringUTFChars (env, jprofile, NULL) : NULL; jniQosProviderCheckError(env, err_strProfile); qpAttr.participantQos.copyOut = saj_copyOutStruct; qpAttr.topicQos.copyOut = saj_copyOutStruct; qpAttr.subscriberQos.copyOut = saj_copyOutStruct; qpAttr.dataReaderQos.copyOut = saj_copyOutStruct; qpAttr.publisherQos.copyOut = saj_copyOutStruct; qpAttr.dataWriterQos.copyOut = saj_copyOutStruct; if((qp = qp_qosProviderNew(strUri, strProfile, &qpAttr)) == NULL){ /* Error reported by qp_qosProviderNew(...) */ goto err_qosProviderNew; } if((_this = saj_qosProviderNew(env, qp)) == NULL){ goto err_sajQosProviderNew; } saj_write_gapi_address(env, jqosProvider, (PA_ADDRCAST)_this); if(strProfile){ (*env)->ReleaseStringUTFChars (env, jprofile, strProfile); } if(strUri){ (*env)->ReleaseStringUTFChars (env, juri, strUri); } return JNI_TRUE; /* Error handling */ err_sajQosProviderNew: qp_qosProviderFree(qp); err_qosProviderNew: if(strProfile){ (*env)->ReleaseStringUTFChars (env, jprofile, strProfile); } err_strProfile: if(strUri){ (*env)->ReleaseStringUTFChars (env, juri, strUri); } err_strUri: return JNI_FALSE; }