summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/tie_sh.cpp
blob: 021309aee09e81b96219e918d84cac79189effb0 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    tie_sh.cpp
//
// = DESCRIPTION
//    Visitor generating code for TIE class for an Interface in the header
//    file.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include	"idl.h"
#include	"idl_extern.h"
#include	"be.h"

#include "be_visitor_interface.h"


// ************************************************************
// Interface visitor for server header
// ************************************************************

be_visitor_interface_tie_sh::be_visitor_interface_tie_sh (be_visitor_context *ctx)
  : be_visitor_interface (ctx)
{
}

be_visitor_interface_tie_sh::~be_visitor_interface_tie_sh (void)
{
}

int
be_visitor_interface_tie_sh::visit_interface (be_interface *node)
{
  TAO_OutStream *os; // output stream
  static char namebuf [NAMEBUFSIZE]; // holds the class name
  static char tiename [NAMEBUFSIZE]; // holds the tie name

  if (node->srv_hdr_gen () || node->imported ())
    return 0;

  ACE_OS::memset (namebuf, '\0', NAMEBUFSIZE);
  ACE_OS::memset (tiename, '\0', NAMEBUFSIZE);

  os = this->ctx_->stream ();

  // generate the skeleton class name which will be used to determine the TIE
  // class name

  // we shall have a POA_ prefix only if we are at the topmost level
  if (!node->is_nested ())
    {
      // we are outermost
      ACE_OS::sprintf (namebuf, "POA_%s", node->local_name ()->get_string ());
      ACE_OS::sprintf (tiename, "POA_%s_tie",
                       node->local_name ()->get_string ());
    }
  else
    {
      ACE_OS::sprintf (namebuf, "%s", node->local_name ()->get_string ());
      ACE_OS::sprintf (tiename, "%s_tie",
                       node->local_name ()->get_string ());
    }

  // now generate the class definition
  os->indent (); // start with whatever indentation level we are at

  // Since templates nested inside of classes are broken on most C++ compilers,
  // we generate code for this inside a conditional macro. The code is
  // activated only if "namespaces" are supported on the platform
  if (node->is_nested ())
    {
      *os << "\n#if defined (ACE_HAS_USING_KEYWORD)" << be_nl;
    }

  *os << "// TIE class: Refer to CORBA v2.2, Section 20.34.4" << be_nl;
  *os << "template <class T>" << be_nl;
  *os << "class " << idl_global->export_macro ()
      << " " << tiename << " : public " << namebuf << be_nl;
  *os << "{" << be_nl
      << "public:" << be_idt_nl
      << tiename << " (T &t);" << be_nl
      << "// the T& ctor" << be_nl
      << tiename << " (T &t, PortableServer::POA_ptr poa);" << be_nl
      << "// ctor taking a POA" << be_nl
      << tiename << " (T *tp, CORBA::Boolean release=1);" << be_nl
      << "// ctor taking pointer and an ownership flag" << be_nl
      << tiename << " (T *tp, PortableServer::POA_ptr poa, "
      << "CORBA::Boolean release=1);" << be_nl
      << "// ctor with T*, ownership flag and a POA" << be_nl
      << "~" << tiename << " (void);" << be_nl
      << "// dtor" << be_nl << be_nl
      << "// TIE specific functions" << be_nl
      << "T *_tied_object (void);" << be_nl
      << "// return the underlying object" << be_nl
      << "void _tied_object (T &obj);" << be_nl
      << "// set the underlying object" << be_nl
      << "void _tied_object (T *obj, CORBA::Boolean release=1);" << be_nl
      << "// set the underlying object and the ownership flag" << be_nl
      << "CORBA::Boolean _is_owner (void);" << be_nl
      << "// do we own it" << be_nl
      << "void _is_owner (CORBA::Boolean b);" << be_nl
      << "// set the ownership" << be_nl << be_nl
      << "// overridden ServantBase operations" << be_nl
      << "PortableServer::POA_ptr _default_POA (CORBA::Environment &env);\n";

  // generate code for the operations in the scope
  if (this->visit_scope (node) ==  -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_tie_sh::"
                         "visit_interface - "
                         "codegen for scope failed\n"),
                        -1);
    }

  *os << be_uidt << "private:" << be_idt_nl
      << "T *ptr_;" << be_nl
      << "PortableServer::POA_var poa_;" << be_nl
      << "CORBA::Boolean rel_;" << be_nl << be_nl
      << "// copy and assignment are not allowed" << be_nl
      << tiename << " (const " << tiename << " &);" << be_nl
      << "void operator= (const " << tiename << " &);" << be_uidt_nl
      << "};\n\n";

  if (node->is_nested ())
    {
      *os << "#endif /* ACE_HAS_USING_KEYWORD */\n";
    }

  return 0;
}