DDSWaitSet* waitset = new DDSWaitSet();
DDSCondition* cond1 = ...; DDSCondition* cond2 = entity->get_statuscondition(); DDSCondition* cond3 = reader->create_readcondition(DDS_NOT_READ_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); DDSCondition* cond4 = new DDSGuardCondition(); DDSCondition* cond5 = ...; DDS_ReturnCode_t retcode; retcode = waitset->attach_condition(cond1); if (retcode != DDS_RETCODE_OK) { // ... error } retcode = waitset->attach_condition(cond2); if (retcode != DDS_RETCODE_OK) { // ... error } retcode = waitset->attach_condition(cond3); if (retcode != DDS_RETCODE_OK) { // ... error } retcode = waitset->attach_condition(cond4); if (retcode != DDS_RETCODE_OK) { // ... error } retcode = waitset->attach_condition(cond5); if (retcode != DDS_RETCODE_OK) { // ... error }
timeout
, whichever occurs first DDS_Duration_t timeout = { 0, 1000000 }; // 1ms DDSConditionSeq active_conditions; // holder for active conditions bool is_cond1_triggered = false; bool is_cond2_triggered = false; DDS_ReturnCode_t retcode; retcode = waitset->wait(active_conditions, timeout); if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure } else { // success if (active_conditions.length() == 0) { // timeout! printf("Wait timed out!! None of the conditions was triggered.\n"); } else { // check if "cond1" or "cond2" are triggered: for(int i = 0; i < active_conditions.length(); ++i) { if (active_conditions[i] == cond1) { printf("Cond1 was triggered!"); is_cond1_triggered = true; } if (active_conditions[i] == cond2) { printf("Cond2 was triggered!"); is_cond2_triggered = true; } if (is_cond1_triggered && is_cond2_triggered) { break; } } } } if (is_cond1_triggered) { // ... do something because "cond1" was triggered ... } if (is_cond2_triggered) { // ... do something because "cond2" was triggered ... }
delete waitset;
waitset = NULL;