summaryrefslogtreecommitdiff
path: root/modules/CIAO/connectors/dds4ccm/impl/ndds/Writer.tpp
blob: 12f8a6aa0afe510117ddc57cc99040bbeec24b9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// $Id$
#include "dds4ccm/impl/ndds/DataWriter.h"
#include "dds4ccm/impl/ndds/Utils.h"

#include "ciao/Logger/Log_Macros.h"

// Implementation skeleton constructor
template <typename NDDS_TYPE, typename BASE >
CIAO::DDS4CCM::RTI::Writer_T<NDDS_TYPE, BASE>::Writer_T (::DDS::DataWriter_ptr writer)
  : impl_ (0)
{
  CIAO_TRACE ("CIAO::DDS4CCM::RTI::Writer_T::Writer_T");

  RTI_DataWriter_i *rdw = dynamic_cast <RTI_DataWriter_i *> (writer);

  if (rdw == 0)
    {
      CIAO_ERROR ((LM_ERROR, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::Writer_T - "
                   "Unable to cast provided DataWriter to servant\n"));
      throw CORBA::INTERNAL ();
    }

  impl_ =  NDDS_TYPE::data_writer::narrow (rdw->get_datawriter ());

  if (!impl_)
    {
      CIAO_ERROR ((LM_ERROR, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::Writer_T - "
                   "Unable to narrow the provided writer entity to the specific "
                   "type necessary to publish messages\n"));
      throw CORBA::INTERNAL ();
    }
}

// Implementation skeleton destructor
template <typename NDDS_TYPE, typename BASE >
CIAO::DDS4CCM::RTI::Writer_T<NDDS_TYPE, BASE>::~Writer_T (void)
{
  CIAO_TRACE ("CIAO::DDS4CCM::RTI::Writer_T::~Writer_T");
}

template <typename NDDS_TYPE, typename BASE >
void
CIAO::DDS4CCM::RTI::Writer_T<NDDS_TYPE, BASE>::write (const typename NDDS_TYPE::value_type & an_instance)
{
  CIAO_TRACE ("CIAO::DDS4CCM::RTI::Writer_T::write");
  
  /*
  if (CORBA::is_nil (an_instance))
    {
      CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
                   "Write was provided a null instance to write\n"));
      return;
    }
  */

  CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
               "Preparing to write to DDS\n"));
  DDS_ReturnCode_t retval = this->impl_->write (an_instance,
                                                DDS_HANDLE_NIL);

  if (retval != DDS_RETCODE_OK)
    {
      CIAO_ERROR ((LM_ERROR, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
                   "Write unsuccessful, received error code %C\n",
                   translate_retcode (retval)));
      throw CCM_DDS::InternalError (retval, 0);
    }

  CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
               "Write successful\n"));
}

template <typename NDDS_TYPE, typename BASE >
void
CIAO::DDS4CCM::RTI::Writer_T<NDDS_TYPE, BASE>::write (const typename NDDS_TYPE::seq_type& instances, bool coherent_write)
{
  CIAO_TRACE ("CIAO::DDS4CCM::RTI::Writer_T::write");

  if (coherent_write)
    {
      this->impl_->get_publisher()->begin_coherent_changes ();
    }

  CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
               "Preparing to write to DDS\n"));
  for (::CORBA::ULong index = 0; index < instances.length(); index++)
    {
      DDS_ReturnCode_t retval = this->impl_->write (instances[index],
                                     DDS_HANDLE_NIL);

      if (retval != DDS_RETCODE_OK)
        {
         CIAO_ERROR ((LM_ERROR, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
                       "Write unsuccessful, received error code %C\n",
                       translate_retcode (retval)));
          throw CCM_DDS::InternalError (retval, index);
        }
    }

  if (coherent_write)
    {
      this->impl_->get_publisher()->end_coherent_changes ();
    }

  CIAO_DEBUG ((LM_TRACE, CLINFO "CIAO::DDS4CCM::RTI::Writer_T::write - "
               "Write successful\n"));
}