gapi_returnCode_t _ConditionAddWaitset( _Condition _this, gapi_waitSet waitset, u_waitset uWaitset) { gapi_returnCode_t result = GAPI_RETCODE_OK; u_result uResult; _this->waitsets = c_iterInsert(_this->waitsets,waitset); if ((uWaitset != NULL) && (_this->uEntity != NULL)) { uResult = u_waitsetAttach(uWaitset, _this->uEntity, (c_voidp)_this); if (uResult != U_RESULT_OK) { result = GAPI_RETCODE_ERROR; } } return result; }
static u_result attachAndMonitor( const u_participant participant, const struct builtin_datareader_set *drset) { u_waitset waitset; u_dataReader dataReader; c_iter readers; u_result result; c_long i, length; result = U_RESULT_INTERNAL_ERROR; readers = NULL; length = 0; /*Create waitset.*/ waitset = u_waitsetNew(participant); if(waitset){ /*Set event mask of the waitset.*/ result = u_waitsetSetEventMask(waitset, V_EVENT_DATA_AVAILABLE | V_EVENT_NEW_GROUP | V_EVENT_SERVICESTATE_CHANGED); if(result == U_RESULT_OK){ result = u_dispatcherSetEventMask( (u_dispatcher)participant, V_EVENT_NEW_GROUP | V_EVENT_SERVICESTATE_CHANGED); if(result == U_RESULT_OK){ v_serviceFillNewGroups(service); result = u_waitsetAttach( waitset, (u_entity)participant, (u_entity)participant); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Could not attach datareader to waitset.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of participant."); } if(result == U_RESULT_OK){ readers = c_iterNew(drset->participant_dr); readers = c_iterInsert(readers, drset->publication_dr); readers = c_iterInsert(readers, drset->subscription_dr); result = U_RESULT_OK; length = c_iterLength(readers); for(i=0; i<length && (result == U_RESULT_OK); i++){ dataReader = (u_dataReader)(c_iterObject(readers, i)); /*Set event mask of the datareader to trigger on available data.*/ result = u_dispatcherSetEventMask( (u_dispatcher)dataReader, V_EVENT_DATA_AVAILABLE); if(result == U_RESULT_OK){ /*Attach reader to the waitset.*/ result = u_waitsetAttach( waitset, (u_entity)dataReader, (u_entity)dataReader); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Could not attach datareader to waitset.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of datareader.\n"); } } } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of waitset.\n"); } if(result == U_RESULT_OK){ /*Start monitoring the creation/deletion of entities.*/ result = startMonitoring(participant, waitset, drset); } u_waitsetDetach(waitset, u_entity(participant)); if(readers){ /*Detach all datareaders from the waitset.*/ for(i=0; i<length; i++){ u_waitsetDetach(waitset, (u_entity)(c_iterObject(readers, i))); } c_iterFree(readers); } /*Delete the waitset.*/ result = u_waitsetFree(waitset); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Deletion of waitset failed.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not create waitset.\n"); } return result; }
c_bool d_waitsetAttach( d_waitset waitset, d_waitsetEntity we) { c_bool result = FALSE; u_result ur; os_result osr; d_waitsetHelper helper; c_ulong mask; d_admin admin; d_durability durability; 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(!we->waitset) { if(c_iterContains(waitset->entities, we) == FALSE) { waitset->entities = c_iterInsert(waitset->entities, we); if(waitset->runToCompletion == TRUE){ ur = u_waitsetAttach(waitset->uwaitset, u_entity(we->dispatcher), (c_voidp)we->dispatcher); if(ur == U_RESULT_OK) { we->waitset = waitset; result = TRUE; } } else { admin = d_subscriberGetAdmin(waitset->subscriber); durability = d_adminGetDurability(admin); helper = os_malloc(C_SIZEOF(d_waitsetHelper)); helper->waitset = waitset; helper->entity = we; helper->terminate = FALSE; helper->tid = OS_THREAD_ID_NONE; helper->userWaitset = u_waitsetNew(u_participant(d_durabilityGetService(durability))); mask = V_EVENT_DATA_AVAILABLE; mask |= V_EVENT_NEW_GROUP; mask |= V_EVENT_HISTORY_DELETE; mask |= V_EVENT_HISTORY_REQUEST; mask |= V_EVENT_PERSISTENT_SNAPSHOT; mask |= V_EVENT_TRIGGER; u_waitsetSetEventMask(helper->userWaitset, mask); ur = u_waitsetAttach(helper->userWaitset, u_entity(we->dispatcher), (c_voidp)we->dispatcher); if(ur != U_RESULT_OK) { assert(FALSE); } else { result = TRUE; } if(result){ waitset->threads = c_iterInsert(waitset->threads, helper); osr = os_threadCreate(&(helper->tid), we->name, &(we->attr), d_waitsetEventHandler, helper); if(osr != os_resultSuccess){ c_iterTake(waitset->threads, helper); u_waitsetDetach(helper->userWaitset, u_entity(we->dispatcher)); u_waitsetFree(helper->userWaitset); os_free(helper); result = FALSE; } } else { u_waitsetFree(helper->userWaitset); os_free(helper); } } } } d_lockUnlock(d_lock(waitset)); } return result; }