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

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/Time_Service
//
// = FILENAME
//    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/PortableServer/ORB_Manager.h"
#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/Naming/Naming_Server.h"
#include "orbsvcs/Time/TAO_Time_Service_Clerk.h"

class Clerk_i
{
  // = TITLE
  //   CORBA Time Clerk implementation.
  //
  // = DESCRIPTION
  //   A CORBA server that initializes the TimeService clerk
  //   implementation and the ORB.
public:

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

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

  ~Clerk_i (void);
  // Destructor.

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

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

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

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

private:

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

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

  TAO_ORB_Manager orb_manager_;
  // The ORB manager.

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

  int init_naming_service (int argc,
                           char* argv[]);
  // Initialises the name server and registers the <TimeService> Clerk
  // object with it.

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

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

  int if_first_clerk (CosNaming::Name clerk_context_name);
  // Check if this is the first clerk.

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

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

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

  TAO_Naming_Server my_name_server_;
  // 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_Time_Service_Clerk *time_service_clerk_impl_;
  // Implementation of the <TimeService> Clerk object.

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

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

  CORBA::ORB_var orb_;
  // My orb.

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

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

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

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

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

#endif /* CLERK_I_H */