summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/Time_Service/Clerk_i.h
blob: a39550e0955338310bea3e9a35bf67c603a7b119 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Clerk_i.h
 *
 *  @author Vishal Kachroo <vishal@cs.wustl.edu>
 */
//=============================================================================


#ifndef CLERK_I_H
#define CLERK_I_H

#include "ace/Get_Opt.h"
#include "ace/Log_Msg.h"
#include "tao/Utils/ORB_Manager.h"
#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/Naming/Naming_Client.h"
#include "orbsvcs/Time/TAO_Time_Service_Clerk.h"

/**
 * @class Clerk_i
 *
 * @brief CORBA Time Clerk implementation.
 *
 * A CORBA server that initializes the TimeService clerk
 * implementation and the ORB.
 */
class Clerk_i
{
public:

  enum {
    // Pre-allocate slots for this many servers. The capacity grows on
    // demand.
    DEFAULT_SERVER_COUNT = 8
  };

  // = Initialization and termination methods.
  /// Constructor.
  Clerk_i (void);

  /// Destructor.
  ~Clerk_i (void);

  /// Set of available Time servers.
  typedef ACE_Array_Base<CosTime::TimeService_var> IORS;

  /// Initialize the Clerk state - parsing arguments and waiting.
  int init (int argc,
            ACE_TCHAR *argv[]);

  /// Run the orb.
  int run (void);

private:
  /// Insert a server in the internal data structure (servers_).
  void insert_server (CosTime::TimeService_ptr server);

private:

  /// Read the server IORs from a file instead of using a naming
  /// service.
  int read_ior (const ACE_TCHAR* filename);

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

  /// The ORB manager.
  TAO_ORB_Manager orb_manager_;

  /// File where the IOR of the Clerk object is stored.
  FILE *ior_output_file_;

  /// Initialises the name client and registers the <TimeService> Clerk
  /// object with it.
  int init_naming_service ();

  /// Create an instance of the clerk to use.
  int create_clerk (void);

  /// Bind the clerk in the appropriate context in the Naming Service.
  int register_clerk (void);

  /// Initialise the Interface Repository and register the clerk
  /// implementation with it.
  int init_IR (void);

  /// Get the reference to the server naming context and the first
  /// server IOR.
  int get_first_IOR (void);

  /// Iterate over the given server context to get the rest of the
  /// server IORs.
  int next_n_IORs (CosNaming::BindingIterator_var iter,
                   CosNaming::NamingContext_var server_context);

  /**
   * An instance of the name server used for registering the
   * <TimeService Clerk> object. The same instance is used by the
   * Clerk to periodically iterate through the Server Naming Context
   * and get IORs of the available servers.
   */
  TAO_Naming_Client naming_client_;

  /// Implementation of the <TimeService> Clerk object.
  TAO_Time_Service_Clerk *time_service_clerk_impl_;

  /// Reference of the time service clerk.
  CosTime::TimeService_var time_service_clerk_;

  /// Naming context for the Naming Service.
  CosNaming::NamingContext_var time_service_clerk_context_;

  /// My orb.
  CORBA::ORB_var orb_;

  /// Clerk seeks time periodically after this interval in secs. from the
  /// servers in the network.
  int timer_value_ ;

  /// Continues the precision of timer_value_ in microseconds.
  int timer_value_usecs_;

  //  IR_Helper *ir_helper_;
  // Helper class for using the IR.

  /// The unbounded set of server IORS.
  IORS server_;

  /// Read IORs from a file.
  int ior_fp_;
};

#endif /* CLERK_I_H */