| 394 | } |
| 395 | |
| 396 | DDS::ReturnCode_t |
| 397 | WriteDataContainer::register_instance( |
| 398 | DDS::InstanceHandle_t& instance_handle, |
| 399 | Message_Block_Ptr& registered_sample) |
| 400 | { |
| 401 | PublicationInstance_rch instance; |
| 402 | |
| 403 | if (instance_handle == DDS::HANDLE_NIL) { |
| 404 | if (max_num_instances_ > 0 |
| 405 | && max_num_instances_ <= (CORBA::Long) instances_.size()) { |
| 406 | return DDS::RETCODE_OUT_OF_RESOURCES; |
| 407 | } |
| 408 | |
| 409 | // registered the instance for the first time. |
| 410 | instance.reset(new PublicationInstance(OPENDDS_MOVE_NS::move(registered_sample)), keep_count()); |
| 411 | |
| 412 | instance_handle = this->writer_->get_next_handle(); |
| 413 | |
| 414 | int const insert_attempt = OpenDDS::DCPS::bind(instances_, instance_handle, instance); |
| 415 | |
| 416 | if (0 != insert_attempt) { |
| 417 | ACE_ERROR((LM_ERROR, |
| 418 | ACE_TEXT("(%P|%t) ERROR: ") |
| 419 | ACE_TEXT("WriteDataContainer::register_instance, ") |
| 420 | ACE_TEXT("failed to insert instance handle=%X\n"), |
| 421 | instance.in())); |
| 422 | return DDS::RETCODE_ERROR; |
| 423 | } // if (0 != insert_attempt) |
| 424 | |
| 425 | instance->instance_handle_ = instance_handle; |
| 426 | |
| 427 | extend_deadline(instance); |
| 428 | |
| 429 | } else { |
| 430 | |
| 431 | int const find_attempt = find(instances_, instance_handle, instance); |
| 432 | |
| 433 | if (0 != find_attempt) { |
| 434 | ACE_ERROR((LM_ERROR, |
| 435 | ACE_TEXT("(%P|%t) ERROR: ") |
| 436 | ACE_TEXT("WriteDataContainer::register_instance, ") |
| 437 | ACE_TEXT("The provided instance handle=%X is not a valid") |
| 438 | ACE_TEXT("handle.\n"), |
| 439 | instance_handle)); |
| 440 | |
| 441 | return DDS::RETCODE_ERROR; |
| 442 | } // if (0 != find_attempt) |
| 443 | } |
| 444 | |
| 445 | // The registered_sample is shallow copied. |
| 446 | registered_sample.reset(instance->registered_sample_->duplicate()); |
| 447 | |
| 448 | return DDS::RETCODE_OK; |
| 449 | } |
| 450 | |
| 451 | DDS::ReturnCode_t |
| 452 | WriteDataContainer::unregister( |