_ReadCondition _ReadConditionNew( const gapi_sampleStateMask sample_states, const gapi_viewStateMask view_states, const gapi_instanceStateMask instance_states, _DataReader datareader, _DataReaderView datareaderview) { _ReadCondition _this; u_reader uReader; u_dataView uDataView; q_expr predicate; /* The datareader and the datareaderview (should) share * a baseclass and therefore it is not necessary to have * both a datareader and a datareaderview as properties. * At run-time the right owner can be determined */ _this = _ReadConditionAlloc(); if ( _this != NULL ) { if (datareaderview != NULL) { _ConditionInit(_Condition(_this), _Entity(datareaderview), _ReadConditionGetTriggerValue); } else { _ConditionInit(_Condition(_this), _Entity(datareader), _ReadConditionGetTriggerValue); } _this->dataReader = datareader; _this->dataReaderView = datareaderview; _this->readerMask.sampleStateMask = sample_states; _this->readerMask.viewStateMask = view_states; _this->readerMask.instanceStateMask = instance_states; predicate = q_parse("1=1"); if (datareaderview) { uDataView = u_dataView(_DataReaderViewUreaderView(datareaderview)); if ( predicate != NULL ) { _this->uQuery = u_queryNew(u_reader(uDataView), NULL, predicate, NULL); } } else { uReader = u_reader(_DataReaderUreader(datareader)); if ( predicate != NULL ) { _this->uQuery = u_queryNew(uReader, NULL, predicate, NULL); } } q_dispose(predicate); if (_this->uQuery != NULL) { u_entitySetUserData(u_entity(_this->uQuery),_this); _Condition(_this)->uEntity = u_entity(_this->uQuery); } else { _ConditionDispose(_Condition(_this)); _this = NULL; } } return _this; }
u_result u_dispatcherGetEventMask( u_dispatcher _this, c_ulong *eventMask) { v_observer ko; u_result result = U_RESULT_OK; if ((_this != NULL) && (eventMask != NULL)) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if (result == U_RESULT_OK) { assert(ko); *eventMask = v_observerGetEventMask(ko); result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcherGetEventMask", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcherGetEventMask", 0, "Failed to claim Dispatcher."); } } else { OS_REPORT(OS_ERROR,"u_dispatcherGetEventMask",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
u_result u_dispatcherNotify( u_dispatcher _this) { v_observer ko; u_result result = U_RESULT_OK; if (_this != NULL) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if (result == U_RESULT_OK) { assert(ko); /* Wakeup the dispatch thread */ v_observerLock(ko); v_observerNotify(ko, NULL, NULL); v_observerUnlock(ko); result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcherNotify", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcherNotify", 0, "Failed to claim Dispatcher."); } } else { OS_REPORT(OS_ERROR,"u_dispatcherNotify",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
u_result u_readerGetMatchedPublications ( u_reader _this, v_statusAction action, c_voidp arg) { v_dataReader reader; v_spliced spliced; v_kernel kernel; u_result result; c_iter participants; v_participant participant; result = U_RESULT_PRECONDITION_NOT_MET; if (_this != NULL) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&reader)); if ((result == U_RESULT_OK) && (reader != NULL)) { kernel = v_objectKernel(reader); participants = v_resolveParticipants(kernel, V_SPLICED_NAME); assert(c_iterLength(participants) == 1); participant = v_participant(c_iterTakeFirst(participants)); spliced = v_spliced(participant); c_free(participant); c_iterFree(participants); result = u_resultFromKernel( v_splicedGetMatchedPublications(spliced, v_dataReader(reader), action, arg)); u_entityRelease(u_entity(_this)); } } return result; }
c_bool u_topicContentFilterValidate ( u_topic _this, q_expr expr, c_value params[]) { v_topic topic; c_type type; c_bool result; q_expr subexpr, term; int i; v_filter filter; u_result uResult; result = FALSE; filter = NULL; uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic)); if (uResult == U_RESULT_OK) { assert(topic); type = v_topicMessageType(topic); i = 0; subexpr = q_getPar(expr, i); /* get rid of Q_EXPR_PROGRAM */ while ((term = q_getPar(subexpr, i++)) != NULL) { if (q_getTag(term) == Q_EXPR_WHERE) { filter = v_filterNew(topic, term, params); } } u_entityRelease(u_entity(_this)); } if (filter != NULL) { result = TRUE; c_free(filter); } return result; }
u_subscriber u_subscriberNew( u_participant p, const c_char *name, v_subscriberQos qos, c_bool enable) { u_subscriber _this = NULL; v_subscriber ks; v_participant kp = NULL; u_result result; if (name == NULL) { name = "No name specified"; } if (p != NULL) { result = u_entityWriteClaim(u_entity(p),(v_entity*)(&kp)); if (result == U_RESULT_OK) { assert(kp); ks = v_subscriberNew(kp,name,qos,enable); if (ks != NULL) { _this = u_entityAlloc(p,u_subscriber,ks,TRUE); if (_this != NULL) { result = u_subscriberInit(_this,p); if (result != U_RESULT_OK) { OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0, "Initialisation failed. " "For DataReader: <%s>.", name); (void)u_subscriberFree(_this); _this = NULL; } } else { OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0, "Create user proxy failed. " "For Subscriber: <%s>.", name); } c_free(ks); } else { OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0, "Create kernel entity failed. " "For Subscriber: <%s>.", name); } result = u_entityRelease(u_entity(p)); if (result != U_RESULT_OK) { OS_REPORT_1(OS_WARNING, "u_subscriberNew", 0, "Could not release participant." "However subscriber <%s> is created.", name); } } else { OS_REPORT_1(OS_WARNING, "u_subscriberNew", 0, "Claim Participant failed. " "For Subscriber: <%s>.", name); } } else { OS_REPORT_1(OS_ERROR,"u_subscriberNew",0, "No Participant specified. " "For Subscriber: <%s>", name); } return _this; }
u_result u_readerGetDeadlineMissedStatus( u_reader _this, c_bool reset, v_statusAction action, c_voidp arg) { v_reader reader; u_result result; result = U_RESULT_PRECONDITION_NOT_MET; if (_this != NULL) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&reader)); if (result == U_RESULT_OK){ result = u_resultFromKernel( v_readerGetDeadlineMissedStatus(reader, reset, (v_statusAction)action, arg)); u_entityRelease(u_entity(_this)); } else { OS_REPORT(OS_ERROR, "u_readerDeadlineMissedStatus", 0, "Illegal handle detected"); } } return result; }
u_result u_serviceRenewLease( u_service _this, v_duration leasePeriod) { u_result r; v_service kernelService; if (_this == NULL) { r = U_RESULT_ILL_PARAM; } else { r = u_entityReadClaim(u_entity(_this), (v_entity*)(&kernelService)); if(r == U_RESULT_OK) { assert(kernelService); v_serviceRenewLease(kernelService, leasePeriod); r = u_entityRelease(u_entity(_this)); } else { OS_REPORT(OS_WARNING, "u_serviceRenewLease", 0, "Failed to claim service."); } } return r; }
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; }
c_char* cmx_writerNew( const c_char* publisher, const c_char* name, const c_char* topic, const c_char* qos) { u_publisher pub; u_topic top; u_writer wri; c_char* result; cmx_entityArg arg; u_result ur; cmx_entityKernelArg kernelArg; v_writerQos wQos; result = NULL; pub = u_publisher(cmx_entityUserEntity(publisher)); if(pub != NULL){ top = u_topic(cmx_entityUserEntity(topic)); if(top != NULL){ kernelArg = cmx_entityKernelArg(os_malloc(C_SIZEOF(cmx_entityKernelArg))); u_entityAction(u_entity(pub), cmx_entityKernelAction, (c_voidp)kernelArg); if(qos != NULL){ wQos = v_writerQos(cmx_qosKernelQosFromKind(qos, K_WRITER, c_getBase(c_object(kernelArg->kernel)))); if(wQos == NULL){ wQos = v_writerQosNew(kernelArg->kernel, NULL); wQos->reliability.kind = V_RELIABILITY_RELIABLE; } } else { wQos = v_writerQosNew(kernelArg->kernel, NULL); wQos->reliability.kind = V_RELIABILITY_RELIABLE; } wri = u_writerNew(pub, name, top, NULL, wQos, TRUE); os_free(kernelArg); c_free(wQos); if(wri != NULL){ cmx_registerEntity(u_entity(wri)); arg = cmx_entityArg(os_malloc(C_SIZEOF(cmx_entityArg))); arg->entity = u_entity(wri); arg->create = FALSE; arg->participant = NULL; arg->result = NULL; ur = u_entityAction(u_entity(wri), cmx_entityNewFromAction, (c_voidp)(arg)); if(ur == U_RESULT_OK){ result = arg->result; os_free(arg); } } } } return result; }
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_char* cmx_participantNew( const c_char* uri, const c_char* domainId, c_long timeout, const c_char* name, const c_char* qos) { u_participant p; u_result ur; u_domainId_t did; int pos; c_char* result; const c_char* context; if (*domainId == '\0') { did = U_DOMAIN_ID_ANY; } else if (sscanf (domainId,"%d%n", &did, &pos) != 1 || domainId[pos] != '\0') { OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "cmx_participantNew failed (reason: illegal argument: domainId \"%s\").", domainId); return NULL; } p = u_participantNew(uri, did, timeout > 0 ? (unsigned)timeout : 0, name, NULL, TRUE); if(p == NULL){ /* Error reported by u_participantNew() */ goto err_u_participantNew; } if(qos && *qos){ if((ur = u_entitySetXMLQos(u_entity(p), qos)) != U_RESULT_OK) { context = "u_entitySetXMLQos"; goto err_entity; } } if((ur = u_entityEnable(u_entity(p))) != U_RESULT_OK) { context = "u_entityEnable"; goto err_entity; } if((ur = cmx_entityRegister(u_object(p), NULL, &result)) != U_RESULT_OK) { context = "cmx_entityRegister"; goto err_entity; } return result; /* Error handling */ err_entity: OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "cmx_participantNew failed (reason: %s returned %u).", context, ur); u_objectFree(u_object(p)); err_u_participantNew: return NULL; }
void d_waitsetDeinit( d_object object) { d_waitset waitset; d_waitsetEntity we; d_waitsetHelper helper; assert(d_objectIsValid(object, D_WAITSET) == TRUE); if(object){ waitset = d_waitset(object); waitset->terminate = TRUE; if(waitset->runToCompletion == TRUE){ if(os_threadIdToInteger(waitset->thread)) { u_waitsetNotify(waitset->uwaitset, NULL); os_threadWaitExit(waitset->thread, NULL); } } else { if(waitset->threads){ helper = d_waitsetHelper(c_iterTakeFirst(waitset->threads)); while(helper){ helper->terminate = TRUE; u_waitsetNotify(helper->userWaitset, NULL); os_threadWaitExit(helper->tid, NULL); u_waitsetDetach(helper->userWaitset, u_entity(helper->entity->dispatcher)); u_waitsetFree(helper->userWaitset); os_free(helper); helper = d_waitsetHelper(c_iterTakeFirst(waitset->threads)); } c_iterFree(waitset->threads); waitset->threads = NULL; } } d_lockLock(d_lock(waitset)); if(waitset->entities) { we = d_waitsetEntity(c_iterTakeFirst(waitset->entities)); while(we) { if(waitset->runToCompletion == TRUE){ u_waitsetDetach(waitset->uwaitset, u_entity(we->dispatcher)); } d_waitsetEntityFree(we); we = d_waitsetEntity(c_iterTakeFirst(waitset->entities)); } c_iterFree(waitset->entities); } if(waitset->runToCompletion == TRUE){ if(waitset->uwaitset) { u_waitsetFree(waitset->uwaitset); } } d_lockUnlock(d_lock(waitset)); } }
static void * dispatch( void *o) { u_dispatcher _this; v_observer claim; struct listenerExecArg arg; u_result result; _this = u_dispatcher(o); if (_this != NULL) { if (_this->startAction) { _this->startAction(_this, _this->actionData); } os_mutexLock(&_this->mutex); result = u_entityReadClaim(u_entity(_this), (v_entity*)(&claim)); if(result == U_RESULT_OK) { assert(claim); while ((!(_this->event & V_EVENT_OBJECT_DESTROYED)) && (_this->listeners != NULL) && (c_iterLength(_this->listeners) > 0)) { os_mutexUnlock(&_this->mutex); _this->event = v_observerWait(claim); os_mutexLock(&_this->mutex); if (!(_this->event & V_EVENT_OBJECT_DESTROYED)) { /* do not call listeners when object is destroyed! */ arg.mask = 0; arg.o = _this; c_iterWalk(_this->listeners, (c_iterWalkAction)listenerExecute, &arg); } } _this->threadId = OS_THREAD_ID_NONE; result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcher::dispatch", 0, "Failed to claim Dispatcher."); } os_mutexUnlock(&_this->mutex); if (_this->stopAction) { _this->stopAction(_this, _this->actionData); } } else { OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0, "No dispatcher specified."); } return NULL; }
u_result u_dispatcherDeinit( u_dispatcher _this) { v_observer ko; u_listener listener; os_threadId tid; u_result result = U_RESULT_OK; if (_this != NULL) { os_mutexLock(&_this->mutex); listener = u_listener(c_iterTakeFirst(_this->listeners)); while (listener != NULL) { u_listenerFree(listener); listener = u_listener(c_iterTakeFirst(_this->listeners)); } c_iterFree(_this->listeners); _this->listeners = NULL; /* Flags the dispatch thread to stop */ if (os_threadIdToInteger(_this->threadId) != 0U) { tid = _this->threadId; result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if(result != U_RESULT_OK) { /* This is a valid situation when a participant has been * freed prior to the freeing of a dispatcher within the * participant. */ os_mutexUnlock(&_this->mutex); os_threadWaitExit(tid, NULL); os_mutexDestroy(&_this->mutex); /*return U_RESULT_INTERNAL_ERROR;*/ } else { /* Wakeup the dispatch thread */ v_observerLock(ko); v_observerNotify(ko, NULL, NULL); v_observerUnlock(ko); u_entityRelease(u_entity(_this)); os_mutexUnlock(&_this->mutex); os_threadWaitExit(tid, NULL); os_mutexDestroy(&_this->mutex); } } else { os_mutexUnlock(&_this->mutex); os_mutexDestroy(&_this->mutex); } result = u_entityDeinit(u_entity(_this)); } else { OS_REPORT(OS_ERROR,"u_dispatcherDeinit",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
u_partition u_partitionNew( u_participant p, const c_char *name, v_partitionQos qos) { u_partition _this = NULL; v_kernel ke = NULL; v_partition kd; u_result result; if (name == NULL) { name = "No partition specified"; } if (p != NULL) { result = u_entityWriteClaim(u_entity(u_participantDomain(p)),(v_entity*)(&ke)); if ((result == U_RESULT_OK) && (ke != NULL)) { kd = v_partitionNew(ke,name,qos); if (kd != NULL) { _this = u_entityAlloc(p,u_partition,kd,FALSE); if (_this != NULL) { result = u_partitionInit(_this); if (result != U_RESULT_OK) { OS_REPORT_1(OS_ERROR, "u_partitionNew", 0, "Initialisation failed. " "For Partition: <%s>.", name); u_partitionFree(_this); } } else { OS_REPORT_1(OS_ERROR, "u_partitionNew", 0, "Create proxy failed. " "For Partition: <%s>.", name); } c_free(kd); } else { OS_REPORT_1(OS_ERROR, "u_partitionNew", 0, "Create kernel entity failed. " "For Partition: <%s>", name); } result = u_entityRelease(u_entity(u_participantDomain(p))); } else { OS_REPORT_1(OS_WARNING, "u_partitionNew", 0, "Claim Participant failed. " "For Partition: <%s>", name); } } else { OS_REPORT_1(OS_ERROR,"u_partitionNew",0, "No Participant specified. " "For Partition: <%s>", name); } return _this; }
c_char* cmx_publisherNew( const c_char* participant, const c_char* name, const c_char* qos) { u_participant par; u_publisher pub; c_char* result; cmx_entityArg arg; u_result ur; v_publisherQos pqos; cmx_entityKernelArg kernelArg; result = NULL; par = u_participant(cmx_entityUserEntity(participant)); if(par != NULL){ kernelArg = cmx_entityKernelArg(os_malloc(C_SIZEOF(cmx_entityKernelArg))); u_entityAction(u_entity(par), cmx_entityKernelAction, (c_voidp)kernelArg); if(qos != NULL){ pqos = v_publisherQos(cmx_qosKernelQosFromKind(qos, K_PUBLISHER, c_getBase(c_object(kernelArg->kernel)))); if(pqos == NULL){ pqos = v_publisherQosNew(kernelArg->kernel, NULL); } } else { pqos = v_publisherQosNew(kernelArg->kernel, NULL); } pub = u_publisherNew(par, name, pqos, TRUE); os_free(kernelArg); c_free(pqos); if(pub != NULL){ cmx_registerEntity(u_entity(pub)); arg = cmx_entityArg(os_malloc(C_SIZEOF(cmx_entityArg))); arg->entity = u_entity(pub); arg->create = FALSE; arg->participant = NULL; arg->result = NULL; ur = u_entityAction(u_entity(pub), cmx_entityNewFromAction, (c_voidp)(arg)); if(ur == U_RESULT_OK){ result = arg->result; os_free(arg); } } } return result; }
u_result u_dispatcherInsertListener( u_dispatcher _this, u_dispatcherListener listener, c_voidp userData) { u_listener ul; os_threadAttr attr; v_observer ke; u_result result = U_RESULT_OK; c_char *name; if ((_this != NULL) && (listener != NULL)) { os_mutexLock(&_this->mutex); ul = u_listenerNew(listener,userData); _this->listeners = c_iterInsert(_this->listeners,ul); if (os_threadIdToInteger(_this->threadId) == 0U) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ke)); if(result == U_RESULT_OK) { assert(ke); name = v_entityName(ke); if (name == NULL) { name = "NoName"; } os_threadAttrInit(&attr); os_threadCreate(&_this->threadId, name, &attr,dispatch, (void *)_this); result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcherInsertListener", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcherInsertListener", 0, "Failed to claim Dispatcher."); } } u_entityEnable(u_entity(_this)); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
u_result u_dispatcherRemoveListener( u_dispatcher _this, u_dispatcherListener listener) { u_listener ul; v_observer ko; os_threadId tid; u_result result = U_RESULT_OK; struct compareArg arg; if ((_this != NULL) && (listener != NULL)) { os_mutexLock(&_this->mutex); arg.listener = listener; ul = (u_listener) c_iterResolve(_this->listeners, compare, &arg); tid = _this->threadId; if (ul != NULL) { c_iterTake(_this->listeners, ul); if (c_iterLength(_this->listeners) == 0) { result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko)); if(result == U_RESULT_OK) { assert(ko); /* Wakeup the dispatch thread */ v_observerLock(ko); v_observerNotify(ko, NULL, NULL); v_observerUnlock(ko); result = u_entityRelease(u_entity(_this)); if (result != U_RESULT_OK) { OS_REPORT(OS_ERROR, "u_dispatcherRemoveListener", 0, "Release observer failed."); } } else { OS_REPORT(OS_WARNING, "u_dispatcherRemoveListener", 0, "Failed to claim Dispatcher."); } } u_listenerFree(ul); } os_mutexUnlock(&_this->mutex); if ((c_iterLength(_this->listeners) == 0) && (os_threadIdToInteger(tid) != 0U)) { os_threadWaitExit(tid, NULL); } } else { OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
c_type u_topicGetUserType ( u_topic _this) { v_topic topic; c_type type = NULL; u_result uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic)); if (uResult == U_RESULT_OK) { assert(topic); type = v_topicGetUserType(topic); c_keep(type); u_entityRelease(u_entity(_this)); } return type; }
c_string u_topicGetTopicKeys ( u_topic _this) { v_topic topic; c_string keys = NULL; u_result uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic)); if (uResult == U_RESULT_OK) { assert(topic); keys = v_topicKeyExpr(topic); c_keep(keys); u_entityRelease(u_entity(_this)); } return keys; }
c_bool d_waitsetDetach( d_waitset waitset, d_waitsetEntity we) { u_result ur; c_bool result = FALSE; int i; d_waitsetHelper helper; helper = NULL; assert(d_objectIsValid(d_object(waitset), D_WAITSET) == TRUE); assert(d_objectIsValid(d_object(we), D_WAITSET_ENTITY) == TRUE); if(waitset && we){ d_lockLock(d_lock(waitset)); if(c_iterContains(waitset->entities, we) == TRUE) { if(waitset->runToCompletion == TRUE){ ur = u_waitsetDetach(waitset->uwaitset, u_entity(we->dispatcher)); } else { for(i=0; i<c_iterLength(waitset->threads) && !helper; i++){ helper = d_waitsetHelper(c_iterObject(waitset->threads, i)); if(helper->entity != we){ helper = NULL; } } assert(helper); c_iterTake(waitset->threads, helper); helper->terminate = TRUE; u_waitsetNotify(helper->userWaitset, NULL); os_threadWaitExit(helper->tid, NULL); ur = u_waitsetDetach(helper->userWaitset, u_entity(we->dispatcher)); u_waitsetFree(helper->userWaitset); os_free(helper); } if(ur == U_RESULT_OK) { c_iterTake(waitset->entities, we); we->waitset = NULL; result = TRUE; } } d_lockUnlock(d_lock(waitset)); } return result; }
c_iter u_readerLookupQueries( u_reader _this) { c_iter queries = NULL; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { c_iterWalk(_this->queries, collect_queries, &queries); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerLookupQueries",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerLookupQueries",0, "No Reader specified."); } return queries; }
static void* cms_soapThreadRun( void *thr) { cms_soapThread thread; struct soap* soap; c_char* result; thread = cms_soapThread(thr); os_mutexLock(&thread->soapMutex); while(cms_thread(thread)->terminate == FALSE){ if(thread->soap != NULL){ soap = thread->soap; thread->soap = NULL; cms_thread(thread)->results = NULL; soap->user = thr; soap_serve(soap); soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); u_entityAction( u_entity(thread->client->service->uservice), cms_soapThreadStatisticsRequestHandledAdd, thread->client->service); if(cms_thread(thread)->results != NULL){ result = (c_char*)(c_iterTakeFirst(cms_thread(thread)->results)); while(result){ os_free(result); result = (c_char*)(c_iterTakeFirst(cms_thread(thread)->results)); } c_iterFree(cms_thread(thread)->results); cms_thread(thread)->results = NULL; } } if(cms_thread(thread)->terminate == FALSE){ cms_thread(thread)->ready = TRUE; if(thread->client->service->configuration->verbosity >= 7){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' ready.", cms_thread(thread)->name); } os_condWait(&thread->condition, &thread->soapMutex); if(thread->client->service->configuration->verbosity >= 7){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' condition triggered.", cms_thread(thread)->name); } } } os_mutexUnlock(&thread->soapMutex); if(thread->client->service->configuration->verbosity >= 6){ OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "soapThread '%s' ends.", cms_thread(thread)->name); } return NULL; }
c_bool u_readerWalkQueries( u_reader _this, u_readerAction action, c_voidp actionArg) { c_bool result = U_RESULT_OK; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { c_iterWalkUntil(_this->queries, (c_iterAction)action, actionArg); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerWalkQueries",0, "Failed to lock Reader."); result = U_RESULT_ILL_PARAM; } } } else { OS_REPORT(OS_WARNING, "u_readerWalkQueries",0, "No Reader specified."); result = U_RESULT_ILL_PARAM; } return result; }
c_long u_readerQueryCount( u_reader _this) { c_long length = -1; os_result r; if (_this) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { length = c_iterLength(_this->queries); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerRemoveQuerie",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerQueryCount",0, "No Reader specified."); } return length; }
c_bool u_readerContainsQuery( u_reader _this, u_query query) { c_bool found = FALSE; os_result r; if (_this && query) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { found = c_iterContains(_this->queries,query); os_mutexUnlock(&_this->mutex); } else { OS_REPORT(OS_WARNING, "u_readerContainsQuery",0, "Failed to lock Reader."); } } } else { OS_REPORT(OS_WARNING, "u_readerRemoveQuery",0, "Illegal parameter."); } return found; }
u_result u_readerAddQuery( u_reader _this, u_query query) { os_result r; u_result result = U_RESULT_PRECONDITION_NOT_MET; if (_this && query) { if(u_entityOwner(u_entity(_this))) { r = os_mutexLock(&_this->mutex); if (r == os_resultSuccess) { _this->queries = c_iterInsert(_this->queries, query); os_mutexUnlock(&_this->mutex); result = U_RESULT_OK; } else { OS_REPORT(OS_WARNING, "u_readerAddQuery",0, "Failed to lock Reader."); result = U_RESULT_ILL_PARAM; } } else { result = U_RESULT_OK; } } else { OS_REPORT(OS_WARNING, "u_readerAddQuery",0, "Illegal parameter."); result = U_RESULT_ILL_PARAM; } return result; }
u_result u_readerTakeNextInstance( u_reader r, u_instanceHandle h, u_readerAction action, c_voidp actionArg) { u_result result; switch (u_entity(r)->kind) { case U_READER: result = u_dataReaderTakeNextInstance(u_dataReader(r), h, action, actionArg); break; case U_DATAVIEW: result = u_dataViewTakeNextInstance(u_dataView(r), h, action, actionArg); break; case U_QUERY: result = u_queryTakeNextInstance(u_query(r), h, action, actionArg); break; default: result = U_RESULT_ILL_PARAM; break; } return result; }
void * u_readerTakeList( u_reader r, c_ulong max, u_readerCopyList copy, c_voidp copyArg) { void *result = NULL; switch (u_entity(r)->kind) { case U_READER: result = u_dataReaderTakeList(u_dataReader(r), max, copy, copyArg); break; case U_DATAVIEW: assert(FALSE); break; case U_QUERY: result = u_queryTakeList(u_query(r), max, copy, copyArg); break; default: result = NULL; break; } return result; }