summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/Naming_Utils.h
blob: 83f4c85eed7d9cc91ec8fcf70bff5856e4d45937 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/Naming_Service
//
// = FILENAME
//    Naming_Utils.h
//
// = DESCRIPTION
//      Implement wrappers useful to Naming Service clients and servers.
//
// = AUTHORS
//    Nagarajan Surendran (naga@cs.wustl.edu), Matt Braun
//    <mjb2@cs.wustl.edu>, and Douglas C. Schmidt <schmidt@cs.wustl.edu>.
//
// ============================================================================

#ifndef TAO_NAMING_UTILS_H
#define TAO_NAMING_UTILS_H

#include "tao/corba.h"
#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/IOR_Multicast.h"
#include "Naming_Context.h"

// Forward decl;
class TAO_Persistent_Context_Index;

class TAO_ORBSVCS_Export TAO_Naming_Server
{
  // = TITLE
  //
  //    Defines a wrapper class that holds the root Naming Context.
  //
  // = DESCRIPTION
  //
  //    This class either finds an existing Naming Service (if the
  //    <resolve_for_existing_naming_service> flag is set) or creates
  //    one (if <resolve_for_existing_naming_service> flag isn't set or
  //    Naming Service was not found).  This class also defines the
  //    operator-> so that  <NamingContext> functions like <bind>,
  //    <unbind> .. can be called directly on a <TAO_Naming_Server>
  //    object, and be forwareded to the root Naming Context.
  //    This class is intended to simplify
  //    programs that want to play the role of a Naming Service
  //    server.  To simplify programs that want to play the role of
  //    Naming Service clients, use <TAO_Naming_Client>.
  //
  //    If a Naming Service is created locally, a TAO_IOR_Multicast
  //    event handler is created and installed on the ORB's reactor.
  //    This event handler allows other clients on the network to
  //    discover and use this Naming Service.
  //    Event handler listens on a multicast port for messages from
  //    clients looking for a Naming Service, and sends back the ior
  //    of the root Naming Context.  For more information on how this
  //    bootstraping through a multicast process works, check out
  //    orbsvcs/orbsvcs/TAO_IOR_Multicast.*, implementation of
  //    <resolve_initial_references>, and orbsvcs/Naming/README.
public:
  TAO_Naming_Server (void);
  // Default constructor.

  TAO_Naming_Server (CORBA::ORB_ptr orb,
                     PortableServer::POA_ptr poa,
                     size_t context_size = ACE_DEFAULT_MAP_SIZE,
                     ACE_Time_Value *timeout = 0,
                     int resolve_for_existing_naming_service = 1,
                     LPCTSTR persistence_location = 0);
  // Constructor.  Attempts to find an existing Naming Service if
  // <resolve_for_existing_naming_service> is set to true.  If it is
  // false, or no Naming Service was found during a <timeout> period,
  // create the Naming Service in this process.  If creating the
  // Naming Service locally, make the root context of size
  // <context_size>, register it under the <poa>, and make the Naming
  // Service persistent if <persistence_location> is not 0.
  // (<persistence_location> specifies name of the file to use for
  // persistent storage).

  int init (CORBA::ORB_ptr orb,
            PortableServer::POA_ptr poa,
            size_t context_size = ACE_DEFAULT_MAP_SIZE,
            ACE_Time_Value *timeout = 0,
            int resolve_for_existing_naming_service = 1,
            LPCTSTR persistence_location = 0);
  // Initializer.  Attempts to find an existing Naming Service if
  // <resolve_for_existing_naming_service> is set to true.  If it is
  // false, or no Naming Service was found during a <timeout> period,
  // create the Naming Service in this process.  If creating the
  // Naming Service locally, make the root context of size
  // <context_size>, register it under the <poa>, and make the Naming
  // Service persistent if <persistence_location> is not 0.
  // (<persistence_location> specifies name of the file to use for
  // persistent storage).

  ~TAO_Naming_Server (void);
  // Destructor.

  CORBA::String naming_service_ior (void);
  // Returns the IOR of the naming service.

  CosNaming::NamingContext_ptr operator-> (void) const;
  // Returns a <NamingContext_ptr> for the root Naming Context.

protected:
  int init_new_naming (CORBA::ORB_ptr orb,
                       PortableServer::POA_ptr root_poa,
                       LPCTSTR persistence_location,
                       size_t context_size);
  // Helper method: create Naming Service locally.
  // Make the root context of size
  // <context_size>, register it under the <root_poa>, and make the Naming
  // Service persistent if <persistence_location> is not 0.
  // (<persistence_location> specifies name of the file to use for
  // persistent storage).

  CosNaming::NamingContext_var naming_context_;
  // Root NamingContext_ptr.

  TAO_IOR_Multicast *ior_multicast_;
  // The ior_multicast event handler.

  CORBA::String_var naming_service_ior_;
  // The IOR string of the root naming context.

  TAO_Persistent_Context_Index *context_index_;
  // Pointer to the object used to create/initialize
  // the Naming Service when local persistent Naming Service is
  // desired.
};

class TAO_ORBSVCS_Export TAO_Naming_Client
{
  // = TITLE
  //    This class is intended to simplify programs that want to play
  //    the role of Naming Service clients.
  //
  // = DESCRIPTION
  //    Wrapper class that locates the root Naming Context.  It also
  //    defines the operator-> so that <NamingContext> functions like
  //    <resolve>, etc. can be directly called on a
  //    <TAO_Naming_Client> object, and will be forwarded to the root
  //    Naming Context.
public:
  // = Initialization and termination methods.

  TAO_Naming_Client (void);
  // Default constructor.

  int init (CORBA::ORB_ptr orb,
            ACE_Time_Value *timeout = 0);
  // Look for a Naming Service for a period of <timeout> using
  // <resolve_initial_references>.  Return 0 if Naming Service is
  // successfully located, and -1 on failure.

  ~TAO_Naming_Client (void);
  // Destructor.

  CosNaming::NamingContext_ptr operator-> (void) const;
  // Returns a pointer to the root Naming Context.

  CosNaming::NamingContext_ptr get_context (void) const;
  // Returns a pointer to the root Naming Context.

protected:
  CosNaming::NamingContext_var naming_context_;
  // Reference to the root Naming Context.
};

#endif /* TAO_NAMING_UTILS_H */