summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/Notify_Service/Notify_Service.h
blob: 486fdbd1e3f05a86faaaee64a2fd19504bbe757c (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file   Notify_Service.h
 *
 * Notification Service front end.
 *
 *  @author Pradeep Gore <pradeep@cs.wustl.edu>
 *  @author Service options code by Wei Chiang <Wei.Chiang@nokia.com>.
 */
//=============================================================================


#ifndef NOTIFY_SERVICE_H
#define NOTIFY_SERVICE_H
#include /**/ "ace/pre.h"

#include "ace/Task.h"
#include "tao/PortableServer/PortableServer.h"
#include "orbsvcs/CosNotifyChannelAdminC.h"
#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/Notify/CosNotify_Initializer.h"
#include "ace/SString.h"
#include "ace/Reactor.h"
#include "ace/Service_Object.h"
#include "Notify_Service_Export.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL
class TAO_Notify_Service;
class TAO_Notify_Service_Driver;

#define NOTIFY_KEY "NotifyEventChannelFactory"
#define NOTIFY_CHANNEL_NAME "NotifyEventChannel"

class LoggingWorker : public ACE_Task_Base
{
public:
  LoggingWorker (TAO_Notify_Service_Driver* ns);
  virtual int svc ();
  void start ();
  void end ();
private:
  ACE_Reactor logging_reactor_;
  TAO_Notify_Service_Driver* ns_;
  bool started_;
  long timer_id_;
};

/**
 * @class Worker
 *
 * @brief Run a server thread
 *
 * Use the ACE_Task_Base class to run server threads
 */
class Worker : public ACE_Task_Base
{
public:
  /// ctor
  Worker (void);

  void orb (CORBA::ORB_ptr orb);

  /// The thread entry point.
  virtual int svc ();

private:
  /// The orb
  CORBA::ORB_var orb_;
};

/**
 * @class TAO_Notify_Service_Driver
 *
 * @brief Notify_Service
 *
 * Implementation of the Notification Service front end.
 */
class TAO_Notify_Service_Export TAO_Notify_Service_Driver : public ACE_Service_Object
{
friend class LoggingWorker;

public:
  /// Constructor.
  TAO_Notify_Service_Driver (void);

  /// Destructor.
  virtual ~TAO_Notify_Service_Driver (void);

  /// Initializes the Service.
  /// Returns 0 on success, -1 on error.
  virtual int init (int argc, ACE_TCHAR *argv[]);

  /// run the Service.
  /// Returns 0 on success, -1 on error.
  int run (void);

  /// Shutdown the Service.
  /// Returns 0 on success, -1 on error.
  virtual int fini ();

protected:
  /// initialize the ORB.
  int init_ORB (int& argc, ACE_TCHAR *argv []);

  /// initialize the dispatching ORB.
  int init_dispatching_ORB (int& argc, ACE_TCHAR *argv []);

  /// Apply a relative round-trip timeout to the ORB
  void apply_timeout (CORBA::ORB_ptr orb);

  TAO_Notify_Service* notify_service_;

  /// Resolve the naming service.
  int resolve_naming_service (void);

  /// Parses the command line arguments.
  int parse_args (int argc, ACE_TCHAR *argv []);

  // = Data members

  /// true: this service is bootstrappable
  bool bootstrap_;

  /// true: register itself with the name service
  bool use_name_svc_;

  /// File name where the IOR of the server object is stored.
  const ACE_TCHAR *ior_output_file_name_;

  /// The Factory name.
  ACE_CString notify_factory_name_;

  /// The event channel names.
  ACE_Unbounded_Set <ACE_CString> notify_channel_name_;

  /// true: create an event channel and registers it with the Naming Service
  /// with the name <notify_channel_name_>
  bool register_event_channel_;

  /// The Factory.
  CosNotifyChannelAdmin::EventChannelFactory_var notify_factory_;

  /// The ORB that we use.
  CORBA::ORB_var orb_;

  /// Separate dispatching orb if needed.
  CORBA::ORB_var dispatching_orb_;

  /// Reference to the root poa.
  PortableServer::POA_var poa_;

  /// A naming context.
  CosNaming::NamingContextExt_var naming_;

  /// Worker for TP reactor mode.
  Worker worker_;

  /// Number of worker threads.
  int nthreads_;

  /// indicate that a separate ORB is used for dispatching events.
  bool separate_dispatching_orb_;

  /// The relative round-trip timeout
  suseconds_t timeout_;

  /// Logging interval
  ACE_Time_Value logging_interval_;

  /// Logging worker
  LoggingWorker logging_worker_;

  /// Shutdown the ORB?
  bool shutdown_orb_;

  /// Shutdown the dispatching ORB?
  bool shutdown_dispatching_orb_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

ACE_STATIC_SVC_DECLARE (TAO_Notify_Service_Driver)
ACE_FACTORY_DECLARE (TAO_Notify_Service, TAO_Notify_Service_Driver)

#include /**/ "ace/post.h"
#endif /* NOTIFY_SERVICE_H */